Optimaze with new mbed os for study
Dependencies: TS_DISCO_F746NG BSP_DISCO_F746NG Graphics
RadarDemo/Radar.h@2:8db224cc1fcb, 2016-11-04 (annotated)
- Committer:
- karpent
- Date:
- Fri Nov 04 23:07:04 2016 +0000
- Revision:
- 2:8db224cc1fcb
- Parent:
- 1:5e49b46de1b0
Touchscreen support added to change the range and center location.
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:8db224cc1fcb | 27 | //static const uint8_t _maxRangeNumber = 1; |
karpent | 2:8db224cc1fcb | 28 | //static const uint8_t _minRangeNumber = 0; |
karpent | 0:d8b9955d2b36 | 29 | |
karpent | 0:d8b9955d2b36 | 30 | #define MAX_RANGE_INDEX 2 |
karpent | 2:8db224cc1fcb | 31 | static const float _ranges[MAX_RANGE_INDEX + 1] = { 50, 100, 300 }; // km |
karpent | 2:8db224cc1fcb | 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 | 2:8db224cc1fcb | 35 | /** |
karpent | 2:8db224cc1fcb | 36 | * @brief Simple radar simulator |
karpent | 2:8db224cc1fcb | 37 | */ |
karpent | 0:d8b9955d2b36 | 38 | class Radar |
karpent | 0:d8b9955d2b36 | 39 | { |
karpent | 0:d8b9955d2b36 | 40 | public: |
karpent | 0:d8b9955d2b36 | 41 | |
karpent | 0:d8b9955d2b36 | 42 | Radar(Display* display); |
karpent | 0:d8b9955d2b36 | 43 | ~Radar(); |
karpent | 0:d8b9955d2b36 | 44 | |
karpent | 0:d8b9955d2b36 | 45 | /// <summary> |
karpent | 0:d8b9955d2b36 | 46 | /// Draws all visible tracks. |
karpent | 0:d8b9955d2b36 | 47 | /// </summary> |
karpent | 0:d8b9955d2b36 | 48 | void DrawTracks(); |
karpent | 0:d8b9955d2b36 | 49 | |
karpent | 0:d8b9955d2b36 | 50 | |
karpent | 0:d8b9955d2b36 | 51 | /// <summary> |
karpent | 2:8db224cc1fcb | 52 | /// Updates the targets in sector for the current time. |
karpent | 1:5e49b46de1b0 | 53 | /// Returns true if targets found. |
karpent | 0:d8b9955d2b36 | 54 | /// </summary> |
karpent | 0:d8b9955d2b36 | 55 | /// <param name="startAngle">The start angle.</param> |
karpent | 0:d8b9955d2b36 | 56 | /// <param name="endAngle">The end angle.</param> |
karpent | 0:d8b9955d2b36 | 57 | /// <param name="currentTime">Current Time in miliseconds.</param> |
karpent | 1:5e49b46de1b0 | 58 | bool UpdateTargetsLocation(float startAngle, float endAngle, uint32_t currentTime); |
karpent | 0:d8b9955d2b36 | 59 | |
karpent | 0:d8b9955d2b36 | 60 | |
karpent | 0:d8b9955d2b36 | 61 | /// <summary> |
karpent | 0:d8b9955d2b36 | 62 | /// Gets currently selected range in world coordinates [km]. |
karpent | 0:d8b9955d2b36 | 63 | /// </summary> |
karpent | 0:d8b9955d2b36 | 64 | /// <returns></returns> |
karpent | 0:d8b9955d2b36 | 65 | static float GetRange() { |
karpent | 0:d8b9955d2b36 | 66 | return _ranges[_rangeNumber]; |
karpent | 0:d8b9955d2b36 | 67 | } |
karpent | 0:d8b9955d2b36 | 68 | |
karpent | 0:d8b9955d2b36 | 69 | /// <summary> |
karpent | 0:d8b9955d2b36 | 70 | /// Gets the maximum radar range in world coordinates [km]. |
karpent | 0:d8b9955d2b36 | 71 | /// </summary> |
karpent | 0:d8b9955d2b36 | 72 | /// <returns></returns> |
karpent | 0:d8b9955d2b36 | 73 | static float GetMaxRange() { |
karpent | 0:d8b9955d2b36 | 74 | return _ranges[MAX_RANGE_INDEX]; |
karpent | 0:d8b9955d2b36 | 75 | } |
karpent | 0:d8b9955d2b36 | 76 | |
karpent | 0:d8b9955d2b36 | 77 | /// <summary> |
karpent | 0:d8b9955d2b36 | 78 | /// Sets current range number. |
karpent | 0:d8b9955d2b36 | 79 | /// </summary> |
karpent | 0:d8b9955d2b36 | 80 | /// <param name="rangeNumber">The range number.</param> |
karpent | 2:8db224cc1fcb | 81 | void SetRange(uint8_t rangeNumber); |
karpent | 0:d8b9955d2b36 | 82 | |
karpent | 2:8db224cc1fcb | 83 | /// <summary> |
karpent | 2:8db224cc1fcb | 84 | /// Increase or decrease range. |
karpent | 2:8db224cc1fcb | 85 | /// </summary> |
karpent | 2:8db224cc1fcb | 86 | /// <param name="change">1 for increase range, -1 for decrease range</param> |
karpent | 2:8db224cc1fcb | 87 | bool ChangeRange(int change); |
karpent | 0:d8b9955d2b36 | 88 | |
karpent | 0:d8b9955d2b36 | 89 | static int GetCenterX() { |
karpent | 0:d8b9955d2b36 | 90 | return _centerX; |
karpent | 0:d8b9955d2b36 | 91 | } |
karpent | 0:d8b9955d2b36 | 92 | |
karpent | 0:d8b9955d2b36 | 93 | static int GetCenterY() { |
karpent | 0:d8b9955d2b36 | 94 | return _centerY; |
karpent | 0:d8b9955d2b36 | 95 | } |
karpent | 0:d8b9955d2b36 | 96 | |
karpent | 0:d8b9955d2b36 | 97 | static void SetCenter(int x, int y) { |
karpent | 0:d8b9955d2b36 | 98 | _centerX = x; |
karpent | 0:d8b9955d2b36 | 99 | _centerY = y; |
karpent | 0:d8b9955d2b36 | 100 | } |
karpent | 0:d8b9955d2b36 | 101 | |
karpent | 0:d8b9955d2b36 | 102 | protected: |
karpent | 0:d8b9955d2b36 | 103 | /// <summary> |
karpent | 0:d8b9955d2b36 | 104 | /// Initializes this instance. |
karpent | 0:d8b9955d2b36 | 105 | /// </summary> |
karpent | 0:d8b9955d2b36 | 106 | void Initialize(); |
karpent | 0:d8b9955d2b36 | 107 | |
karpent | 2:8db224cc1fcb | 108 | Display* GetDisplay(); |
karpent | 2:8db224cc1fcb | 109 | list<Target> targetsList; |
karpent | 2:8db224cc1fcb | 110 | |
karpent | 2:8db224cc1fcb | 111 | void DrawPlot(Location* plot); |
karpent | 2:8db224cc1fcb | 112 | void DrawRadarBeam(float azimuth); |
karpent | 0:d8b9955d2b36 | 113 | void DrawBorder(); |
karpent | 0:d8b9955d2b36 | 114 | void DrawMarkers(); |
karpent | 0:d8b9955d2b36 | 115 | void DrawTarget(Target* target); |
karpent | 2:8db224cc1fcb | 116 | void DrawRangeButtons(uint16_t raSize); |
karpent | 0:d8b9955d2b36 | 117 | |
karpent | 0:d8b9955d2b36 | 118 | /// <summary> |
karpent | 1:5e49b46de1b0 | 119 | /// Display window in local coordinates system |
karpent | 0:d8b9955d2b36 | 120 | /// </summary> |
karpent | 0:d8b9955d2b36 | 121 | Window window; |
karpent | 0:d8b9955d2b36 | 122 | |
karpent | 2:8db224cc1fcb | 123 | private: |
karpent | 2:8db224cc1fcb | 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 | 2:8db224cc1fcb | 144 | |
karpent | 0:d8b9955d2b36 | 145 | }; |