Optimaze with new mbed os for study
Dependencies: TS_DISCO_F746NG BSP_DISCO_F746NG Graphics
Diff: RadarDemo/Radar.h
- Revision:
- 0:d8b9955d2b36
- Child:
- 1:5e49b46de1b0
diff -r 000000000000 -r d8b9955d2b36 RadarDemo/Radar.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RadarDemo/Radar.h Fri Nov 04 01:02:37 2016 +0000 @@ -0,0 +1,133 @@ +// +// Radar.h - example of graphic commands usage to create 2D graphics. +// + +#pragma once + +#include "Commons.h" +#include "Display.h" +#include "Target.h" +#include <list> + +using namespace std; + +static const uint8_t _maxRangeNumber = 1; +static const uint8_t _minRangeNumber = 0; + +#define MAX_RANGE_INDEX 2 +static const float _ranges[MAX_RANGE_INDEX + 1] = { 50, 100, 300 }; // km +static const float _rangeMarkersDelta[MAX_RANGE_INDEX + 1] = { 10, 25, 50 }; // km +static const int azimuthMarkersCount = 8; + +class Radar +{ +public: + + Radar(Display* display); + //Radar(); + ~Radar(); + + /// <summary> + /// Draws all visible tracks. + /// </summary> + void DrawTracks(); + + + /// <summary> + /// Demo: Updates the targets in sector. + /// </summary> + /// <param name="startAngle">The start angle.</param> + /// <param name="endAngle">The end angle.</param> + /// <param name="currentTime">Current Time in miliseconds.</param> + void UpdateTargetsLocation(float startAngle, float endAngle, uint32_t currentTime); + + + /// <summary> + /// Gets currently selected range in world coordinates [km]. + /// </summary> + /// <returns></returns> + static float GetRange() { + return _ranges[_rangeNumber]; + } + + /// <summary> + /// Gets the maximum radar range in world coordinates [km]. + /// </summary> + /// <returns></returns> + static float GetMaxRange() { + return _ranges[MAX_RANGE_INDEX]; + } + + /// <summary> + /// Sets current range number. + /// </summary> + /// <param name="rangeNumber">The range number.</param> + void SetRange(uint8_t rangeNumber) { + if (rangeNumber <= MAX_RANGE_INDEX) { + _rangeNumber = rangeNumber; + + int localRange = (window.y2 - window.y1) / 2; + _scaleRatio = localRange / GetRange(); + } + }; + + static int GetCenterX() { + return _centerX; + } + + static int GetCenterY() { + return _centerY; + } + + static void SetCenter(int x, int y) { + _centerX = x; + _centerY = y; + } + + void DrawPlot(Location* plot); + + void DrawRadarBeam(float azimuth); + +protected: + /// <summary> + /// Initializes this instance. + /// </summary> + void Initialize(); + + void DrawBorder(); + void DrawMarkers(); + void DrawTarget(Target* target); + +protected: + Display* GetDisplay(); + list<Target> targetsList; + +private: + + + /// <summary> + /// Display window in local coordinate system + /// </summary> + Window window; + + /// <summary> + /// Center y position in local coordinate system + /// </summary> + static int _centerX; + + /// <summary> + /// Center y position in local coordinate system + /// </summary> + static int _centerY; + + /// <summary> + /// Selected range (0..MaxRangeNumber) + /// </summary> + static uint8_t _rangeNumber; + + static float _scaleRatio; + + // Can be canvas, display or SDL renderer + Display* _display; + +}; \ No newline at end of file