diff --git a/src/display.c b/src/display.c --- a/src/display.c +++ b/src/display.c @@ -3,10 +3,6 @@ // #include "display.h" -#include "gpio.h" -#include "ssd1306/ssd1306.h" -#include "system/stringhelpers.h" -#include "flash.h" // Private function prototypes static void draw_setpoint(therm_status_t* status); @@ -30,9 +26,8 @@ static uint8_t sw_right_last = 0; // States static uint8_t trigger_drawsetpoint = 1; -static int16_t last_temp = 21245; -static int16_t last_temp_frac = 21245; -static int16_t last_state = 123; +static float last_temp = 21245; +static int16_t last_state = STATE_RESET; static uint8_t goto_mode = MODE_HEAT; static uint8_t reset_mode = RESET_REBOOT; @@ -72,6 +67,8 @@ void display_process(void) uint8_t sw_left = !HAL_GPIO_ReadPin(SW_LEFT); uint8_t sw_right = !HAL_GPIO_ReadPin(SW_RIGHT); + uint8_t aux_input = !HAL_GPIO_ReadPin(AUX_INPUT); + switch(status->state) { // Idle state @@ -115,12 +112,12 @@ void display_process(void) ssd1306_drawstring("\x83 reset ", 1, 40); } break; -#ifdef BOOTLOADER_SHORTCUT + #ifdef BOOTLOADER_SHORTCUT case MODE_BOOTLOADER: { ssd1306_drawstring("\x83 dfu ", 1, 40); } -#endif + #endif } // Button handler @@ -136,7 +133,7 @@ void display_process(void) status->state = STATE_RESET; reset_mode = RESET_REBOOT; break; -#ifdef BOOTLOADER_SHORTCUT + #ifdef BOOTLOADER_SHORTCUT case MODE_BOOTLOADER: ssd1306_clearscreen(); ssd1306_drawstring("Bootloader Entered", 0, 0); @@ -145,7 +142,7 @@ void display_process(void) // bootloader_enter(); // Resets into bootloader status->state = STATE_RESET; // Just in case break; -#endif + #endif default: status->state = STATE_PREHEAT; } @@ -157,7 +154,6 @@ void display_process(void) goto_mode--; } - // Event Handler // N/A @@ -246,10 +242,7 @@ void display_process(void) // Button handler if(SW_BTN_PRESSED) { - if(set->val.control_mode == MODE_PID) - status->state = STATE_SETP; - else - status->state = STATE_SETHYSTERESIS; + status->state = STATE_SETSETPOINTCOUNT; } else if (!HAL_GPIO_ReadPin(SW_UP)) { set->val.plant_type = PLANT_COOLER; @@ -263,6 +256,86 @@ void display_process(void) } break; + case STATE_SETSETPOINTCOUNT: + { + // Write text to OLED + // [ therm :: number of setpoints ] + // [ p = 12 ] + ssd1306_drawstring("Num Setpoints", 0, 40); + ssd1306_drawlogo(); + + ssd1306_drawchar(updown(), 1, 52); + + char tempstr[12]; + snprintf(tempstr, 12, "%ld ", set->val.setpoint_count); + ssd1306_drawstring(tempstr, 1, 60); + ssd1306_drawstring("Press to accept", 3, 40); + + // Button handler + if(SW_BTN_PRESSED) { + if (set->val.setpoint_count > 1) + { + status->state = STATE_SETSETPOINTAUXSELECTENABLE; + } + else + { + if(set->val.control_mode == MODE_PID) + status->state = STATE_SETP; + else + status->state = STATE_SETHYSTERESIS; + } + } + else { + user_input_min_max((uint16_t*)&set->val.setpoint_count, 1, MAX_SETPOINTS); + + //update setpoint index to the new maximum + if (status->setpoint_index >= set->val.setpoint_count) + { + status->setpoint_index = set->val.setpoint_count - 1; + } + } + + // Event Handler + // N/A + + } break; + + + case STATE_SETSETPOINTAUXSELECTENABLE: + { + // Write text to OLED + // [ therm :: set p ] + // [ p = 12 ] + ssd1306_drawstring("Aux Select", 0, 40); + ssd1306_drawlogo(); + + ssd1306_drawchar(updown(), 1, 52); + + if(set->val.setpoint_aux_select_enable == AUX_ENABLE) + ssd1306_drawstring("Enable ", 1, 60); + else + ssd1306_drawstring("Disable", 1, 60); + + ssd1306_drawstring("Press to accept", 3, 40); + + // Button handler + if(SW_BTN_PRESSED) { + if(set->val.control_mode == MODE_PID) + status->state = STATE_SETP; + else + status->state = STATE_SETHYSTERESIS; + } + else if (!HAL_GPIO_ReadPin(SW_UP)) { + set->val.setpoint_aux_select_enable = AUX_ENABLE; + } + else if(!HAL_GPIO_ReadPin(SW_DOWN)) { + set->val.setpoint_aux_select_enable = AUX_DISABLE; + } + + // Event Handler + // N/A + + } break; case STATE_SETP: @@ -276,7 +349,7 @@ void display_process(void) ssd1306_drawchar(updown(), 1, 52); char tempstr[12]; - snprintf(tempstr, 12, "P=%d", set->val.k_p); + snprintf(tempstr, 12, "P=%ld", set->val.k_p); ssd1306_drawstring(tempstr, 1, 60); ssd1306_drawstring("Press to accept", 3, 40); @@ -304,7 +377,7 @@ void display_process(void) ssd1306_drawchar(updown(), 1, 52); char tempstr[12]; - snprintf(tempstr, 12, "I=%d", set->val.k_i); + snprintf(tempstr, 12, "I=%ld", set->val.k_i); ssd1306_drawstring(tempstr, 1, 60); ssd1306_drawstring("Press to accept", 3, 40); @@ -333,7 +406,7 @@ void display_process(void) ssd1306_drawchar(updown(), 1, 52); char tempstr[12]; - snprintf(tempstr, 12, "D=%d", set->val.k_d); + snprintf(tempstr, 12, "D=%ld", set->val.k_d); ssd1306_drawstring(tempstr, 1, 60); ssd1306_drawstring("Press to accept", 3, 40); @@ -362,7 +435,7 @@ void display_process(void) ssd1306_drawchar(updown(), 1, 52); char tempstr[12]; - snprintf(tempstr, 12, "H=%d", set->val.hysteresis); + snprintf(tempstr, 12, "H=%ld", set->val.hysteresis); ssd1306_drawstring(tempstr, 1, 60); ssd1306_drawstring("Press to accept", 3, 40); @@ -392,7 +465,7 @@ void display_process(void) ssd1306_drawchar(updown(), 1, 52); char tempstr[12]; - snprintf(tempstr, 12, "G=%d", set->val.windup_guard); + snprintf(tempstr, 12, "G=%ld", set->val.windup_guard); ssd1306_drawstring(tempstr, 1, 60); ssd1306_drawstring("Press to accept", 3, 40); @@ -490,7 +563,7 @@ void display_process(void) ssd1306_drawchar(updown(), 1, 52); char tempstr[12]; - snprintf(tempstr, 12, "O=%d", set->val.temp_offset); + snprintf(tempstr, 12, "O=%ld", set->val.temp_offset); ssd1306_drawstring(tempstr, 1, 60); ssd1306_drawstring("Press to accept", 3, 40); @@ -524,15 +597,29 @@ void display_process(void) draw_setpoint(status); status->pid_enabled = 1; - status->setpoint = set->val.setpoint_brew; + status->setpoint = set->val.setpoints[status->setpoint_index]; // Button handler if(SW_BTN_PRESSED) { status->state = STATE_IDLE; flash_savesettings(); } + else if (!(set->val.setpoint_aux_select_enable) && SW_LEFT_PRESSED) + { + if (status->setpoint_index > 0) + { + status->setpoint_index--; + } + } + else if (!(set->val.setpoint_aux_select_enable) && SW_RIGHT_PRESSED) + { + if (status->setpoint_index < (set->val.setpoint_count - 1)) + { + status->setpoint_index++; + } + } else { - user_input_signed(&set->val.setpoint_brew); + user_input_signed(&set->val.setpoints[status->setpoint_index]); } // Event Handler @@ -540,6 +627,15 @@ void display_process(void) status->state = STATE_MAINTAIN; } + if(set->val.setpoint_aux_select_enable && aux_input) + { + status->setpoint_index = 1; + } + else if(set->val.setpoint_aux_select_enable && !aux_input) + { + status->setpoint_index = 0; + } + } break; case STATE_MAINTAIN: @@ -555,15 +651,29 @@ void display_process(void) draw_setpoint(status); status->pid_enabled = 1; - status->setpoint = set->val.setpoint_brew; + status->setpoint = set->val.setpoints[status->setpoint_index]; // Button handler if(SW_BTN_PRESSED) { status->state = STATE_IDLE; flash_savesettings(); } + else if (!(set->val.setpoint_aux_select_enable) && SW_LEFT_PRESSED) + { + if (status->setpoint_index > 0) + { + status->setpoint_index--; + } + } + else if (!(set->val.setpoint_aux_select_enable) && SW_RIGHT_PRESSED) + { + if (status->setpoint_index < (set->val.setpoint_count - 1)) + { + status->setpoint_index++; + } + } else { - user_input_signed(&set->val.setpoint_brew); + user_input_signed(&set->val.setpoints[status->setpoint_index]); } // Event Handler @@ -601,9 +711,9 @@ void display_process(void) // Button handler if(SW_BTN_PRESSED) { status->state = STATE_IDLE; -#ifdef MAX31865_RTD_SENSOR + #ifdef MAX31865_RTD_SENSOR max31865_clear_errors(spi_get()); -#endif + #endif } else if(SW_RIGHT_PRESSED) { set->val.ignore_error = 1; @@ -732,7 +842,7 @@ static void draw_setpoint(therm_status_t if(status->setpoint != setpoint_last || trigger_drawsetpoint) { char tempstr[4]; - snprintf(tempstr, 4, "%g ", status->setpoint); + snprintf(tempstr, 4, "%ld ", status->setpoint); ssd1306_drawstringbig(tempstr, 3, 90); }