@@ -15,12 +15,14 @@
static __IO uint32_t TimingDelay;
void init_gpio();
void init_spi();
void process();
void machine();
int main(void)
{
// Init clocks
SystemInit();
@@ -47,12 +49,19 @@ int main(void)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
init_spi();
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);
uint8_t sw_down = GPIO_ReadInputDataBit(SW_DOWN);
uint8_t sw_left = GPIO_ReadInputDataBit(SW_LEFT);
uint8_t sw_right = GPIO_ReadInputDataBit(SW_RIGHT);
@@ -68,12 +77,199 @@ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SP
Delay(150);
GPIO_ResetBits(LED_POWER);
}
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:
// [ therm :: set p ]
// [ p = 12 ]
state = STATE_IDLE;
case STATE_SETI:
// [ therm :: set i ]
// [ i = 12 ]
case STATE_SETD:
// [ therm :: set d ]
// [ d = 12 ]
case STATE_PREHEAT_BREW:
// [ therm : preheating brew ]
// [ 30 => 120 C ]
if(temp >= setpoint) {
state = STATE_MAINTAIN_BREW;
case STATE_MAINTAIN_BREW:
// [ therm : ready to brew ]
case STATE_PREHEAT_STEAM:
// [ therm : preheating steam ]
state = STATE_MAINTAIN_STEAM;
case STATE_MAINTAIN_STEAM:
// [ therm : ready to steam ]
// Something is terribly wrong
deault:
/**
* @brief Inserts a delay time.
* @param nTime: specifies the delay time length, in 1 ms.
* @retval None
*/
void Delay(__IO uint32_t nTime)
Status change: