![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Started a gui menuflow
Dependencies: LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI
Diff: main.cpp
- Revision:
- 1:35eb0c8fa2c0
- Parent:
- 0:e7b2dc7d7a7f
- Child:
- 2:5828e6917e75
--- a/main.cpp Tue Jun 09 14:57:20 2020 +0000 +++ b/main.cpp Tue Jun 09 22:28:46 2020 +0000 @@ -2,30 +2,127 @@ #include "TS_DISCO_F429ZI.h" #include "LCD_DISCO_F429ZI.h" -LCD_DISCO_F429ZI lcd; -TS_DISCO_F429ZI ts; +#define y_max 310 DigitalOut led1(LED1); Ticker ts_service; +AnalogIn pdiff(PC_5); +AnalogIn p_guage(PC_4); + +LCD_DISCO_F429ZI lcd; +TS_DISCO_F429ZI ts; +//PwmOut led(LED1); +PwmOut motor(PB_0); + TS_StateTypeDef TS_State; -uint16_t x, y; +TS_StateTypeDef Old_TS_State; + uint8_t text[30]; - uint8_t status; +uint8_t status; + +uint16_t x, y = 0; +uint16_t touch_x, touch_y = 0; +bool press_detected = false; + +uint16_t setPressure = 0; +uint8_t isr_text[30]; +uint8_t display_screen = 1; + +int showScreen(uint8_t screen) +{ + switch(screen) + { + case 1 : + BSP_LCD_SetFont(&Font20); + setPressure = (y*20)/y_max; + sprintf((char*)isr_text, "SetP=%2d", setPressure); + lcd.DisplayStringAt(0, LINE(1), (uint8_t *)&isr_text, CENTER_MODE); + sprintf((char*)isr_text, "PDIFF=%.2f", pdiff.read()*6.0f); + lcd.DisplayStringAt(0, LINE(2), (uint8_t *)&isr_text, CENTER_MODE); + sprintf((char*)isr_text, "PGUAGE=%.2f", p_guage.read()*38.0f); + lcd.DisplayStringAt(0, LINE(3), (uint8_t *)&isr_text, CENTER_MODE); + + BSP_LCD_SetFont(&Font12); + lcd.DrawRect(5, 100, 70, 50); + lcd.DrawRect(85, 100, 70, 50); + lcd.DrawRect(165, 100, 70, 50); + sprintf((char*)isr_text, " Start"); + lcd.DisplayStringAt(10, 130, (uint8_t *)&isr_text, LEFT_MODE); + sprintf((char*)isr_text, "Settings"); + lcd.DisplayStringAt(95, 130, (uint8_t *)&isr_text, LEFT_MODE); + sprintf((char*)isr_text, " Stop"); + lcd.DisplayStringAt(165, 130, (uint8_t *)&isr_text, LEFT_MODE); + + lcd.DrawRect(5, 160, 70, 50); + lcd.DrawRect(85, 160, 70, 50); + lcd.DrawRect(165, 160, 70, 50); + + lcd.DrawRect(5, 220, 70, 50); + lcd.DrawRect(85, 220, 70, 50); + lcd.DrawRect(165, 220, 70, 50); + break; + case 2 : + BSP_LCD_SetFont(&Font20); + setPressure = (y*20)/y_max; + sprintf((char*)isr_text, "SetPress=%2d", setPressure); + lcd.DisplayStringAt(0, LINE(1), (uint8_t *)&isr_text, CENTER_MODE); + sprintf((char*)isr_text, "PDIFF=%.2f", pdiff.read()*6.0f); + lcd.DisplayStringAt(0, LINE(2), (uint8_t *)&isr_text, CENTER_MODE); + sprintf((char*)isr_text, "PGUAGE=%.2f", p_guage.read()*38.0f); + lcd.DisplayStringAt(0, LINE(3), (uint8_t *)&isr_text, CENTER_MODE); + + BSP_LCD_SetFont(&Font12); + lcd.DrawRect(5, 100, 70, 50); + lcd.DrawRect(85, 100, 70, 50); + lcd.DrawRect(165, 100, 70, 50); + sprintf((char*)isr_text, " Start"); + lcd.DisplayStringAt(10, 130, (uint8_t *)&isr_text, LEFT_MODE); + sprintf((char*)isr_text, "Settings"); + lcd.DisplayStringAt(95, 130, (uint8_t *)&isr_text, LEFT_MODE); + sprintf((char*)isr_text, " Stop"); + lcd.DisplayStringAt(165, 130, (uint8_t *)&isr_text, LEFT_MODE); + + lcd.DrawRect(5, 160, 70, 50); + lcd.DrawRect(85, 160, 70, 50); + lcd.DrawRect(165, 160, 70, 50); + + lcd.DrawRect(5, 220, 70, 50); + lcd.DrawRect(85, 220, 70, 50); + lcd.DrawRect(165, 220, 70, 50); + } + return screen; +} + +void CheckPress() +{ + if(press_detected) + { + display_screen = 2; + } +} + void CheckTs() { ts.GetState(&TS_State); if (TS_State.TouchDetected) { - x = TS_State.X; - y = TS_State.Y; - sprintf((char*)text, "x=%d y=%d ", x, y); - lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + x = TS_State.X; + y = TS_State.Y; } + if ((Old_TS_State.TouchDetected) && (!TS_State.TouchDetected)) + { + touch_x = x; + touch_y = y; + press_detected = true; + } + Old_TS_State = TS_State; } int main() { + motor.period(0.1f); + BSP_LCD_SetFont(&Font20); lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); @@ -63,7 +160,8 @@ while(1) { led1 = !led1; - wait(0.5); - + wait(0.2); + CheckPress(); + showScreen(display_screen); } }