Changeset - 4ced8964c979
[Not reviewed]
cortex-f0
0 4 0
Ethan Zonca - 9 years ago 2015-11-28 14:36:16
ez@ethanzonca.com
Remove brew and steam states, just use one preheating/preheated stage
4 files changed with 24 insertions and 66 deletions:
0 comments (0 inline, 0 general)
display.c
Show inline comments
 
@@ -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;
 
static uint8_t goto_mode = 2;
 

	
 
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;
 
                        break;
 
                    case 0:
 
                        status->state = STATE_IDLE;
 
                        //flash_erase();
 
                        NVIC_SystemReset(); 
 
                        break;
 

	
 
                    default:
 
                        status->state = STATE_PREHEAT_BREW;
 
                        status->state = STATE_PREHEAT;
 
                }
 
            }
 
            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
 
 
 
        } break;
 

	
 

	
 
        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);
 
            }
 

	
 
            // Event Handler
 
            if(status->temp >= status->setpoint) {
 
                status->state = STATE_MAINTAIN_BREW;
 
                status->state = STATE_MAINTAIN;
 
            }
 
 
 
        } break;
 

	
 
        case STATE_MAINTAIN_BREW:
 
        case STATE_MAINTAIN:
 
        {
 
            // Write text to OLED
 
            // [ therm : ready to brew ]
 
            // [ 30 => 120 C           ]
 
            ssd1306_drawstring("Preheated!", 0, 0);
 
            //ssd1306_drawlogo();
 
@@ -384,62 +392,13 @@ void display_process(therm_settings_t* s
 

	
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 

	
 
        case STATE_PREHEAT_STEAM:
 
        {
 
            // Write text to OLED
 
            // [ therm : preheating steam ]
 
            // [ 30 => 120 C           ]
 
            ssd1306_drawstring("Preheating...", 0, 0);
 
            //ssd1306_drawlogo();
 
            draw_setpoint(status);
 
            status->pid_enabled = 1;
 
	    status->setpoint = set->val.setpoint_steam;
 
	    
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
                status->state = STATE_IDLE;
 
            }
 
            else {
 
                user_input(&set->val.setpoint_steam);
 
            }
 

	
 
            // Event Handler
 
            if(status->temp >= status->setpoint) {
 
                status->state = STATE_MAINTAIN_STEAM;
 
            }
 
 
 
        } break;
 

	
 
        case STATE_MAINTAIN_STEAM:
 
        {
 
            // Write text to OLED
 
            // [ therm : ready to steam ]
 
            // [ 30 => 120 C            ]
 
            ssd1306_drawstring("Ready to Steam!", 0, 0);
 
            //ssd1306_drawlogo();
 
            draw_setpoint(status);
 
            status->pid_enabled = 1;
 
	    status->setpoint = set->val.setpoint_steam;
 

	
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
                status->state = STATE_IDLE;
 
            }
 
            else {
 
                user_input(&set->val.setpoint_steam);
 
            }
 

	
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 

	
 
        // Thermocouple error
 
        case STATE_TC_ERROR:
 
        {
 
            // Write text to OLED
 
            // [ therm : ready to steam ]
 
            // [ 30 => 120 C            ]
 
            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);
display.h
Show inline comments
 
#ifndef DISPLAY_H
 
#define DISPLAY_H
 

	
 
#include "states.h"
 

	
 
void display_process(therm_settings_t* set, therm_status_t* status);
 
void draw_setpoint(therm_status_t* status);
 

	
 
#endif
main.c
Show inline comments
 
@@ -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);
states.h
Show inline comments
 
@@ -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,
 
};
 

	
 
#endif
0 comments (0 inline, 0 general)