# HG changeset patch # User Ethan Zonca # Date 2014-08-23 23:36:42 # Node ID 7e85f405b6d0814c13d3a574284616b8b5d57709 # Parent e0a38751daed7d3f4e921b31672d45f872c00383 PID setting now more user friendly diff --git a/main.c b/main.c --- a/main.c +++ b/main.c @@ -15,10 +15,10 @@ // TODO: Grab buttonpresses with interrupts #define SW_BTN GPIOB, GPIO_Pin_3 -#define SW_UP GPIOB, GPIO_Pin_7 +#define SW_UP GPIOB, GPIO_Pin_4 #define SW_DOWN GPIOB, GPIO_Pin_6 #define SW_LEFT GPIOB, GPIO_Pin_5 -#define SW_RIGHT GPIOB, GPIO_Pin_4 +#define SW_RIGHT GPIOB, GPIO_Pin_7 // USB Supporting Vars extern __IO uint8_t Receive_Buffer[64]; @@ -213,9 +213,9 @@ void update_temp() { int32_t setpoint = 0; -int32_t p = 1; -int32_t i = 1; -int32_t d = 1; +uint16_t k_p = 1; +uint16_t k_i = 1; +uint16_t k_d = 1; // Process things @@ -248,6 +248,7 @@ enum state { uint8_t state = STATE_IDLE; +uint8_t goto_mode = 2; // State machine void machine() @@ -263,17 +264,54 @@ void machine() // [ therm :: idle ] ssd1306_DrawString("therm :: idle ", 0, 40); - ssd1306_drawlogo(); - char tempstr[9]; + char tempstr[5]; itoa_fp(temp, temp_frac, tempstr); - ssd1306_DrawString("Temp: ", 2, 40); - ssd1306_DrawString(" ", 2, 70); - ssd1306_DrawString(tempstr, 2, 72); + ssd1306_DrawString("Temp: ", 3, 40); + ssd1306_DrawString(" ", 3, 70); + ssd1306_DrawString(tempstr, 3, 72); + + ssd1306_drawlogo(); + + switch(goto_mode) { + case 2: + { + ssd1306_DrawString("-> brew ", 1, 40); + } break; + + case 1: + { + ssd1306_DrawString("-> set P/I/D", 1, 40); + } break; + + case 0: + { + ssd1306_DrawString("-> setup ", 1, 40); + } break; + } // Button handler if(!GPIO_ReadInputDataBit(SW_BTN)) { - state = STATE_SETP; + switch(goto_mode) { + case 2: + state = STATE_PREHEAT_BREW; + break; + case 1: + state = STATE_SETP; + break; + case 0: + state = STATE_SETP; + break; + default: + state = STATE_PREHEAT_BREW; + } } + else if(!GPIO_ReadInputDataBit(SW_UP) && goto_mode < 2) { + goto_mode++; + } + else if(!GPIO_ReadInputDataBit(SW_DOWN) && k_p > 0 && goto_mode > 0) { + goto_mode--; + } + // Event Handler // N/A @@ -285,12 +323,26 @@ void machine() // Write text to OLED // [ therm :: set p ] // [ p = 12 ] - ssd1306_DrawString("therm :: set p", 0, 40); + ssd1306_DrawString("Proportional", 0, 40); + char tempstr[6]; + itoa(k_p, tempstr); + ssd1306_DrawString("P=", 1, 45); + ssd1306_DrawString(" ", 1, 57); + ssd1306_DrawString(tempstr, 1, 57); + + ssd1306_DrawString("Press to accept", 3, 40); + // Button handler if(!GPIO_ReadInputDataBit(SW_BTN)) { state = STATE_SETI; } + else if(!GPIO_ReadInputDataBit(SW_UP)) { + k_p++; + } + else if(!GPIO_ReadInputDataBit(SW_DOWN) && k_p > 0) { + k_p--; + } // Event Handler // N/A @@ -302,12 +354,27 @@ void machine() // Write text to OLED // [ therm :: set i ] // [ i = 12 ] - ssd1306_DrawString("therm :: set i", 0, 40); + ssd1306_DrawString("Integral", 0, 40); + char tempstr[6]; + itoa(k_i, tempstr); + ssd1306_DrawString("I=", 1, 45); + ssd1306_DrawString(" ", 1, 57); + ssd1306_DrawString(tempstr, 1, 57); + + ssd1306_DrawString("Press to accept", 3, 40); + // Button handler if(!GPIO_ReadInputDataBit(SW_BTN)) { state = STATE_SETD; } + else if(!GPIO_ReadInputDataBit(SW_UP)) { + k_i++; + } + else if(!GPIO_ReadInputDataBit(SW_DOWN) && k_i > 0) { + k_i--; + } + // Event Handler // N/A @@ -319,12 +386,26 @@ void machine() // Write text to OLED // [ therm :: set d ] // [ d = 12 ] - ssd1306_DrawString("therm :: set d", 0, 40); + ssd1306_DrawString("Derivative", 0, 40); + + char tempstr[6]; + itoa(k_d, tempstr); + ssd1306_DrawString("D=", 1, 45); + ssd1306_DrawString(" ", 1, 57); + ssd1306_DrawString(tempstr, 1, 57); + + ssd1306_DrawString("Press to accept", 3, 40); // Button handler if(!GPIO_ReadInputDataBit(SW_BTN)) { state = STATE_IDLE; } + else if(!GPIO_ReadInputDataBit(SW_UP)) { + k_d++; + } + else if(!GPIO_ReadInputDataBit(SW_DOWN) && k_d > 0) { + k_d--; + } // Event Handler // N/A @@ -336,7 +417,7 @@ void machine() // Write text to OLED // [ therm : preheating brew ] // [ 30 => 120 C ] - ssd1306_DrawString("therm :: Bpreheat", 0, 40); + ssd1306_DrawString("Preheating...", 0, 40); // Button handler if(!GPIO_ReadInputDataBit(SW_BTN)) { @@ -355,7 +436,7 @@ void machine() // Write text to OLED // [ therm : ready to brew ] // [ 30 => 120 C ] - ssd1306_DrawString("therm :: Bready", 0, 40); + ssd1306_DrawString("Ready to Brew!", 0, 40); // Button handler @@ -373,7 +454,7 @@ void machine() // Write text to OLED // [ therm : preheating steam ] // [ 30 => 120 C ] - ssd1306_DrawString("therm :: Spreheat", 0, 40); + ssd1306_DrawString("Preheating...", 0, 40); // Button handler if(!GPIO_ReadInputDataBit(SW_BTN)) { @@ -392,7 +473,7 @@ void machine() // Write text to OLED // [ therm : ready to steam ] // [ 30 => 120 C ] - ssd1306_DrawString("therm :: Sready", 0, 40); + ssd1306_DrawString("Ready to Steam!", 0, 40); // Button handler if(!GPIO_ReadInputDataBit(SW_BTN)) {