@@ -5,32 +5,40 @@
#include "config.h"
#include "states.h"
#include "syslib.h"
#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)
#define SW_LEFT_PRESSED (sw_left_last == 0 && sw_left == 1)
#define SW_RIGHT_PRESSED (sw_right_last == 0 && sw_right == 1)
// States
static uint8_t trigger_drawsetpoint = 1;
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;
uint8_t temp_changed = status->temp != last_temp;
last_temp = status->temp;
@@ -93,25 +101,25 @@ void display_process(therm_settings_t* s
ssd1306_drawstring("Device won't boot", 2, 0);
ssd1306_drawstring("until reflashed!", 3, 0);
bootloader_enter(); // Resets into bootloader
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;
case 0:
status->state = STATE_IDLE;
//flash_erase();
NVIC_SystemReset();
default:
}
else if(SW_UP_PRESSED && goto_mode < 3) {
goto_mode++;
else if(SW_DOWN_PRESSED && goto_mode > 0) {
@@ -333,13 +341,13 @@ void display_process(therm_settings_t* s
// Event Handler
// N/A
case STATE_PREHEAT_BREW:
case STATE_PREHEAT:
// Write text to OLED
// [ therm : preheating brew ]
// [ 30 => 120 C ]
ssd1306_drawstring("Preheating...", 0, 0);
//ssd1306_drawlogo();
@@ -355,18 +363,18 @@ void display_process(therm_settings_t* s
else {
user_input(&set->val.setpoint_brew);
if(status->temp >= status->setpoint) {
status->state = STATE_MAINTAIN_BREW;
status->state = STATE_MAINTAIN;
case STATE_MAINTAIN_BREW:
case STATE_MAINTAIN:
// [ therm : ready to brew ]
ssd1306_drawstring("Preheated!", 0, 0);
@@ -384,62 +392,13 @@ void display_process(therm_settings_t* s
case STATE_PREHEAT_STEAM:
// [ therm : preheating steam ]
draw_setpoint(status);
status->pid_enabled = 1;
status->setpoint = set->val.setpoint_steam;
// Button handler
if(SW_BTN_PRESSED) {
user_input(&set->val.setpoint_steam);
status->state = STATE_MAINTAIN_STEAM;
case STATE_MAINTAIN_STEAM:
// [ therm : ready to steam ]
ssd1306_drawstring("Ready to Steam!", 0, 0);
// Thermocouple error
case STATE_TC_ERROR:
ssd1306_drawstring("Error: ", 0, 0);
@@ -500,13 +459,15 @@ void display_process(therm_settings_t* s
sw_right_last = sw_right;
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];
itoa_fp(status->temp, status->temp_frac, tempstr);
ssd1306_drawstringbig(" ", 3, 0);
ssd1306_drawstringbig(tempstr, 3, 0);
#ifndef DISPLAY_H
#define DISPLAY_H
void display_process(therm_settings_t* set, therm_status_t* status);
void draw_setpoint(therm_status_t* status);
#endif
@@ -70,13 +70,13 @@ int main(void)
status.state = STATE_IDLE;
status.setpoint = 70;
status.pid_enabled = 0;
// 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);
ssd1306_drawstring("protofusion.org/therm", 3, 0);
HAL_Delay(1000);
@@ -43,15 +43,13 @@ enum state {
STATE_SETSTEPS,
STATE_SETWINDUP,
STATE_SETBOOTTOBREW,
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,
};
Status change: