diff --git a/display.c b/display.c --- a/display.c +++ b/display.c @@ -341,8 +341,7 @@ void display_process(therm_settings_t* s // Button handler if(SW_BTN_PRESSED) { - save_settings(); - status->state = STATE_IDLE; + status->state = STATE_SETTEMPOFFSET; } else if(!HAL_GPIO_ReadPin(SW_UP)) { set->temp_units = TEMP_UNITS_FAHRENHEIT; @@ -357,6 +356,37 @@ void display_process(therm_settings_t* s } break; + case STATE_SETTEMPOFFSET: + { + // Write text to OLED + // [ therm :: set temp offset ] + // [ g = 12 ] + ssd1306_DrawString("Thermocouple Offset", 0, 40); + ssd1306_drawlogo(); + + char tempstr[6]; + itoa(set->temp_offset, tempstr, 10); + ssd1306_DrawString("O=", 1, 45); + ssd1306_DrawString(" ", 1, 57); + ssd1306_DrawString(tempstr, 1, 57); + + ssd1306_DrawString("Press to accept", 3, 40); + + // Button handler + if(SW_BTN_PRESSED) { + save_settings(); + status->state = STATE_IDLE; + } + else { + user_input_signed(&set->temp_offset); + } + + // Event Handler + // N/A + + } break; + + case STATE_PREHEAT_BREW: { // Write text to OLED diff --git a/gpio.c b/gpio.c --- a/gpio.c +++ b/gpio.c @@ -20,6 +20,21 @@ void user_input(uint16_t* to_modify) } } +void user_input_signed(int16_t* to_modify) +{ + // TODO: Bounds check on int16_t + if(CHANGE_ELAPSED) { + if(!HAL_GPIO_ReadPin(SW_UP) ) { + CHANGE_RESET; + (*to_modify)++; + } + else if(!HAL_GPIO_ReadPin(SW_DOWN)) { + CHANGE_RESET; + (*to_modify)--; + } + } +} + void init_gpio(void) { diff --git a/gpio.h b/gpio.h --- a/gpio.h +++ b/gpio.h @@ -9,6 +9,7 @@ void user_input(uint16_t* to_modify); +void user_input_signed(int16_t* to_modify); void init_gpio(void); #endif diff --git a/main.c b/main.c --- a/main.c +++ b/main.c @@ -206,12 +206,14 @@ void update_temp() { status.temp += 3200; status.temp_frac = status.temp % 100; status.temp /= 100; + status.temp += set.temp_offset; } // Use Celsius values else { status.temp = temp_pre * signint; + status.temp += set.temp_offset; } } } diff --git a/states.h b/states.h --- a/states.h +++ b/states.h @@ -17,6 +17,7 @@ typedef struct { uint16_t k_p; uint16_t k_i; uint16_t k_d; + int16_t temp_offset; uint8_t ignore_tc_error; int16_t setpoint_brew; int16_t setpoint_steam; @@ -39,6 +40,7 @@ enum state { STATE_SETWINDUP, STATE_SETBOOTTOBREW, STATE_SETUNITS, + STATE_SETTEMPOFFSET, STATE_PREHEAT_BREW, STATE_MAINTAIN_BREW,