diff --git a/display.c b/display.c --- a/display.c +++ b/display.c @@ -7,6 +7,9 @@ #include "syslib.h" #include "flash.h" #include "gpio.h" +#ifdef MAX31865_RTD_SENSOR +#include "max31865.h" +#endif // Private function prototypes static void draw_setpoint(therm_status_t* status); @@ -31,7 +34,7 @@ static uint8_t sw_right_last = 0; // States static uint8_t trigger_drawsetpoint = 1; static int16_t last_temp = 21245; -static uint8_t goto_mode = 2; +static uint8_t goto_mode = MODE_HEAT; @@ -70,22 +73,22 @@ void display_process(therm_settings_t* s ssd1306_drawlogo(); switch(goto_mode) { - case 3: + case MODE_BOOTLOADER: { ssd1306_drawstring("-> loader ", 1, 40); } break; - case 2: + case MODE_HEAT: { ssd1306_drawstring("-> heat ", 1, 40); } break; - case 1: + case MODE_SETUP: { ssd1306_drawstring("-> setup ", 1, 40); } break; - case 0: + case MODE_RESET: { ssd1306_drawstring("-> reset ", 1, 40); } @@ -94,7 +97,7 @@ void display_process(therm_settings_t* s // Button handler if(SW_BTN_PRESSED) { switch(goto_mode) { - case 3: + case MODE_BOOTLOADER: { ssd1306_clearscreen(); ssd1306_drawstring("Bootloader Entered", 0, 0); @@ -103,13 +106,13 @@ void display_process(therm_settings_t* s bootloader_enter(); // Resets into bootloader status->state = STATE_IDLE; // Just in case } break; - case 2: + case MODE_HEAT: status->state = STATE_PREHEAT; break; - case 1: + case MODE_SETUP: status->state = STATE_SETP; break; - case 0: + case MODE_RESET: status->state = STATE_IDLE; //flash_erase(); NVIC_SystemReset(); @@ -119,10 +122,10 @@ void display_process(therm_settings_t* s status->state = STATE_PREHEAT; } } - else if(SW_UP_PRESSED && goto_mode < 3) { + else if(SW_DOWN_PRESSED && goto_mode < (MODE_SIZE - 1)) { goto_mode++; } - else if(SW_DOWN_PRESSED && goto_mode > 0) { + else if(SW_UP_PRESSED && goto_mode > 0) { goto_mode--; } @@ -404,14 +407,16 @@ void display_process(therm_settings_t* s ssd1306_drawstring("Error: ", 0, 0); char tempstr[6]; - itoa(status->tc_errno, tempstr, 10); + itoa(status->error_code, tempstr, 10); ssd1306_drawstring(tempstr, 0, 57); - if(status->tc_errno == 1) + //TODO: add RTD error codes + + if(status->error_code == 1) ssd1306_drawstring(" TC Open Circuit", 1, 0); - else if(status->tc_errno == 4) + else if(status->error_code == 4) ssd1306_drawstring(" TC Short to GND", 1, 0); - else if(status->tc_errno == 8) + else if(status->error_code == 8) ssd1306_drawstring(" TC Short to VCC", 1, 0); else ssd1306_drawstring("#?, Unknown Error", 1, 0); @@ -423,9 +428,12 @@ void display_process(therm_settings_t* s // Button handler if(SW_BTN_PRESSED) { status->state = STATE_IDLE; + #ifdef MAX31865_RTD_SENSOR + max31865_clear_errors(spi_get()); + #endif } else if(SW_RIGHT_PRESSED) { - set->val.ignore_tc_error = 1; + set->val.ignore_error = 1; status->state = STATE_IDLE; } // Event Handler @@ -446,7 +454,7 @@ void display_process(therm_settings_t* s if(last_state != status->state) { // Clear screen on state change - goto_mode = 2; + goto_mode = MODE_HEAT; trigger_drawsetpoint = 1; ssd1306_clearscreen(); }