Optimaze with new mbed os for study

Dependencies:   TS_DISCO_F746NG BSP_DISCO_F746NG Graphics

Revision:
3:732f7144ec81
Parent:
2:8db224cc1fcb
Child:
4:66f13188c26b
--- a/RadarDemo/RadarDemo.cpp	Fri Nov 04 23:07:04 2016 +0000
+++ b/RadarDemo/RadarDemo.cpp	Sat Nov 05 15:36:59 2016 +0000
@@ -15,9 +15,6 @@
 
 RadarDemo::~RadarDemo()
 {
-#ifndef _SDL_timer_h
-    t.stop();
-#endif
     Radar::~Radar();
 }
 
@@ -25,7 +22,7 @@
 void RadarDemo::Initialize()
 {
     // Set scan perion for 6 seconds
-    scanPeriod = 6000;
+    timer.SetScanPeriod(6);
 
     // Run forever, to set limited time for the demo
     // use for example: demoTime = 10 * scanPeriod;
@@ -39,8 +36,6 @@
 
     // Remark : Data member initializer is not allowed for ARM compiler,
     //          initialize data in class constructor.
-    runningTime = 0;
-    lastScanTime = runningTime;
     currentBeamAngle = 0;
     lastBeamAngle = currentBeamAngle;
 
@@ -50,39 +45,25 @@
     // Initialize touchscreen
     ts.Init(((RK043FN48H*)GetDisplay())->DisplayWidth(), ((RK043FN48H*)GetDisplay())->DisplayHeight());
 
-#ifndef _SDL_timer_h
-    t.start();
-#endif
+    timer.Start();
 }
 
 
 void RadarDemo::Render()
 {
-    // Reset scan time after one full turn
-    if (runningTime >= (lastScanTime + scanPeriod)) {
-        lastScanTime = runningTime;
-    }
+    timer.RegisterScan();
 
     // Calculate actual beam position
     lastBeamAngle = currentBeamAngle;
+    currentBeamAngle = timer.GetBeamAngle();
 
-#ifdef _SDL_timer_h
-    uint32_t msTime = SDL_GetTicks();
-#else
-    int msTime = t.read_ms();
-#endif
-    currentBeamAngle = 2 * M_PI * (msTime - lastScanTime) / (float)scanPeriod;
-    if(currentBeamAngle >= (2 * M_PI)) {
-        currentBeamAngle -= 2 * M_PI;
-    }
-
-    RK043FN48H* display = (RK043FN48H*)GetDisplay();
-
+    // TODO: 
     if(DetectTouch(window))
     {
         // Set timeout for the next touch detection
     }
 
+    RK043FN48H* display = (RK043FN48H*)GetDisplay();
     if(NeedsRedraw()) {
 
         display->SetActiveLayer(Background);
@@ -100,16 +81,9 @@
 
         display->SetActiveLayer(Foreground);
         _needsRedraw = false;
-
     }
 
-#ifdef _SDL_timer_h
-    runningTime = SDL_GetTicks();
-#else
-    runningTime = t.read_ms();
-#endif
-
-    UpdateTargetsLocation(lastBeamAngle, currentBeamAngle, runningTime);
+    UpdateTargetsLocation(lastBeamAngle, currentBeamAngle, timer.GetRunningTime());
 
     // Redraw foreground
     display->Clear();
@@ -121,13 +95,7 @@
 
 bool RadarDemo::IsRunning()
 {
-#ifdef _SDL_timer_h
-    runningTime = SDL_GetTicks();
-#else
-    runningTime = t.read_ms();
-#endif
-
-    return demoTime > 0 ? runningTime <= demoTime : true;
+    return demoTime > 0 ? timer.GetRunningTime() <= demoTime : true;
 }
 
 
@@ -137,11 +105,7 @@
     const float maxSpeed = 800; // [km/h]
     Target *target;
 
-#ifdef _SDL_timer_h
-    srand(SDL_GetTicks());
-#else
-    srand(t.read_us());
-#endif
+    srand(timer.GetRunningTime());
 
     for (int i = 0; i<count; i++) {
         // Generate target parameters
@@ -178,7 +142,7 @@
 
     ts.GetState(&tsState);
 
-    if (tsState.touchDetected) {
+    if (tsState.touchDetected > 0) {
 
         if(tsState.touchX[0] > (screen.x2-raSize) && tsState.touchY[0] < screen.y1 + raSize) {
             if(ChangeRange(1))