diff --git a/main.c b/main.c --- a/main.c +++ b/main.c @@ -43,6 +43,7 @@ void init_gpio(); void init_spi(); void process(); void machine(); +void delay(__IO uint32_t nTime); int main(void) { @@ -79,7 +80,7 @@ int main(void) // Startup screen ssd1306_DrawString("therm v0.1", 1, 40); ssd1306_DrawString("protofusion.org/therm", 3, 0); - Delay(1500); + delay(1500); ssd1306_block_write(); // Main loop @@ -101,7 +102,7 @@ uint8_t temp_frac = 0; void update_temp() { // Assert CS GPIO_ResetBits(MAX_CS); - Delay(1); + delay(1); // This may not clock at all... might need to send 16 bits first SPI_I2S_SendData(SPI2, 0xAAAA); // send dummy data @@ -134,7 +135,7 @@ void update_temp() { } // Deassert CS - Delay(1); + delay(1); GPIO_SetBits(MAX_CS); } @@ -160,15 +161,15 @@ void process() last_led = ticks; } - // Every 200ms, set the SSR on - if(ticks - last_ssr_on > SSR_PERIOD) + // Every 200ms, set the SSR on unless output is 0 + if((ticks - last_ssr_on > SSR_PERIOD) && ssr_output > 0) { GPIO_SetBits(LED_STAT); last_ssr_on = ticks; } // Kill SSR after elapsed period less than SSR_PERIOD - if(ticks - last_ssr_on > ssr_output || !ssr_output) + if(ticks - last_ssr_on > ssr_output) { GPIO_ResetBits(LED_STAT); } @@ -184,9 +185,6 @@ void draw_setpoint() { ssd1306_DrawString(" ", 3, 95); ssd1306_DrawString(tempstr, 3, 95); } - - - uint8_t state = STATE_IDLE; uint8_t goto_mode = 2; @@ -365,6 +363,13 @@ void machine() if(!GPIO_ReadInputDataBit(SW_BTN)) { state = STATE_IDLE; } + else if(!GPIO_ReadInputDataBit(SW_UP)) { + setpoint++; + } + else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint > 0) { + setpoint--; + } + // Event Handler if(temp >= setpoint) { @@ -385,6 +390,13 @@ void machine() if(!GPIO_ReadInputDataBit(SW_BTN)) { state = STATE_IDLE; } + else if(!GPIO_ReadInputDataBit(SW_UP)) { + setpoint++; + } + else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint > 0) { + setpoint--; + } + // Event Handler // N/A @@ -403,6 +415,13 @@ void machine() if(!GPIO_ReadInputDataBit(SW_BTN)) { state = STATE_IDLE; } + else if(!GPIO_ReadInputDataBit(SW_UP)) { + setpoint++; + } + else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint > 0) { + setpoint--; + } + // Event Handler if(temp >= setpoint) { @@ -423,6 +442,13 @@ void machine() if(!GPIO_ReadInputDataBit(SW_BTN)) { state = STATE_IDLE; } + else if(!GPIO_ReadInputDataBit(SW_UP)) { + setpoint++; + } + else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint > 0) { + setpoint--; + } + // Event Handler // N/A @@ -445,23 +471,14 @@ void machine() } -/** - * @brief Inserts a delay time. - * @param nTime: specifies the delay time length, in 1 ms. - * @retval None - */ -void Delay(__IO uint32_t nTime) +// Delay a number of systicks +void delay(__IO uint32_t nTime) { TimingDelay = nTime; while(TimingDelay != 0); } - -/** - * @brief Decrements the TimingDelay variable. - * @param None - * @retval None - */ +// ISR-triggered decrement of delay and increment of tickcounter void TimingDelay_Decrement(void) { if (TimingDelay != 0x00)