Simple radar simulator. Example of 2D graphics on DISCO-F746NG display.

Dependencies:   BSP_DISCO_F746NG Graphics mbed TS_DISCO_F746NG

Revision:
4:66f13188c26b
Parent:
3:732f7144ec81
--- a/RadarDemo/RadarDemo.cpp	Sat Nov 05 15:36:59 2016 +0000
+++ b/RadarDemo/RadarDemo.cpp	Sat Nov 05 20:24:59 2016 +0000
@@ -8,14 +8,20 @@
 // Size of range control areas on the screen
 const int raSize = 50;
 
+// Button Press Timeout in miliseconds
+const uint32_t buttonPressTimeout = 400;
+
+
 RadarDemo::RadarDemo(Display* display) : Radar(display)
 {
+    _ts = new TouchScreen(display);
 }
 
 
 RadarDemo::~RadarDemo()
 {
     Radar::~Radar();
+    free(_ts);
 }
 
 
@@ -41,11 +47,13 @@
 
     // Force background redraw
     UnvalidateBackground();
+    
+    _buttonPressTime = 0;
 
     // Initialize touchscreen
-    ts.Init(((RK043FN48H*)GetDisplay())->DisplayWidth(), ((RK043FN48H*)GetDisplay())->DisplayHeight());
-
-    timer.Start();
+    _ts->Init();
+   
+    timer.Start();   
 }
 
 
@@ -57,11 +65,7 @@
     lastBeamAngle = currentBeamAngle;
     currentBeamAngle = timer.GetBeamAngle();
 
-    // TODO: 
-    if(DetectTouch(window))
-    {
-        // Set timeout for the next touch detection
-    }
+    CheckUserInput(window); 
 
     RK043FN48H* display = (RK043FN48H*)GetDisplay();
     if(NeedsRedraw()) {
@@ -136,32 +140,49 @@
 }
 
 
-bool RadarDemo::DetectTouch(Window screen)
+UserInputType RadarDemo::CheckUserInput(Window screen)
 {
-    TS_StateTypeDef tsState;
-
-    ts.GetState(&tsState);
+    pPoint p;
+    
+    // There is a timeout after pressing the button
+    if(TouchScreenDisabled())
+        return None;
+        
+    if ((p = _ts->DetectTouch()) != NULL) {
 
-    if (tsState.touchDetected > 0) {
-
-        if(tsState.touchX[0] > (screen.x2-raSize) && tsState.touchY[0] < screen.y1 + raSize) {
-            if(ChangeRange(1))
+        if(p->X > (screen.x2-raSize) && p->Y < (screen.y1 + raSize)) {
+            if(ChangeRange(1)) {
                 UnvalidateBackground();
+                SetTouchScreenTimeout();
+                
+                return ButtonPressed;
+            }
         }
 
-        else if(tsState.touchX[0] > (screen.x2-raSize) && tsState.touchY[0] > (screen.y2-raSize)) {
-            if(ChangeRange(-1))
+        if(p->X > (screen.x2-raSize) && p->Y > (screen.y2-raSize)) {
+            if(ChangeRange(-1)) {
                 UnvalidateBackground();
+                SetTouchScreenTimeout();
+                
+                return ButtonPressed;
+            }
         }
 
-        else {
-            SetCenter(tsState.touchX[0], tsState.touchY[0]);
-            UnvalidateBackground();
-        }
+        SetCenter(p->X, p->Y);
+        UnvalidateBackground();
         
-        ts.ResetTouchData(&tsState);
-        return true;
+        return SingleTouch;
     }
 
-    return false;
+    return None;
 }
+
+bool RadarDemo::TouchScreenDisabled()
+{
+    return _buttonPressTime + buttonPressTimeout > timer.GetRunningTime();
+}
+
+void RadarDemo::SetTouchScreenTimeout()
+{
+    _buttonPressTime = timer.GetRunningTime();
+}