@@ -12,16 +12,16 @@
#define LED_STAT GPIOA,GPIO_Pin_15
#define MAX_CS GPIOB,GPIO_Pin_12
// TODO: Grab buttonpresses with interrupts
#define SW_BTN GPIOB, GPIO_Pin_3
#define SW_UP GPIOB, GPIO_Pin_7
#define SW_UP GPIOB, GPIO_Pin_4
#define SW_DOWN GPIOB, GPIO_Pin_6
#define SW_LEFT GPIOB, GPIO_Pin_5
#define SW_RIGHT GPIOB, GPIO_Pin_4
#define SW_RIGHT GPIOB, GPIO_Pin_7
// USB Supporting Vars
extern __IO uint8_t Receive_Buffer[64];
extern __IO uint32_t Receive_length ;
extern __IO uint32_t length ;
uint8_t Send_Buffer[64];
@@ -210,15 +210,15 @@ void update_temp() {
Delay(1);
GPIO_SetBits(MAX_CS);
}
int32_t setpoint = 0;
int32_t p = 1;
int32_t i = 1;
int32_t d = 1;
uint16_t k_p = 1;
uint16_t k_i = 1;
uint16_t k_d = 1;
// Process things
void process()
{
update_temp(); // Read MAX31855
@@ -245,12 +245,13 @@ enum state {
STATE_PREHEAT_STEAM,
STATE_MAINTAIN_STEAM,
};
uint8_t state = STATE_IDLE;
uint8_t goto_mode = 2;
// State machine
void machine()
uint8_t last_state = state;
@@ -260,86 +261,166 @@ void machine()
case STATE_IDLE:
// Write text to OLED
// [ therm :: idle ]
ssd1306_DrawString("therm :: idle ", 0, 40);
ssd1306_drawlogo();
char tempstr[9];
char tempstr[5];
itoa_fp(temp, temp_frac, tempstr);
ssd1306_DrawString("Temp: ", 2, 40);
ssd1306_DrawString(" ", 2, 70);
ssd1306_DrawString(tempstr, 2, 72);
ssd1306_DrawString("Temp: ", 3, 40);
ssd1306_DrawString(" ", 3, 70);
ssd1306_DrawString(tempstr, 3, 72);
switch(goto_mode) {
case 2:
ssd1306_DrawString("-> brew ", 1, 40);
} break;
case 1:
ssd1306_DrawString("-> set P/I/D", 1, 40);
case 0:
ssd1306_DrawString("-> setup ", 1, 40);
// Button handler
if(!GPIO_ReadInputDataBit(SW_BTN)) {
state = STATE_SETP;
state = STATE_PREHEAT_BREW;
break;
default:
else if(!GPIO_ReadInputDataBit(SW_UP) && goto_mode < 2) {
goto_mode++;
else if(!GPIO_ReadInputDataBit(SW_DOWN) && k_p > 0 && goto_mode > 0) {
goto_mode--;
// Event Handler
// N/A
case STATE_SETP:
// [ therm :: set p ]
// [ p = 12 ]
ssd1306_DrawString("therm :: set p", 0, 40);
ssd1306_DrawString("Proportional", 0, 40);
char tempstr[6];
itoa(k_p, tempstr);
ssd1306_DrawString("P=", 1, 45);
ssd1306_DrawString(" ", 1, 57);
ssd1306_DrawString(tempstr, 1, 57);
ssd1306_DrawString("Press to accept", 3, 40);
state = STATE_SETI;
else if(!GPIO_ReadInputDataBit(SW_UP)) {
k_p++;
else if(!GPIO_ReadInputDataBit(SW_DOWN) && k_p > 0) {
k_p--;
case STATE_SETI:
// [ therm :: set i ]
// [ i = 12 ]
ssd1306_DrawString("therm :: set i", 0, 40);
ssd1306_DrawString("Integral", 0, 40);
itoa(k_i, tempstr);
ssd1306_DrawString("I=", 1, 45);
state = STATE_SETD;
k_i++;
else if(!GPIO_ReadInputDataBit(SW_DOWN) && k_i > 0) {
k_i--;
case STATE_SETD:
// [ therm :: set d ]
// [ d = 12 ]
ssd1306_DrawString("therm :: set d", 0, 40);
ssd1306_DrawString("Derivative", 0, 40);
itoa(k_d, tempstr);
ssd1306_DrawString("D=", 1, 45);
state = STATE_IDLE;
k_d++;
else if(!GPIO_ReadInputDataBit(SW_DOWN) && k_d > 0) {
k_d--;
case STATE_PREHEAT_BREW:
// [ therm : preheating brew ]
// [ 30 => 120 C ]
ssd1306_DrawString("therm :: Bpreheat", 0, 40);
ssd1306_DrawString("Preheating...", 0, 40);
@@ -352,13 +433,13 @@ void machine()
case STATE_MAINTAIN_BREW:
// [ therm : ready to brew ]
ssd1306_DrawString("therm :: Bready", 0, 40);
ssd1306_DrawString("Ready to Brew!", 0, 40);
@@ -370,13 +451,13 @@ void machine()
case STATE_PREHEAT_STEAM:
// [ therm : preheating steam ]
ssd1306_DrawString("therm :: Spreheat", 0, 40);
@@ -389,13 +470,13 @@ void machine()
case STATE_MAINTAIN_STEAM:
// [ therm : ready to steam ]
ssd1306_DrawString("therm :: Sready", 0, 40);
ssd1306_DrawString("Ready to Steam!", 0, 40);
Status change: