Optimaze with new mbed os for study

Dependencies:   TS_DISCO_F746NG BSP_DISCO_F746NG Graphics

Revision:
2:8db224cc1fcb
Parent:
1:5e49b46de1b0
Child:
3:732f7144ec81
--- a/RadarDemo/RadarDemo.cpp	Fri Nov 04 17:10:50 2016 +0000
+++ b/RadarDemo/RadarDemo.cpp	Fri Nov 04 23:07:04 2016 +0000
@@ -5,6 +5,9 @@
 #include "RadarDemo.h"
 #include "RK043FN48H.h"
 
+// Size of range control areas on the screen
+const int raSize = 50;
+
 RadarDemo::RadarDemo(Display* display) : Radar(display)
 {
 }
@@ -29,13 +32,11 @@
     demoTime = 0;
 
     // Put a number of sample targets on the display
-    AddSampleTargets(100);
+    AddSampleTargets(30);
 
     // Use medium range, values 0..2 are available now
     SetRange(1);
 
-    //SetCenter(0, 0);
-
     // Remark : Data member initializer is not allowed for ARM compiler,
     //          initialize data in class constructor.
     runningTime = 0;
@@ -46,6 +47,9 @@
     // Force background redraw
     UnvalidateBackground();
 
+    // Initialize touchscreen
+    ts.Init(((RK043FN48H*)GetDisplay())->DisplayWidth(), ((RK043FN48H*)GetDisplay())->DisplayHeight());
+
 #ifndef _SDL_timer_h
     t.start();
 #endif
@@ -74,12 +78,20 @@
 
     RK043FN48H* display = (RK043FN48H*)GetDisplay();
 
+    if(DetectTouch(window))
+    {
+        // Set timeout for the next touch detection
+    }
+
     if(NeedsRedraw()) {
 
         display->SetActiveLayer(Background);
         display->Clear();
 
-        // Set color for markers
+        // Set draw color before calling draw method
+        display->SetDrawColor(0x80, 0, 0, 0xFF);
+        DrawRangeButtons(raSize);
+
         display->SetDrawColor(0x40, 0x40, 0x40, 0xFF);
         DrawMarkers();
 
@@ -96,9 +108,9 @@
 #else
     runningTime = t.read_ms();
 #endif
-    
+
     UpdateTargetsLocation(lastBeamAngle, currentBeamAngle, runningTime);
-    
+
     // Redraw foreground
     display->Clear();
     DrawTracks();
@@ -159,3 +171,33 @@
     return _needsRedraw;
 }
 
+
+bool RadarDemo::DetectTouch(Window screen)
+{
+    TS_StateTypeDef tsState;
+
+    ts.GetState(&tsState);
+
+    if (tsState.touchDetected) {
+
+        if(tsState.touchX[0] > (screen.x2-raSize) && tsState.touchY[0] < screen.y1 + raSize) {
+            if(ChangeRange(1))
+                UnvalidateBackground();
+        }
+
+        else if(tsState.touchX[0] > (screen.x2-raSize) && tsState.touchY[0] > (screen.y2-raSize)) {
+            if(ChangeRange(-1))
+                UnvalidateBackground();
+        }
+
+        else {
+            SetCenter(tsState.touchX[0], tsState.touchY[0]);
+            UnvalidateBackground();
+        }
+        
+        ts.ResetTouchData(&tsState);
+        return true;
+    }
+
+    return false;
+}