Optimaze with new mbed os for study

Dependencies:   TS_DISCO_F746NG BSP_DISCO_F746NG Graphics

Committer:
karpent
Date:
Fri Nov 04 17:10:50 2016 +0000
Revision:
1:5e49b46de1b0
Parent:
0:d8b9955d2b36
Child:
2:8db224cc1fcb
Graphics folder published as a library, minor comments update.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
karpent 1:5e49b46de1b0 1 /*
karpent 1:5e49b46de1b0 2 Radar.h - Simple radar simulator, example of graphic commands usage to create 2D graphics.
karpent 1:5e49b46de1b0 3
karpent 1:5e49b46de1b0 4 Copyright(c) 2016 karpent at gmail.com, MIT License
karpent 1:5e49b46de1b0 5
karpent 1:5e49b46de1b0 6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"),
karpent 1:5e49b46de1b0 7 to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
karpent 1:5e49b46de1b0 8 and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
karpent 1:5e49b46de1b0 9
karpent 1:5e49b46de1b0 10 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
karpent 1:5e49b46de1b0 11
karpent 1:5e49b46de1b0 12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
karpent 1:5e49b46de1b0 13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
karpent 1:5e49b46de1b0 14 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
karpent 1:5e49b46de1b0 15 THE USE OR OTHER DEALINGS IN THE SOFTWARE.
karpent 1:5e49b46de1b0 16 */
karpent 0:d8b9955d2b36 17
karpent 0:d8b9955d2b36 18 #pragma once
karpent 0:d8b9955d2b36 19
karpent 0:d8b9955d2b36 20 #include "Commons.h"
karpent 0:d8b9955d2b36 21 #include "Display.h"
karpent 0:d8b9955d2b36 22 #include "Target.h"
karpent 0:d8b9955d2b36 23 #include <list>
karpent 0:d8b9955d2b36 24
karpent 0:d8b9955d2b36 25 using namespace std;
karpent 0:d8b9955d2b36 26
karpent 0:d8b9955d2b36 27 static const uint8_t _maxRangeNumber = 1;
karpent 0:d8b9955d2b36 28 static const uint8_t _minRangeNumber = 0;
karpent 0:d8b9955d2b36 29
karpent 0:d8b9955d2b36 30 #define MAX_RANGE_INDEX 2
karpent 0:d8b9955d2b36 31 static const float _ranges[MAX_RANGE_INDEX + 1] = { 50, 100, 300 }; // km
karpent 0:d8b9955d2b36 32 static const float _rangeMarkersDelta[MAX_RANGE_INDEX + 1] = { 10, 25, 50 }; // km
karpent 0:d8b9955d2b36 33 static const int azimuthMarkersCount = 8;
karpent 0:d8b9955d2b36 34
karpent 0:d8b9955d2b36 35 class Radar
karpent 0:d8b9955d2b36 36 {
karpent 0:d8b9955d2b36 37 public:
karpent 0:d8b9955d2b36 38
karpent 0:d8b9955d2b36 39 Radar(Display* display);
karpent 0:d8b9955d2b36 40 ~Radar();
karpent 0:d8b9955d2b36 41
karpent 0:d8b9955d2b36 42 /// <summary>
karpent 0:d8b9955d2b36 43 /// Draws all visible tracks.
karpent 0:d8b9955d2b36 44 /// </summary>
karpent 0:d8b9955d2b36 45 void DrawTracks();
karpent 0:d8b9955d2b36 46
karpent 0:d8b9955d2b36 47
karpent 0:d8b9955d2b36 48 /// <summary>
karpent 1:5e49b46de1b0 49 /// Updates the targets in sector for the current time.
karpent 1:5e49b46de1b0 50 /// Returns true if targets found.
karpent 0:d8b9955d2b36 51 /// </summary>
karpent 0:d8b9955d2b36 52 /// <param name="startAngle">The start angle.</param>
karpent 0:d8b9955d2b36 53 /// <param name="endAngle">The end angle.</param>
karpent 0:d8b9955d2b36 54 /// <param name="currentTime">Current Time in miliseconds.</param>
karpent 1:5e49b46de1b0 55 bool UpdateTargetsLocation(float startAngle, float endAngle, uint32_t currentTime);
karpent 0:d8b9955d2b36 56
karpent 0:d8b9955d2b36 57
karpent 0:d8b9955d2b36 58 /// <summary>
karpent 0:d8b9955d2b36 59 /// Gets currently selected range in world coordinates [km].
karpent 0:d8b9955d2b36 60 /// </summary>
karpent 0:d8b9955d2b36 61 /// <returns></returns>
karpent 0:d8b9955d2b36 62 static float GetRange() {
karpent 0:d8b9955d2b36 63 return _ranges[_rangeNumber];
karpent 0:d8b9955d2b36 64 }
karpent 0:d8b9955d2b36 65
karpent 0:d8b9955d2b36 66 /// <summary>
karpent 0:d8b9955d2b36 67 /// Gets the maximum radar range in world coordinates [km].
karpent 0:d8b9955d2b36 68 /// </summary>
karpent 0:d8b9955d2b36 69 /// <returns></returns>
karpent 0:d8b9955d2b36 70 static float GetMaxRange() {
karpent 0:d8b9955d2b36 71 return _ranges[MAX_RANGE_INDEX];
karpent 0:d8b9955d2b36 72 }
karpent 0:d8b9955d2b36 73
karpent 0:d8b9955d2b36 74 /// <summary>
karpent 0:d8b9955d2b36 75 /// Sets current range number.
karpent 0:d8b9955d2b36 76 /// </summary>
karpent 0:d8b9955d2b36 77 /// <param name="rangeNumber">The range number.</param>
karpent 0:d8b9955d2b36 78 void SetRange(uint8_t rangeNumber) {
karpent 0:d8b9955d2b36 79 if (rangeNumber <= MAX_RANGE_INDEX) {
karpent 0:d8b9955d2b36 80 _rangeNumber = rangeNumber;
karpent 0:d8b9955d2b36 81
karpent 0:d8b9955d2b36 82 int localRange = (window.y2 - window.y1) / 2;
karpent 0:d8b9955d2b36 83 _scaleRatio = localRange / GetRange();
karpent 0:d8b9955d2b36 84 }
karpent 0:d8b9955d2b36 85 };
karpent 0:d8b9955d2b36 86
karpent 0:d8b9955d2b36 87 static int GetCenterX() {
karpent 0:d8b9955d2b36 88 return _centerX;
karpent 0:d8b9955d2b36 89 }
karpent 0:d8b9955d2b36 90
karpent 0:d8b9955d2b36 91 static int GetCenterY() {
karpent 0:d8b9955d2b36 92 return _centerY;
karpent 0:d8b9955d2b36 93 }
karpent 0:d8b9955d2b36 94
karpent 0:d8b9955d2b36 95 static void SetCenter(int x, int y) {
karpent 0:d8b9955d2b36 96 _centerX = x;
karpent 0:d8b9955d2b36 97 _centerY = y;
karpent 0:d8b9955d2b36 98 }
karpent 0:d8b9955d2b36 99
karpent 0:d8b9955d2b36 100 void DrawPlot(Location* plot);
karpent 0:d8b9955d2b36 101
karpent 0:d8b9955d2b36 102 void DrawRadarBeam(float azimuth);
karpent 0:d8b9955d2b36 103
karpent 0:d8b9955d2b36 104 protected:
karpent 0:d8b9955d2b36 105 /// <summary>
karpent 0:d8b9955d2b36 106 /// Initializes this instance.
karpent 0:d8b9955d2b36 107 /// </summary>
karpent 0:d8b9955d2b36 108 void Initialize();
karpent 0:d8b9955d2b36 109
karpent 0:d8b9955d2b36 110 void DrawBorder();
karpent 0:d8b9955d2b36 111 void DrawMarkers();
karpent 0:d8b9955d2b36 112 void DrawTarget(Target* target);
karpent 0:d8b9955d2b36 113
karpent 0:d8b9955d2b36 114 protected:
karpent 0:d8b9955d2b36 115 Display* GetDisplay();
karpent 0:d8b9955d2b36 116 list<Target> targetsList;
karpent 0:d8b9955d2b36 117
karpent 0:d8b9955d2b36 118 private:
karpent 0:d8b9955d2b36 119
karpent 0:d8b9955d2b36 120 /// <summary>
karpent 1:5e49b46de1b0 121 /// Display window in local coordinates system
karpent 0:d8b9955d2b36 122 /// </summary>
karpent 0:d8b9955d2b36 123 Window window;
karpent 0:d8b9955d2b36 124
karpent 0:d8b9955d2b36 125 /// <summary>
karpent 0:d8b9955d2b36 126 /// Center y position in local coordinate system
karpent 0:d8b9955d2b36 127 /// </summary>
karpent 0:d8b9955d2b36 128 static int _centerX;
karpent 0:d8b9955d2b36 129
karpent 0:d8b9955d2b36 130 /// <summary>
karpent 0:d8b9955d2b36 131 /// Center y position in local coordinate system
karpent 0:d8b9955d2b36 132 /// </summary>
karpent 0:d8b9955d2b36 133 static int _centerY;
karpent 0:d8b9955d2b36 134
karpent 0:d8b9955d2b36 135 /// <summary>
karpent 0:d8b9955d2b36 136 /// Selected range (0..MaxRangeNumber)
karpent 0:d8b9955d2b36 137 /// </summary>
karpent 0:d8b9955d2b36 138 static uint8_t _rangeNumber;
karpent 0:d8b9955d2b36 139
karpent 0:d8b9955d2b36 140 static float _scaleRatio;
karpent 0:d8b9955d2b36 141
karpent 0:d8b9955d2b36 142 // Can be canvas, display or SDL renderer
karpent 0:d8b9955d2b36 143 Display* _display;
karpent 0:d8b9955d2b36 144
karpent 0:d8b9955d2b36 145 };