diff --git a/main.c b/main.c --- a/main.c +++ b/main.c @@ -18,6 +18,8 @@ static __IO uint32_t TimingDelay; void init_gpio(); void init_spi(); +void process(); +void machine(); int main(void) { @@ -50,6 +52,13 @@ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SP while(1) { + // Process sensor inputs [TODO: 5hz?] + process(); + + // Run state machine [TODO: 50hz?] + machine(); // this argument is sooo wrong + // 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); @@ -71,6 +80,193 @@ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SP } } + + +int32_t temp = 0; +int32_t setpoint = 0; +int32_t p = 1; +int32_t i = 1; +int32_t d = 1; + +// Process things +void process() +{ + // Read MAX temp sensor + temp = 0; + + // Perform PID calculations + + // Write output to SSR +} + + + +enum state { + STATE_IDLE = 0, + STATE_SETP, + STATE_SETI, + STATE_SETD, + + STATE_PREHEAT_BREW, + STATE_MAINTAIN_BREW, + STATE_PREHEAT_STEAM, + STATE_MAINTAIN_STEAM, +}; + + +uint8_t state = STATE_IDLE; + +// State machine +void machine() +{ + + switch(state) + { + // Idle state + case STATE_IDLE: + { + // Write text to OLED + // [ therm :: idle ] + + // Button handler + if(GPIO_ReadInputDataBit(SW_BTN)) { + state = STATE_SETP; + } + + // Event Handler + // N/A + + } break; + + case STATE_SETP: + { + // Write text to OLED + // [ therm :: set p ] + // [ p = 12 ] + + // Button handler + if(GPIO_ReadInputDataBit(SW_BTN)) { + state = STATE_IDLE; + } + + // Event Handler + // N/A + + } break; + + case STATE_SETI: + { + // Write text to OLED + // [ therm :: set i ] + // [ i = 12 ] + + // Button handler + if(GPIO_ReadInputDataBit(SW_BTN)) { + state = STATE_IDLE; + } + + // Event Handler + // N/A + + } break; + + case STATE_SETD: + { + // Write text to OLED + // [ therm :: set d ] + // [ d = 12 ] + + // Button handler + if(GPIO_ReadInputDataBit(SW_BTN)) { + state = STATE_IDLE; + } + + // Event Handler + // N/A + + } break; + + case STATE_PREHEAT_BREW: + { + // Write text to OLED + // [ therm : preheating brew ] + // [ 30 => 120 C ] + + // Button handler + if(GPIO_ReadInputDataBit(SW_BTN)) { + state = STATE_IDLE; + } + + // Event Handler + if(temp >= setpoint) { + state = STATE_MAINTAIN_BREW; + } + + } break; + + case STATE_MAINTAIN_BREW: + { + // Write text to OLED + // [ therm : ready to brew ] + // [ 30 => 120 C ] + + + // Button handler + if(GPIO_ReadInputDataBit(SW_BTN)) { + state = STATE_IDLE; + } + + // Event Handler + // N/A + + } break; + + case STATE_PREHEAT_STEAM: + { + // Write text to OLED + // [ therm : preheating steam ] + // [ 30 => 120 C ] + + // Button handler + if(GPIO_ReadInputDataBit(SW_BTN)) { + state = STATE_IDLE; + } + + // Event Handler + if(temp >= setpoint) { + state = STATE_MAINTAIN_STEAM; + } + + } break; + + case STATE_MAINTAIN_STEAM: + { + // Write text to OLED + // [ therm : ready to steam ] + // [ 30 => 120 C ] + + // Button handler + if(GPIO_ReadInputDataBit(SW_BTN)) { + state = STATE_IDLE; + } + + // Event Handler + // N/A + + } break; + + + // Something is terribly wrong + deault: + { + state = STATE_IDLE; + + } break; + + } +} + + /** * @brief Inserts a delay time. * @param nTime: specifies the delay time length, in 1 ms.