diff --git a/display.c b/display.c --- a/display.c +++ b/display.c @@ -8,15 +8,19 @@ #include "flash.h" #include "gpio.h" -static uint8_t goto_mode = 2; +// Private function prototypes +static void draw_setpoint(therm_status_t* status); -// State machine + +// Button transition variables static uint8_t sw_btn_last = 0; static uint8_t sw_up_last = 0; static uint8_t sw_down_last = 0; static uint8_t sw_left_last = 0; static uint8_t sw_right_last = 0; + +// Buttonpress macros #define SW_BTN_PRESSED (sw_btn_last == 0 && sw_btn == 1) // rising edge on buttonpress #define SW_UP_PRESSED (sw_up_last == 0 && sw_up == 1) #define SW_DOWN_PRESSED (sw_down_last == 0 && sw_down == 1) @@ -24,10 +28,14 @@ static uint8_t sw_right_last = 0; #define SW_RIGHT_PRESSED (sw_right_last == 0 && sw_right == 1) +// States static uint8_t trigger_drawsetpoint = 1; +static int16_t last_temp = 21245; +static uint8_t goto_mode = 2; -static int16_t last_temp = 21245; + +// Display state machine void display_process(therm_settings_t* set, therm_status_t* status) { uint8_t last_state = status->state; @@ -96,7 +104,7 @@ void display_process(therm_settings_t* s status->state = STATE_IDLE; // Just in case } break; case 2: - status->state = STATE_PREHEAT_BREW; + status->state = STATE_PREHEAT; break; case 1: status->state = STATE_SETP; @@ -108,7 +116,7 @@ void display_process(therm_settings_t* s break; default: - status->state = STATE_PREHEAT_BREW; + status->state = STATE_PREHEAT; } } else if(SW_UP_PRESSED && goto_mode < 3) { @@ -336,7 +344,7 @@ void display_process(therm_settings_t* s } break; - case STATE_PREHEAT_BREW: + case STATE_PREHEAT: { // Write text to OLED // [ therm : preheating brew ] @@ -358,12 +366,12 @@ void display_process(therm_settings_t* s // Event Handler if(status->temp >= status->setpoint) { - status->state = STATE_MAINTAIN_BREW; + status->state = STATE_MAINTAIN; } } break; - case STATE_MAINTAIN_BREW: + case STATE_MAINTAIN: { // Write text to OLED // [ therm : ready to brew ] @@ -387,56 +395,7 @@ void display_process(therm_settings_t* s } break; - case STATE_PREHEAT_STEAM: - { - // Write text to OLED - // [ therm : preheating steam ] - // [ 30 => 120 C ] - ssd1306_drawstring("Preheating...", 0, 0); - //ssd1306_drawlogo(); - draw_setpoint(status); - status->pid_enabled = 1; - status->setpoint = set->val.setpoint_steam; - - // Button handler - if(SW_BTN_PRESSED) { - status->state = STATE_IDLE; - } - else { - user_input(&set->val.setpoint_steam); - } - - // Event Handler - if(status->temp >= status->setpoint) { - status->state = STATE_MAINTAIN_STEAM; - } - - } break; - - case STATE_MAINTAIN_STEAM: - { - // Write text to OLED - // [ therm : ready to steam ] - // [ 30 => 120 C ] - ssd1306_drawstring("Ready to Steam!", 0, 0); - //ssd1306_drawlogo(); - draw_setpoint(status); - status->pid_enabled = 1; - status->setpoint = set->val.setpoint_steam; - - // Button handler - if(SW_BTN_PRESSED) { - status->state = STATE_IDLE; - } - else { - user_input(&set->val.setpoint_steam); - } - - // Event Handler - // N/A - - } break; - + // Thermocouple error case STATE_TC_ERROR: { // Write text to OLED @@ -503,7 +462,9 @@ void display_process(therm_settings_t* s static int32_t temp_last = 43002; static int32_t setpoint_last = 10023; -void draw_setpoint(therm_status_t* status) { + +// Draw current setpoint on display +static void draw_setpoint(therm_status_t* status) { // FIXME: need to do this when switching modes too if(status->temp != temp_last || trigger_drawsetpoint) { char tempstr[3]; diff --git a/display.h b/display.h --- a/display.h +++ b/display.h @@ -4,6 +4,5 @@ #include "states.h" void display_process(therm_settings_t* set, therm_status_t* status); -void draw_setpoint(therm_status_t* status); #endif diff --git a/main.c b/main.c --- a/main.c +++ b/main.c @@ -73,7 +73,7 @@ int main(void) // Go to brew instead of idle if configured thusly if(set.val.boottobrew) - status.state = STATE_PREHEAT_BREW; + status.state = STATE_PREHEAT; // Startup screen ssd1306_drawstring("therm v0.2", 1, 40); diff --git a/states.h b/states.h --- a/states.h +++ b/states.h @@ -46,12 +46,10 @@ enum state { STATE_SETUNITS, STATE_SETTEMPOFFSET, - STATE_PREHEAT_BREW, - STATE_MAINTAIN_BREW, - STATE_PREHEAT_STEAM, - STATE_MAINTAIN_STEAM, + STATE_PREHEAT, + STATE_MAINTAIN, - STATE_TC_ERROR + STATE_TC_ERROR, }; #endif