@@ -11,27 +11,30 @@
// Solid-state relay maximum on-time
#define SSR_PERIOD 200
// Interval of PID calculations
#define PID_PERIOD 120
// Pin settings
#define LED_POWER GPIOF,GPIO_PIN_0
#define MAX_CS GPIOA,GPIO_PIN_15
#define SW_BTN GPIOB, GPIO_PIN_4
#define SW_UP GPIOB, GPIO_PIN_7
#define SW_DOWN GPIOB, GPIO_PIN_3
#define SW_LEFT GPIOB, GPIO_PIN_5
#define SW_RIGHT GPIOB, GPIO_PIN_6
#define SSR_PIN GPIOA, GPIO_PIN_1
// Visual niceness
#define hal_init() HAL_Init()
// Add bootloader option to top of idle screen menu
#define BOOTLOADER_SHORTCUT
#endif
// vim:softtabstop=4 shiftwidth=4 expandtab
@@ -14,131 +14,134 @@
// Private function prototypes
static void draw_setpoint(therm_status_t* status);
// 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;
static uint8_t goto_mode = MODE_HEAT;
static uint8_t reset_mode = RESET_RESET;
// 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;
uint8_t sw_btn = !HAL_GPIO_ReadPin(SW_BTN);
uint8_t sw_up = !HAL_GPIO_ReadPin(SW_UP);
uint8_t sw_down = !HAL_GPIO_ReadPin(SW_DOWN);
uint8_t sw_left = !HAL_GPIO_ReadPin(SW_LEFT);
uint8_t sw_right = !HAL_GPIO_ReadPin(SW_RIGHT);
switch(status->state)
// Idle state
case STATE_IDLE:
// Write text to OLED
// [ therm :: idle ]
ssd1306_drawstring("therm :: idle ", 0, 40);
status->pid_enabled = 0;
if(temp_changed) {
char tempstr[6];
itoa_fp(status->temp, status->temp_frac, tempstr);
ssd1306_drawstring("Temp: ", 3, 40);
ssd1306_drawstring(" ", 3, 72);
ssd1306_drawstring(tempstr, 3, 72);
}
ssd1306_drawlogo();
switch(goto_mode) {
case MODE_BOOTLOADER:
ssd1306_drawstring("-> loader ", 1, 40);
} break;
case MODE_HEAT:
ssd1306_drawstring("-> heat ", 1, 40);
case MODE_SETUP:
ssd1306_drawstring("-> setup ", 1, 40);
case MODE_RESET:
ssd1306_drawstring("-> reset ", 1, 40);
#ifdef BOOTLOADER_SHORTCUT
ssd1306_drawstring("-> dfu ", 1, 40);
// Button handler
if(SW_BTN_PRESSED) {
ssd1306_clearscreen();
ssd1306_drawstring("Bootloader Entered", 0, 0);
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
status->state = STATE_PREHEAT;
break;
status->state = STATE_SETP;
status->state = STATE_IDLE;
//flash_erase();
NVIC_SystemReset();
status->state = STATE_RESET;
reset_mode = RESET_RESET;
status->state = STATE_RESET; // Just in case
default:
else if(SW_DOWN_PRESSED && goto_mode < (MODE_SIZE - 1)) {
goto_mode++;
else if(SW_UP_PRESSED && goto_mode > 0) {
goto_mode--;
// Event Handler
// N/A
case STATE_SETP:
// [ therm :: set p ]
// [ p = 12 ]
ssd1306_drawstring("Proportional", 0, 40);
@@ -421,48 +424,112 @@ void display_process(therm_settings_t* s
else
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());
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);
switch(reset_mode) {
case RESET_RESET:
case RESET_BOOTLOADER:
ssd1306_drawstring("-> bootloader", 1, 40);
case RESET_EXIT:
ssd1306_drawstring("-> exit ", 1, 40);
HAL_Delay(1000);
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
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;
#ifndef STATES_H
#define STATES_H
#include "config.h"
typedef struct {
int32_t temp;
uint8_t temp_frac;
uint8_t state_resume;
uint8_t state;
int32_t setpoint;
uint8_t pid_enabled;
uint8_t error_code;
} therm_status_t;
typedef union
struct {
uint32_t boottobrew;
uint32_t temp_units;
uint32_t windup_guard;
uint32_t k_p;
uint32_t k_i;
uint32_t k_d;
int32_t temp_offset;
uint32_t ignore_error;
int32_t setpoint_brew;
int32_t setpoint_steam;
} val;
@@ -29,35 +31,45 @@ typedef union
uint16_t data[128];
} therm_settings_t;
enum tempunits {
TEMP_UNITS_CELSIUS = 0,
TEMP_UNITS_FAHRENHEIT,
};
enum state {
STATE_IDLE = 0,
STATE_SETP,
STATE_SETI,
STATE_SETD,
STATE_SETSTEPS,
STATE_SETWINDUP,
STATE_SETBOOTTOBREW,
STATE_SETUNITS,
STATE_SETTEMPOFFSET,
STATE_PREHEAT,
STATE_MAINTAIN,
STATE_TC_ERROR,
STATE_RESET,
enum GOTO_MODE {
MODE_HEAT = 0,
MODE_BOOTLOADER,
MODE_HEAT,
MODE_SETUP,
MODE_RESET,
MODE_SIZE,
enum RESET_MODE {
RESET_RESET = 0,
RESET_BOOTLOADER,
RESET_EXIT,
RESET_SIZE,
Status change: