Changeset - 3d43c0d055a8
[Not reviewed]
default
0 1 0
Ethan Zonca - 10 years ago 2014-08-19 22:00:18
ez@ethanzonca.com
Add some more text and stuff
1 file changed with 31 insertions and 11 deletions:
main.c
31
11
0 comments (0 inline, 0 general)
main.c
Show inline comments
 
@@ -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:
 
        {
 
            // Write text to OLED
 
            // [ therm :: set p ]
 
            // [ p = 12         ]
 
            ssd1306_DrawString("therm :: set p", 0, 40);
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_IDLE;
 
            if(!GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_SETI;
 
            }
 
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 
 
        case STATE_SETI:
 
        {
 
            // Write text to OLED
 
            // [ therm :: set i ]
 
            // [ i = 12         ]
 
            ssd1306_DrawString("therm :: set i", 0, 40);
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_IDLE;
 
            if(!GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_SETD;
 
            }
 
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 
 
        case STATE_SETD:
 
        {
 
            // Write text to OLED
 
            // [ therm :: set d ]
 
            // [ d = 12         ]
 
            ssd1306_DrawString("therm :: set d", 0, 40);
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
            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             ]
 
            ssd1306_DrawString("therm :: Bpreheat", 0, 40);
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
            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           ]
 
            ssd1306_DrawString("therm :: Bready", 0, 40);
 
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
            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           ]
 
            ssd1306_DrawString("therm :: Spreheat", 0, 40);
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
            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            ]
 
            ssd1306_DrawString("therm :: Sready", 0, 40);
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
            if(!GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_IDLE;
 
            }
 
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 
 
 
        // Something is terribly wrong
 
        default:
 
        {
 
            ssd1306_DrawString("therm :: BAD BAD", 0, 40);
 
            state = STATE_IDLE;
 
 
        } break;
 
            
 
    }
 
}
 
 
 
/**
 
  * @brief  Inserts a delay time.
 
  * @param  nTime: specifies the delay time length, in 1 ms.
 
  * @retval None
0 comments (0 inline, 0 general)