Optimaze with new mbed os for study

Dependencies:   TS_DISCO_F746NG BSP_DISCO_F746NG Graphics

Committer:
karpent
Date:
Fri Nov 04 01:02:37 2016 +0000
Revision:
0:d8b9955d2b36
Child:
1:5e49b46de1b0
Initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
karpent 0:d8b9955d2b36 1 //
karpent 0:d8b9955d2b36 2 // Radar.h - example of graphic commands usage to create 2D graphics.
karpent 0:d8b9955d2b36 3 //
karpent 0:d8b9955d2b36 4
karpent 0:d8b9955d2b36 5 #pragma once
karpent 0:d8b9955d2b36 6
karpent 0:d8b9955d2b36 7 #include "Commons.h"
karpent 0:d8b9955d2b36 8 #include "Display.h"
karpent 0:d8b9955d2b36 9 #include "Target.h"
karpent 0:d8b9955d2b36 10 #include <list>
karpent 0:d8b9955d2b36 11
karpent 0:d8b9955d2b36 12 using namespace std;
karpent 0:d8b9955d2b36 13
karpent 0:d8b9955d2b36 14 static const uint8_t _maxRangeNumber = 1;
karpent 0:d8b9955d2b36 15 static const uint8_t _minRangeNumber = 0;
karpent 0:d8b9955d2b36 16
karpent 0:d8b9955d2b36 17 #define MAX_RANGE_INDEX 2
karpent 0:d8b9955d2b36 18 static const float _ranges[MAX_RANGE_INDEX + 1] = { 50, 100, 300 }; // km
karpent 0:d8b9955d2b36 19 static const float _rangeMarkersDelta[MAX_RANGE_INDEX + 1] = { 10, 25, 50 }; // km
karpent 0:d8b9955d2b36 20 static const int azimuthMarkersCount = 8;
karpent 0:d8b9955d2b36 21
karpent 0:d8b9955d2b36 22 class Radar
karpent 0:d8b9955d2b36 23 {
karpent 0:d8b9955d2b36 24 public:
karpent 0:d8b9955d2b36 25
karpent 0:d8b9955d2b36 26 Radar(Display* display);
karpent 0:d8b9955d2b36 27 //Radar();
karpent 0:d8b9955d2b36 28 ~Radar();
karpent 0:d8b9955d2b36 29
karpent 0:d8b9955d2b36 30 /// <summary>
karpent 0:d8b9955d2b36 31 /// Draws all visible tracks.
karpent 0:d8b9955d2b36 32 /// </summary>
karpent 0:d8b9955d2b36 33 void DrawTracks();
karpent 0:d8b9955d2b36 34
karpent 0:d8b9955d2b36 35
karpent 0:d8b9955d2b36 36 /// <summary>
karpent 0:d8b9955d2b36 37 /// Demo: Updates the targets in sector.
karpent 0:d8b9955d2b36 38 /// </summary>
karpent 0:d8b9955d2b36 39 /// <param name="startAngle">The start angle.</param>
karpent 0:d8b9955d2b36 40 /// <param name="endAngle">The end angle.</param>
karpent 0:d8b9955d2b36 41 /// <param name="currentTime">Current Time in miliseconds.</param>
karpent 0:d8b9955d2b36 42 void UpdateTargetsLocation(float startAngle, float endAngle, uint32_t currentTime);
karpent 0:d8b9955d2b36 43
karpent 0:d8b9955d2b36 44
karpent 0:d8b9955d2b36 45 /// <summary>
karpent 0:d8b9955d2b36 46 /// Gets currently selected range in world coordinates [km].
karpent 0:d8b9955d2b36 47 /// </summary>
karpent 0:d8b9955d2b36 48 /// <returns></returns>
karpent 0:d8b9955d2b36 49 static float GetRange() {
karpent 0:d8b9955d2b36 50 return _ranges[_rangeNumber];
karpent 0:d8b9955d2b36 51 }
karpent 0:d8b9955d2b36 52
karpent 0:d8b9955d2b36 53 /// <summary>
karpent 0:d8b9955d2b36 54 /// Gets the maximum radar range in world coordinates [km].
karpent 0:d8b9955d2b36 55 /// </summary>
karpent 0:d8b9955d2b36 56 /// <returns></returns>
karpent 0:d8b9955d2b36 57 static float GetMaxRange() {
karpent 0:d8b9955d2b36 58 return _ranges[MAX_RANGE_INDEX];
karpent 0:d8b9955d2b36 59 }
karpent 0:d8b9955d2b36 60
karpent 0:d8b9955d2b36 61 /// <summary>
karpent 0:d8b9955d2b36 62 /// Sets current range number.
karpent 0:d8b9955d2b36 63 /// </summary>
karpent 0:d8b9955d2b36 64 /// <param name="rangeNumber">The range number.</param>
karpent 0:d8b9955d2b36 65 void SetRange(uint8_t rangeNumber) {
karpent 0:d8b9955d2b36 66 if (rangeNumber <= MAX_RANGE_INDEX) {
karpent 0:d8b9955d2b36 67 _rangeNumber = rangeNumber;
karpent 0:d8b9955d2b36 68
karpent 0:d8b9955d2b36 69 int localRange = (window.y2 - window.y1) / 2;
karpent 0:d8b9955d2b36 70 _scaleRatio = localRange / GetRange();
karpent 0:d8b9955d2b36 71 }
karpent 0:d8b9955d2b36 72 };
karpent 0:d8b9955d2b36 73
karpent 0:d8b9955d2b36 74 static int GetCenterX() {
karpent 0:d8b9955d2b36 75 return _centerX;
karpent 0:d8b9955d2b36 76 }
karpent 0:d8b9955d2b36 77
karpent 0:d8b9955d2b36 78 static int GetCenterY() {
karpent 0:d8b9955d2b36 79 return _centerY;
karpent 0:d8b9955d2b36 80 }
karpent 0:d8b9955d2b36 81
karpent 0:d8b9955d2b36 82 static void SetCenter(int x, int y) {
karpent 0:d8b9955d2b36 83 _centerX = x;
karpent 0:d8b9955d2b36 84 _centerY = y;
karpent 0:d8b9955d2b36 85 }
karpent 0:d8b9955d2b36 86
karpent 0:d8b9955d2b36 87 void DrawPlot(Location* plot);
karpent 0:d8b9955d2b36 88
karpent 0:d8b9955d2b36 89 void DrawRadarBeam(float azimuth);
karpent 0:d8b9955d2b36 90
karpent 0:d8b9955d2b36 91 protected:
karpent 0:d8b9955d2b36 92 /// <summary>
karpent 0:d8b9955d2b36 93 /// Initializes this instance.
karpent 0:d8b9955d2b36 94 /// </summary>
karpent 0:d8b9955d2b36 95 void Initialize();
karpent 0:d8b9955d2b36 96
karpent 0:d8b9955d2b36 97 void DrawBorder();
karpent 0:d8b9955d2b36 98 void DrawMarkers();
karpent 0:d8b9955d2b36 99 void DrawTarget(Target* target);
karpent 0:d8b9955d2b36 100
karpent 0:d8b9955d2b36 101 protected:
karpent 0:d8b9955d2b36 102 Display* GetDisplay();
karpent 0:d8b9955d2b36 103 list<Target> targetsList;
karpent 0:d8b9955d2b36 104
karpent 0:d8b9955d2b36 105 private:
karpent 0:d8b9955d2b36 106
karpent 0:d8b9955d2b36 107
karpent 0:d8b9955d2b36 108 /// <summary>
karpent 0:d8b9955d2b36 109 /// Display window in local coordinate system
karpent 0:d8b9955d2b36 110 /// </summary>
karpent 0:d8b9955d2b36 111 Window window;
karpent 0:d8b9955d2b36 112
karpent 0:d8b9955d2b36 113 /// <summary>
karpent 0:d8b9955d2b36 114 /// Center y position in local coordinate system
karpent 0:d8b9955d2b36 115 /// </summary>
karpent 0:d8b9955d2b36 116 static int _centerX;
karpent 0:d8b9955d2b36 117
karpent 0:d8b9955d2b36 118 /// <summary>
karpent 0:d8b9955d2b36 119 /// Center y position in local coordinate system
karpent 0:d8b9955d2b36 120 /// </summary>
karpent 0:d8b9955d2b36 121 static int _centerY;
karpent 0:d8b9955d2b36 122
karpent 0:d8b9955d2b36 123 /// <summary>
karpent 0:d8b9955d2b36 124 /// Selected range (0..MaxRangeNumber)
karpent 0:d8b9955d2b36 125 /// </summary>
karpent 0:d8b9955d2b36 126 static uint8_t _rangeNumber;
karpent 0:d8b9955d2b36 127
karpent 0:d8b9955d2b36 128 static float _scaleRatio;
karpent 0:d8b9955d2b36 129
karpent 0:d8b9955d2b36 130 // Can be canvas, display or SDL renderer
karpent 0:d8b9955d2b36 131 Display* _display;
karpent 0:d8b9955d2b36 132
karpent 0:d8b9955d2b36 133 };