Touchscreen voltage meter (WIP)

Dependencies:   LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI VoltageMeter_stm32f429disco

Dependents:   VoltageMeter_stm32f429disco

Files at this revision

API Documentation at this revision

Comitter:
dongero
Date:
Mon Feb 24 20:44:58 2020 +0000
Parent:
0:199627fa5461
Commit message:
Refactored structure to use multiple files (display, adc, ts); Initializes and displays splash screen and start button.

Changed in this revision

VoltageMeter_stm32f429disco.lib Show annotated file Show diff for this revision Revisions of this file
adc.cpp Show annotated file Show diff for this revision Revisions of this file
adc.h Show annotated file Show diff for this revision Revisions of this file
display.cpp Show annotated file Show diff for this revision Revisions of this file
display.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
temp_notes.cpp Show annotated file Show diff for this revision Revisions of this file
ts.cpp Show annotated file Show diff for this revision Revisions of this file
ts.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VoltageMeter_stm32f429disco.lib	Mon Feb 24 20:44:58 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/danngreen/code/VoltageMeter_stm32f429disco/#199627fa5461
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/adc.cpp	Mon Feb 24 20:44:58 2020 +0000
@@ -0,0 +1,17 @@
+#include "mbed.h"
+
+AnalogIn adc12V(PA_2);
+AnalogIn adc5V(PA_4);
+AnalogIn adcN12V(PA_6);
+
+//            float adc12V_involts = adc12V.read() * 24.0f;
+//            sprintf((char*)text, "+12V = %.2f", adc12V_involts);
+//            lcd.DisplayStringAt(0, LINE(8), (uint8_t *)&text, LEFT_MODE);
+//            
+//            float adcN12V_involts = adcN12V.read() * 24.0f;
+//            sprintf((char*)text, "-12V = %.2f", adcN12V_involts);
+//            lcd.DisplayStringAt(0, LINE(9), (uint8_t *)&text, LEFT_MODE);
+//            
+//            float adc5V_involts = adc5V.read() * 10.0f;
+//            sprintf((char*)text, "+5V = %.2f", adc5V_involts);
+//            lcd.DisplayStringAt(0, LINE(10), (uint8_t *)&text, LEFT_MODE);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/display.cpp	Mon Feb 24 20:44:58 2020 +0000
@@ -0,0 +1,50 @@
+#include "LCD_DISCO_F429ZI.h"
+
+static LCD_DISCO_F429ZI lcd;
+
+struct Rect {
+    uint32_t x;
+    uint32_t y;
+    uint32_t height;
+    uint32_t width;    
+};
+
+void display_failed_ts_init() {
+    BSP_LCD_SetFont(&Font20);
+    
+    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);
+}
+
+void display_splash_screen() {
+    BSP_LCD_SetFont(&Font20);
+  
+    lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"POWER", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"TIME", CENTER_MODE);
+}
+
+void display_debug_info(char *debug_text) {
+    BSP_LCD_SetFont(&Font20);
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    lcd.DisplayStringAt(0, LINE(0), (uint8_t *)debug_text, CENTER_MODE);
+}
+
+void display_main_screen() {
+    lcd.Clear(LCD_COLOR_WHITE);
+    
+    lcd.SetTextColor(LCD_COLOR_BLUE);
+    lcd.FillRect(79, 82, 100, 100); //(x, y, height, width)
+    
+    lcd.SetBackColor(LCD_COLOR_BLUE);
+    lcd.SetTextColor(LCD_COLOR_WHITE);
+    BSP_LCD_SetFont(&Font24);
+    lcd.DisplayStringAt(10, LINE(5), (uint8_t *)"START", CENTER_MODE);
+}
+
+void display_get_size(uint32_t &x, uint32_t &y) {
+    x = lcd.GetXSize();
+    y = lcd.GetYSize();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/display.h	Mon Feb 24 20:44:58 2020 +0000
@@ -0,0 +1,6 @@
+void display_failed_ts_init();
+void display_splash_screen();
+void display_main_screen();
+void display_get_size(uint32_t &x, uint32_t &y);
+
+void display_debug_info(char *debug_text);
--- a/main.cpp	Thu Feb 13 18:12:42 2020 +0000
+++ b/main.cpp	Mon Feb 24 20:44:58 2020 +0000
@@ -1,93 +1,31 @@
 #include "mbed.h"
-#include "TS_DISCO_F429ZI.h"
-#include "LCD_DISCO_F429ZI.h"
+#include "ts.h"
+#include "display.h"
+#include "adc.h"
 
-LCD_DISCO_F429ZI lcd;
-TS_DISCO_F429ZI ts;
-struct Rect {
-    uint32_t x;
-    uint32_t y;
-    uint32_t height;
-    uint32_t width;    
-};
+void initialize_app(void)
+{
+    display_splash_screen();
+    wait(2);
+    
+    uint32_t display_size_x, display_size_y;
+    display_get_size(display_size_x, display_size_y);
+    
+    bool success = ts_init(display_size_x, display_size_y);
 
-AnalogIn adc12V(PA_2);
-AnalogIn adc5V(PA_4);
-AnalogIn adcN12V(PA_6);
+    if (!success) {
+        display_failed_ts_init();   
+        while(true) {;}
+    }
+}
 
 
 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);
-
+    initialize_app();
+    display_main_screen();
     
-//    lcd.SetTextColor(LCD_COLOR_BLACK);
-//    lcd.FillRect(30, 25, 180, 45);
-//    lcd.SetBackColor(LCD_COLOR_BLACK);
-//    lcd.SetTextColor(LCD_COLOR_WHITE);
-//    lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"Row Power 25", CENTER_MODE);
-//
-//
-//    lcd.SetTextColor(LCD_COLOR_BLACK);
-//    lcd.FillRect(30, 105, 180, 45);
-//    lcd.SetBackColor(LCD_COLOR_BLACK);
-//    lcd.SetTextColor(LCD_COLOR_WHITE);
-//    lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"Row Power 45", CENTER_MODE);
-
-    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);
-      }
-      float adc12V_involts = adc12V.read() * 24.0f;
-      sprintf((char*)text, "+12V = %.2f", adc12V_involts);
-      lcd.DisplayStringAt(0, LINE(8), (uint8_t *)&text, LEFT_MODE);
-      
-      float adcN12V_involts = adcN12V.read() * 24.0f;
-      sprintf((char*)text, "-12V = %.2f", adcN12V_involts);
-      lcd.DisplayStringAt(0, LINE(9), (uint8_t *)&text, LEFT_MODE);
-      
-      float adc5V_involts = adc5V.read() * 10.0f;
-      sprintf((char*)text, "+5V = %.2f", adc5V_involts);
-      lcd.DisplayStringAt(0, LINE(10), (uint8_t *)&text, LEFT_MODE);
-      
-      
+    while (1) {
+        
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/temp_notes.cpp	Mon Feb 24 20:44:58 2020 +0000
@@ -0,0 +1,45 @@
+ 
+//    BSP_LCD_SetFont(&Font20);
+//  
+//    lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"POWER", CENTER_MODE);
+//    lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"TIME", 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_WHITE);
+//      
+//      lcd.SetTextColor(LCD_COLOR_BLUE);
+//      lcd.FillRect(79, 82, 100, 100); //(x, y, height, width)
+//
+//      lcd.SetBackColor(LCD_COLOR_BLUE);
+//      lcd.SetTextColor(LCD_COLOR_WHITE);
+//      BSP_LCD_SetFont(&Font24);
+//      lcd.DisplayStringAt(10, LINE(5), (uint8_t *)"START", CENTER_MODE);
+//    }
+//    
+//    while(1)
+//    {
+//        //    uint8_t text[30];
+////
+//////        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);
+////
+//////            wait(0.1);
+////        }
+//    }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ts.cpp	Mon Feb 24 20:44:58 2020 +0000
@@ -0,0 +1,11 @@
+#include "TS_DISCO_F429ZI.h"
+
+static TS_DISCO_F429ZI ts;
+
+//    TS_StateTypeDef TS_State;
+
+bool ts_init(uint32_t x, uint32_t y) {
+    uint8_t status = ts.Init(x, y);
+    bool did_ts_init_ok = (status == TS_OK);
+    return did_ts_init_ok;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ts.h	Mon Feb 24 20:44:58 2020 +0000
@@ -0,0 +1,2 @@
+
+bool ts_init(uint32_t x, uint32_t y);