Andreas Haas / Mbed 2 deprecated VIVIDBreathFirstversionGUIStuff

Dependencies:   LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI

Files at this revision

API Documentation at this revision

Comitter:
Clancy_SENDSOR
Date:
Tue Jun 09 22:28:46 2020 +0000
Parent:
0:e7b2dc7d7a7f
Child:
2:5828e6917e75
Commit message:
version with first buttons

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mainbackup.txt Show annotated file Show diff for this revision Revisions of this file
--- 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);
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mainbackup.txt	Tue Jun 09 22:28:46 2020 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+#include "TS_DISCO_F429ZI.h"
+#include "LCD_DISCO_F429ZI.h"
+
+LCD_DISCO_F429ZI lcd;
+TS_DISCO_F429ZI ts;
+
+int main()
+{
+    TS_StateTypeDef TS_State;
+    uint16_t x, y;
+    uint8_t text[30];
+    uint8_t status;
+  
+    BSP_LCD_SetFont(&Font20);
+  
+    lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"DEMO", CENTER_MODE);
+    wait(1);
+  
+    status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
+  
+    if (status != TS_OK)
+    {
+      lcd.Clear(LCD_COLOR_RED);
+      lcd.SetBackColor(LCD_COLOR_RED);
+      lcd.SetTextColor(LCD_COLOR_WHITE);
+      lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE);
+      lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT FAIL", CENTER_MODE);
+    }
+    else
+    {
+      lcd.Clear(LCD_COLOR_GREEN);
+      lcd.SetBackColor(LCD_COLOR_GREEN);
+      lcd.SetTextColor(LCD_COLOR_WHITE);
+      lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE);
+      lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT OK", CENTER_MODE);
+    }
+    
+    wait(1);
+    lcd.Clear(LCD_COLOR_BLUE);
+    lcd.SetBackColor(LCD_COLOR_BLUE);
+    lcd.SetTextColor(LCD_COLOR_WHITE);
+    
+    while(1)
+    {
+      
+      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);
+      }
+    }
+}