Optimaze with new mbed os for study

Dependencies:   TS_DISCO_F746NG BSP_DISCO_F746NG Graphics

Committer:
karpent
Date:
Sat Nov 05 15:36:59 2016 +0000
Revision:
3:732f7144ec81
Child:
4:66f13188c26b
RadarTimer class added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
karpent 3:732f7144ec81 1 #include "RadarTimer.h"
karpent 3:732f7144ec81 2 #include "Commons.h"
karpent 3:732f7144ec81 3
karpent 3:732f7144ec81 4 RadarTimer::RadarTimer()
karpent 3:732f7144ec81 5 {
karpent 3:732f7144ec81 6
karpent 3:732f7144ec81 7 }
karpent 3:732f7144ec81 8
karpent 3:732f7144ec81 9 RadarTimer::RadarTimer(uint32_t scanPeriod)
karpent 3:732f7144ec81 10 {
karpent 3:732f7144ec81 11 SetScanPeriod(scanPeriod);
karpent 3:732f7144ec81 12 }
karpent 3:732f7144ec81 13
karpent 3:732f7144ec81 14
karpent 3:732f7144ec81 15 void RadarTimer::SetScanPeriod(uint32_t scanPeriod)
karpent 3:732f7144ec81 16 {
karpent 3:732f7144ec81 17 _scanPeriod = scanPeriod * 1000;
karpent 3:732f7144ec81 18 }
karpent 3:732f7144ec81 19
karpent 3:732f7144ec81 20 void RadarTimer::Start()
karpent 3:732f7144ec81 21 {
karpent 3:732f7144ec81 22 #ifndef _SDL_timer_h
karpent 3:732f7144ec81 23 start();
karpent 3:732f7144ec81 24 #endif
karpent 3:732f7144ec81 25 }
karpent 3:732f7144ec81 26
karpent 3:732f7144ec81 27 uint32_t RadarTimer::GetRunningTime()
karpent 3:732f7144ec81 28 {
karpent 3:732f7144ec81 29 #ifdef _SDL_timer_h
karpent 3:732f7144ec81 30 return SDL_GetTicks();
karpent 3:732f7144ec81 31 #else
karpent 3:732f7144ec81 32 return read_ms();
karpent 3:732f7144ec81 33 #endif
karpent 3:732f7144ec81 34 }
karpent 3:732f7144ec81 35
karpent 3:732f7144ec81 36
karpent 3:732f7144ec81 37 void RadarTimer::RegisterScan()
karpent 3:732f7144ec81 38 {
karpent 3:732f7144ec81 39 // Lock scan time
karpent 3:732f7144ec81 40 _runningTime = GetRunningTime();
karpent 3:732f7144ec81 41
karpent 3:732f7144ec81 42 // Reset scan time after one full turn
karpent 3:732f7144ec81 43 if (_runningTime >= (_lastScanTime + _scanPeriod)) {
karpent 3:732f7144ec81 44 _lastScanTime = _runningTime;
karpent 3:732f7144ec81 45 }
karpent 3:732f7144ec81 46 }
karpent 3:732f7144ec81 47
karpent 3:732f7144ec81 48
karpent 3:732f7144ec81 49 float RadarTimer::GetBeamAngle()
karpent 3:732f7144ec81 50 {
karpent 3:732f7144ec81 51 float angle = 2 * M_PI * (GetRunningTime() - _lastScanTime) / (float)_scanPeriod;
karpent 3:732f7144ec81 52 if(angle >= (2 * M_PI)) {
karpent 3:732f7144ec81 53 angle -= 2 * M_PI;
karpent 3:732f7144ec81 54 }
karpent 3:732f7144ec81 55
karpent 3:732f7144ec81 56 return angle;
karpent 3:732f7144ec81 57 }