diff --git a/coincellhell.c b/coincellhell.c index b76c7dddfe808da617609723e97af1b416fb2232..ca9801743480269a6d985bf6eecf21daa7bf9d98 100644 --- a/coincellhell.c +++ b/coincellhell.c @@ -117,6 +117,7 @@ int coincellhell_get_state(struct coincellhell* hell, uint8_t heater, struct hea state->ready = buf[0] & (1 << 1); state->ramp = buf[0] & (1 << 2); state->fault = buf[0] & (1 << 3); + state->faultType = buf[6]; state->setpoint = *setpoint/10.0f; state->rampTarget = *rampTarget/10.0f; @@ -234,3 +235,23 @@ void coincellhell_disconnect(struct coincellhell* hell) hell->priv = NULL; } +const char* coincellhell_string_for_fault(fault_t fault) +{ + switch(fault) + { + case FAULT_NONE: + return "no fault detected"; + case FAULT_FRONT_SENSOR: + return "unable to read from front sensor"; + case FAULT_SIDE_SENSOR: + return "unable to read from side sensor"; + case FAULT_OVERTEMP: + return "system shutdown due to a overtemperature event"; + case FAULT_UNDERTEMP: + return "system shutdown due to a undertemperature event"; + case FAULT_UNSPECIFIED: + default: + return "a unspecified fault occured"; + } +} + diff --git a/coincellhell/coincellhell.h b/coincellhell/coincellhell.h index 698a5f04a68c2c740763858a8059e7a73bc097c2..2a1c337c7438b52f60835c85c4d965e8ff918661 100644 --- a/coincellhell/coincellhell.h +++ b/coincellhell/coincellhell.h @@ -59,6 +59,8 @@ struct heater_state bool ramp; /** true if the system has detected a fault with this heater*/ bool fault; + /** the detected fault type as a fault_t enum*/ + fault_t faultType; /** current command (0-255) that is being sent to the dac for this heater*/ uint8_t dacCommand; /** current target temperature for this heater*/ @@ -156,6 +158,13 @@ int coincellhell_set_led(struct coincellhell* hell, bool on); */ void coincellhell_disconnect(struct coincellhell* hell); +/** + * @brief Returns a human readable string for a given fault. + * @param fault the fault code + * @return a const string describeing the fault + */ +const char* coincellhell_string_for_fault(fault_t fault); + int coincellhell_write_eeprom(struct coincellhell* hell, uint16_t addr, uint16_t value); uint16_t coincellhell_read_eeprom(struct coincellhell* hell, uint16_t addr); uint8_t coincellhell_read_oscal(struct coincellhell* hell); diff --git a/coincellhell/usbcommands.h b/coincellhell/usbcommands.h index 6bced32ec696d02bb39f8bbdbb20dddae04ee0da..47e8990391bf9e7a1959a5709d04d77639d3d092 100644 --- a/coincellhell/usbcommands.h +++ b/coincellhell/usbcommands.h @@ -31,6 +31,15 @@ typedef enum { TEMP_LOCATION_INVALID, } temperature_sensor_location_t; +typedef enum { + FAULT_NONE = 0, + FAULT_FRONT_SENSOR, + FAULT_SIDE_SENSOR, + FAULT_OVERTEMP, + FAULT_UNDERTEMP, + FAULT_UNSPECIFIED +} fault_t; + /* * @} */