Optimaze with new mbed os for study

Dependencies:   TS_DISCO_F746NG BSP_DISCO_F746NG Graphics

Revision:
3:732f7144ec81
Child:
4:66f13188c26b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RadarDemo/RadarTimer.cpp	Sat Nov 05 15:36:59 2016 +0000
@@ -0,0 +1,57 @@
+#include "RadarTimer.h"
+#include "Commons.h"
+
+RadarTimer::RadarTimer()
+{
+
+}
+
+RadarTimer::RadarTimer(uint32_t scanPeriod)
+{
+    SetScanPeriod(scanPeriod);
+}
+
+
+void RadarTimer::SetScanPeriod(uint32_t scanPeriod)
+{
+    _scanPeriod = scanPeriod * 1000;
+}
+
+void RadarTimer::Start()
+{
+#ifndef _SDL_timer_h
+   start();
+#endif
+}
+
+uint32_t RadarTimer::GetRunningTime()
+{
+#ifdef _SDL_timer_h
+    return SDL_GetTicks();
+#else
+    return read_ms();
+#endif
+}
+
+
+void RadarTimer::RegisterScan()
+{
+    // Lock scan time  
+    _runningTime = GetRunningTime();
+    
+    // Reset scan time after one full turn
+    if (_runningTime >= (_lastScanTime + _scanPeriod)) {
+        _lastScanTime = _runningTime;
+    }
+}
+
+
+float RadarTimer::GetBeamAngle()
+{
+    float angle = 2 * M_PI * (GetRunningTime() - _lastScanTime) / (float)_scanPeriod;
+    if(angle >= (2 * M_PI)) {
+        angle -= 2 * M_PI;
+    }
+    
+    return angle;
+}
\ No newline at end of file