@@ -176,15 +176,17 @@ void update_temp() {
// Assemble data array into one var
uint16_t temp_pre = rxdatal[0] | (rxdatah[0]<<8);
if(temp_pre & 0b0000000000000010) {
ssd1306_clearscreen();
ssd1306_DrawString("Fatal Error", 3, 35);
//ssd1306_DrawString("Fatal Error", 3, 35);
HAL_Delay(100);
state = STATE_TC_ERROR;
temp = 0;
temp_frac = 0;
}
else if(temp_pre & 0b0000000000000001 && !ignore_tc_error) {
state_resume = state;
@@ -228,23 +230,24 @@ void update_temp() {
{
temp = temp_pre * signint;
// Print temp to cdc
/*
CDC_Transmit_FS("Temp: ", 6);
char tempstr[6];
zitoa(temp, tempstr);
CDC_Transmit_FS(tempstr, sizeof(tempstr));
CDC_Transmit_FS("\r\n", 2);
*/
// PID implementation
// TODO: Make struct that has the last_temp and i_state in it, pass by ref. Make struct that has other input values maybe.
int16_t last_pid_temp = 0;
@@ -348,22 +351,12 @@ void process()
if(ticks - last_ssr_on > ssr_output || ssr_output == 0)
HAL_GPIO_WritePin(SSR_PIN, 0);
void draw_setpoint() {
char tempstr[3];
itoa_fp(temp, temp_frac, tempstr);
ssd1306_DrawStringBig(" ", 3, 0);
ssd1306_DrawStringBig(tempstr, 3, 0);
ssd1306_DrawStringBig(">", 3, 74);
itoa(setpoint, tempstr, 10);
ssd1306_DrawStringBig(" ", 3, 90);
ssd1306_DrawStringBig(tempstr, 3, 90);
uint8_t goto_mode = 2;
// State machine
uint8_t sw_btn_last = 0;
uint8_t sw_up_last = 0;
@@ -447,12 +440,41 @@ uint8_t final_setpoint = 0;
// press center to go to the next one, and press left or right or something to confirm
// When executing, complete on time AND(?) temperature. Maybe allow switching to OR via settings
////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t trigger_drawsetpoint = 1;
int32_t temp_last = 43002;
int32_t setpoint_last = 10023;
// FIXME: need to do this when switching modes too
if(temp != temp_last || trigger_drawsetpoint) {
if(trigger_drawsetpoint)
if(setpoint != setpoint_last || trigger_drawsetpoint) {
trigger_drawsetpoint = 0;
setpoint_last = setpoint;
temp_last = temp;
void machine()
uint8_t last_state = state;
uint8_t temp_changed = temp != last_temp;
last_temp = temp;
@@ -764,12 +786,13 @@ void machine()
// Write text to OLED
// [ therm : preheating brew ]
// [ 30 => 120 C ]
ssd1306_DrawString("Preheating...", 0, 0);
//ssd1306_drawlogo();
draw_setpoint();
pid_enabled = 1;
setpoint = setpoint_brew;
// Button handler
if(SW_BTN_PRESSED) {
save_setpoints(); // TODO: Check for mod
@@ -896,12 +919,13 @@ void machine()
if(last_state != state) {
// Clear screen on state change
goto_mode = 2;
trigger_drawsetpoint = 1;
// Last buttonpress
sw_btn_last = sw_btn;
sw_up_last = sw_up;
Status change: