@@ -232,385 +232,389 @@ void display_process(therm_settings_t* s
// N/A
} break;
case STATE_SETI:
{
// Write text to OLED
// [ therm :: set i ]
// [ i = 12 ]
ssd1306_drawstring("Integral", 0, 40);
ssd1306_drawlogo();
char tempstr[6];
itoa(set->val.k_i, tempstr, 10);
ssd1306_drawstring("I=", 1, 45);
ssd1306_drawstring(" ", 1, 57);
ssd1306_drawstring(tempstr, 1, 57);
ssd1306_drawstring("Press to accept", 3, 40);
// Button handler
if(SW_BTN_PRESSED) {
status->state = STATE_SETD;
}
else {
user_input((uint16_t*)&set->val.k_i);
// Event Handler
case STATE_SETD:
// [ therm :: set d ]
// [ d = 12 ]
ssd1306_drawstring("Derivative", 0, 40);
itoa(set->val.k_d, tempstr, 10);
ssd1306_drawstring("D=", 1, 45);
status->state = STATE_SETWINDUP;
user_input((uint16_t*)&set->val.k_d);
case STATE_SETWINDUP:
// [ therm :: set windup ]
// [ g = 12 ]
ssd1306_drawstring("Windup Guard", 0, 40);
itoa(set->val.windup_guard, tempstr, 10);
ssd1306_drawstring("G=", 1, 45);
status->state = STATE_SETBOOTTOBREW;
user_input((uint16_t*)&set->val.windup_guard);
case STATE_SETBOOTTOBREW:
ssd1306_drawstring("Start on Boot", 0, 40);
ssd1306_drawstring("sob=", 1, 45);
if(set->val.boottobrew)
ssd1306_drawstring("Enabled ", 1, 70);
else
ssd1306_drawstring("Disabled", 1, 70);
status->state = STATE_SETUNITS;
else if(!HAL_GPIO_ReadPin(SW_UP)) {
set->val.boottobrew = 1;
else if(!HAL_GPIO_ReadPin(SW_DOWN)) {
set->val.boottobrew = 0;
case STATE_SETUNITS:
ssd1306_drawstring("Units: ", 0, 40);
if(set->val.temp_units == TEMP_UNITS_FAHRENHEIT)
ssd1306_drawstring("Fahrenheit", 1, 60);
ssd1306_drawstring("Celsius ", 1, 60);
status->state = STATE_SETTEMPOFFSET;
set->val.temp_units = TEMP_UNITS_FAHRENHEIT;
set->val.temp_units = TEMP_UNITS_CELSIUS;
case STATE_SETTEMPOFFSET:
// [ therm :: set temp offset ]
ssd1306_drawstring("Temp Cal Offset", 0, 40);
itoa(set->val.temp_offset, tempstr, 10);
ssd1306_drawstring("O=", 1, 45);
flash_save(set);
status->state = STATE_IDLE;
user_input_signed(&set->val.temp_offset);
case STATE_PREHEAT:
// [ therm : preheating brew ]
// [ 30 => 120 C ]
ssd1306_drawstring("Preheating...", 0, 0);
if(set->val.plant_type == PLANT_HEATER)
ssd1306_drawstring("Precooling...", 0, 0);
//ssd1306_drawlogo();
draw_setpoint(status);
status->pid_enabled = 1;
status->setpoint = set->val.setpoint_brew;
user_input((uint16_t*)&set->val.setpoint_brew);
if(status->temp >= status->setpoint) {
status->state = STATE_MAINTAIN;
case STATE_MAINTAIN:
// [ therm : ready to brew ]
ssd1306_drawstring("Preheated!", 0, 0);
ssd1306_drawstring("Precooled!", 0, 0);
// Thermocouple error
case STATE_TC_ERROR:
// [ therm : ready to steam ]
ssd1306_drawstring("Error: ", 0, 0);
itoa(status->error_code, tempstr, 10);
ssd1306_drawstring(tempstr, 0, 57);
//TODO: add RTD error codes
if(status->error_code == 1)
ssd1306_drawstring(" TC Open Circuit", 1, 0);
else if(status->error_code == 4)
ssd1306_drawstring(" TC Short to GND", 1, 0);
else if(status->error_code == 8)
ssd1306_drawstring(" TC Short to VCC", 1, 0);
ssd1306_drawstring("#?, Unknown Error", 1, 0);
ssd1306_drawstring(" ", 2, 0);
ssd1306_drawstring("-> to ignore all or", 2, 0);
ssd1306_drawstring("press to continue", 3, 0);
#ifdef MAX31865_RTD_SENSOR
max31865_clear_errors(spi_get());
#endif
else if(SW_RIGHT_PRESSED) {
set->val.ignore_error = 1;
// Maybe handle if TC is plugged in
// Reset state
case STATE_RESET:
// [ therm :: reset ]
ssd1306_drawstring("therm :: reset ", 0, 40);
status->pid_enabled = 0;
switch(reset_mode) {
case RESET_DEFAULTS:
ssd1306_drawstring("-> defaults ", 1, 40);
case RESET_BOOTLOADER:
ssd1306_drawstring("-> bootloader ", 1, 40);
case RESET_REBOOT:
ssd1306_drawstring("-> reboot ", 1, 40);
case RESET_EXIT:
ssd1306_drawstring("-> exit ", 1, 40);
ssd1306_clearscreen();
ssd1306_drawstring("Bootloader Entered", 0, 0);
ssd1306_drawstring("Device won't boot", 2, 0);
ssd1306_drawstring("until reflashed!", 3, 0);
HAL_Delay(1000);
bootloader_enter(); // Resets into bootloader
status->state = STATE_RESET; // Just in case
status->state = STATE_RESET;
flash_load_defaults(set);
NVIC_SystemReset();
else if(SW_DOWN_PRESSED && reset_mode < (RESET_SIZE-1)) {
reset_mode++;
else if(SW_UP_PRESSED && reset_mode > 0) {
reset_mode--;
// Something is terribly wrong
default:
if(last_state != status->state) {
// Clear screen on state change
goto_mode = MODE_HEAT;
trigger_drawsetpoint = 1;
// Last buttonpress
sw_btn_last = sw_btn;
sw_up_last = sw_up;
sw_down_last = sw_down;
sw_left_last = sw_left;
sw_right_last = sw_right;
Status change: