@@ -67,26 +67,37 @@ int main(void)
GPIO_ResetBits(LED_POWER);
init_spi();
ssd1306_Init();
ssd1306_block_write();
ssd1306_DrawString("therm 0.1", 0, 40);
ssd1306_DrawString("Status: Idle", 2, 40);
// ssd1306_block_write();
ssd1306_test();
uint8_t toggle = 0;
int16_t temp = 0;
while(1)
{
temp = SPI_I2S_ReceiveData(SPI2);
ssd1306_DrawString("Temp: ", 1, 40);
char tempstr[5];
char test = temp + 0x30;
//sprintf(tempstr, "%d", test);
//ssd1306_DrawString(tempstr, 1, 70);
//ssd1306_block_write();
// Process sensor inputs [TODO: 5hz?]
process();
// Run state machine [TODO: 50hz?]
machine();
// probably just passed the actual port
// TODO: Grab buttonpresses with interrupts
uint8_t sw_btn = GPIO_ReadInputDataBit(SW_BTN);
uint8_t sw_up = GPIO_ReadInputDataBit(SW_UP);
@@ -169,156 +180,165 @@ uint8_t state = STATE_IDLE;
// State machine
void machine()
switch(state)
// Idle state
case STATE_IDLE:
// Write text to OLED
// [ therm :: idle ]
ssd1306_DrawString("therm :: idle ", 0, 40);
// Button handler
if(GPIO_ReadInputDataBit(SW_BTN)) {
if(!GPIO_ReadInputDataBit(SW_BTN)) {
state = STATE_SETP;
}
// Event Handler
// N/A
} break;
case STATE_SETP:
// [ therm :: set p ]
// [ p = 12 ]
ssd1306_DrawString("therm :: set p", 0, 40);
state = STATE_IDLE;
state = STATE_SETI;
case STATE_SETI:
// [ therm :: set i ]
// [ i = 12 ]
ssd1306_DrawString("therm :: set i", 0, 40);
state = STATE_SETD;
case STATE_SETD:
// [ therm :: set d ]
// [ d = 12 ]
ssd1306_DrawString("therm :: set d", 0, 40);
case STATE_PREHEAT_BREW:
// [ therm : preheating brew ]
// [ 30 => 120 C ]
ssd1306_DrawString("therm :: Bpreheat", 0, 40);
if(temp >= setpoint) {
state = STATE_MAINTAIN_BREW;
case STATE_MAINTAIN_BREW:
// [ therm : ready to brew ]
ssd1306_DrawString("therm :: Bready", 0, 40);
case STATE_PREHEAT_STEAM:
// [ therm : preheating steam ]
ssd1306_DrawString("therm :: Spreheat", 0, 40);
state = STATE_MAINTAIN_STEAM;
case STATE_MAINTAIN_STEAM:
// [ therm : ready to steam ]
ssd1306_DrawString("therm :: Sready", 0, 40);
// Something is terribly wrong
default:
ssd1306_DrawString("therm :: BAD BAD", 0, 40);
/**
* @brief Inserts a delay time.
* @param nTime: specifies the delay time length, in 1 ms.
* @retval None
Status change: