@@ -15,10 +15,10 @@
// 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];
@@ -213,9 +213,9 @@ void update_temp() {
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
@@ -248,6 +248,7 @@ enum state {
uint8_t state = STATE_IDLE;
uint8_t goto_mode = 2;
// State machine
void machine()
@@ -263,17 +264,54 @@ void machine()
// [ 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_PREHEAT_BREW;
break;
state = STATE_SETP;
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
@@ -285,12 +323,26 @@ void machine()
// Write text to OLED
// [ 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--;
@@ -302,12 +354,27 @@ void machine()
// [ 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--;
@@ -319,12 +386,26 @@ void machine()
// [ 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--;
@@ -336,7 +417,7 @@ void machine()
// [ therm : preheating brew ]
// [ 30 => 120 C ]
ssd1306_DrawString("therm :: Bpreheat", 0, 40);
ssd1306_DrawString("Preheating...", 0, 40);
@@ -355,7 +436,7 @@ void machine()
// [ therm : ready to brew ]
ssd1306_DrawString("therm :: Bready", 0, 40);
ssd1306_DrawString("Ready to Brew!", 0, 40);
@@ -373,7 +454,7 @@ void machine()
// [ therm : preheating steam ]
ssd1306_DrawString("therm :: Spreheat", 0, 40);
@@ -392,7 +473,7 @@ void machine()
// [ therm : ready to steam ]
ssd1306_DrawString("therm :: Sready", 0, 40);
ssd1306_DrawString("Ready to Steam!", 0, 40);
Status change: