From 43171396b37dcf06fb0d47a0cf45b9f5309c4f66 Mon Sep 17 00:00:00 2001 From: uvos <devnull@uvos.xyz> Date: Thu, 24 Aug 2023 14:09:57 +0200 Subject: [PATCH] fix some minor issues, expose fault flag --- coincellhell.c | 9 ++++++--- coincellhell.h | 1 + main.c | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/coincellhell.c b/coincellhell.c index c59eb0b..ab45f64 100644 --- a/coincellhell.c +++ b/coincellhell.c @@ -115,8 +115,9 @@ int coincellhell_get_state(struct coincellhell* hell, uint8_t heater, struct hea int16_t* rampTarget = (int16_t*)(buf+3); state->enabled = buf[0] & (1 << 0); - state->ready = buf[0] & (1 << 2); - state->ramp = buf[0] & (1 << 3); + state->ready = buf[0] & (1 << 1); + state->ramp = buf[0] & (1 << 2); + state->fault = buf[0] & (1 << 3); state->setpoint = *setpoint/10.0f; state->rampTarget = *rampTarget/10.0f; @@ -151,8 +152,10 @@ int coincellhell_check_ready(struct coincellhell* hell, bool* ready) { *ready = false; int ret; - while((ret = usbshm_readControlTransferSync(hell->priv, COMMAND_READY, 0, 0, (uint8_t*)ready, 1)) == USBSHM_ERROR_AGAIN) + uint8_t readybits; + while((ret = usbshm_readControlTransferSync(hell->priv, COMMAND_READY, 0, 0, &readybits, 1)) == USBSHM_ERROR_AGAIN) usleep(100000); + *ready = !(~readybits & 0x0F); return ret == 1 ? 0 : -1; } diff --git a/coincellhell.h b/coincellhell.h index b0a490a..061ab15 100644 --- a/coincellhell.h +++ b/coincellhell.h @@ -54,6 +54,7 @@ struct heater_state bool enabled; bool ready; bool ramp; + bool fault; uint8_t dacCommand; float setpoint; diff --git a/main.c b/main.c index 09c8650..a5d41f2 100644 --- a/main.c +++ b/main.c @@ -186,8 +186,9 @@ static int process_commands(char** commands, size_t command_count, struct coince break; } - printf("Heater %d:\n\tEnabled: %s\n\tReady: %s\n\tRamp: %s\n\tSet point: %f\n\tDAC command: %d\n", - i, state.enabled ? "True" : "False", state.ready ? "True" : "False", state.ramp ? "True" : "False", state.setpoint, state.dacCommand); + printf("Heater %d:\n\tEnabled: %s\n\tReady: %s\n\tRamp: %s\n\tFault: %s\n\tSet point: %f\n\tDAC command: %d\n", + i, state.enabled ? "True" : "False", state.ready ? "True" : "False", state.ramp ? "True" : "False", state.fault ? "True" : "False", + state.setpoint, state.dacCommand); float temperature; ret = coincellhell_get_temperature(hell, i, TEMP_LOCATION_BOTH, &temperature); -- GitLab