Miroslaw K. / Mbed 2 deprecated RadarDemo

Dependencies:   BSP_DISCO_F746NG Graphics mbed TS_DISCO_F746NG

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Radar.h Source File

Radar.h

00001 /*
00002     Radar.h - Simple radar simulator, example of graphic commands usage to create 2D graphics.
00003 
00004     Copyright(c) 2016 karpent at gmail.com, MIT License
00005 
00006     Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"),
00007     to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008     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 :
00009 
00010     The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
00011 
00012     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00013     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00014     OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
00015     THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00016 */
00017 
00018 #pragma once
00019 
00020 #include "Commons.h"
00021 #include "Display.h"
00022 #include "Target.h"
00023 #include <list>
00024 
00025 using namespace std;
00026 
00027 //static const uint8_t _maxRangeNumber = 1;
00028 //static const uint8_t _minRangeNumber = 0;
00029 
00030 #define MAX_RANGE_INDEX 2
00031 static const float _ranges[MAX_RANGE_INDEX + 1]             = { 50, 100, 300 }; // km
00032 static const float _rangeMarkersDelta[MAX_RANGE_INDEX + 1]  = { 10,  25,  50 }; // km
00033 static const int azimuthMarkersCount = 8;
00034 
00035 /**
00036   * @brief Simple radar simulator
00037   */
00038 class Radar
00039 {
00040 public:
00041 
00042     Radar(Display* display);
00043     ~Radar();
00044 
00045     /// <summary>
00046     /// Draws all visible tracks.
00047     /// </summary>
00048     void DrawTracks();
00049 
00050 
00051     /// <summary>
00052     /// Updates the targets in sector for the current time.
00053     /// Returns true if targets found.
00054     /// </summary>
00055     /// <param name="startAngle">The start angle.</param>
00056     /// <param name="endAngle">The end angle.</param>
00057     /// <param name="currentTime">Current Time in miliseconds.</param>
00058     bool UpdateTargetsLocation(float startAngle, float endAngle, uint32_t currentTime);
00059 
00060 
00061     /// <summary>
00062     /// Gets currently selected range in world coordinates [km].
00063     /// </summary>
00064     /// <returns></returns>
00065     static float GetRange() {
00066         return _ranges[_rangeNumber];
00067     }
00068 
00069     /// <summary>
00070     /// Gets the maximum radar range in world coordinates [km].
00071     /// </summary>
00072     /// <returns></returns>
00073     static float GetMaxRange() {
00074         return _ranges[MAX_RANGE_INDEX];
00075     }
00076 
00077     /// <summary>
00078     /// Sets current range number.
00079     /// </summary>
00080     /// <param name="rangeNumber">The range number.</param>
00081     void SetRange(uint8_t rangeNumber);
00082 
00083     /// <summary>
00084     /// Increase or decrease range.
00085     /// </summary>
00086     /// <param name="change">1 for increase range, -1 for decrease range</param>
00087     bool ChangeRange(int change);    
00088 
00089     static int GetCenterX() {
00090         return _centerX;
00091     }
00092 
00093     static int GetCenterY() {
00094         return _centerY;
00095     }
00096 
00097     static void SetCenter(int x, int y) {
00098         _centerX = x;
00099         _centerY = y;
00100     }
00101 
00102 protected:
00103     /// <summary>
00104     /// Initializes this instance.
00105     /// </summary>
00106     void Initialize();
00107 
00108     Display* GetDisplay();
00109     list<Target> targetsList;
00110     
00111     void DrawPlot(Location* plot);
00112     void DrawRadarBeam(float azimuth);
00113     void DrawBorder();
00114     void DrawMarkers();
00115     void DrawTarget(Target* target);
00116     void DrawRangeButtons(uint16_t raSize);
00117 
00118     /// <summary>
00119     /// Display window in local coordinates system
00120     /// </summary>
00121     Window window;
00122 
00123 private:
00124 
00125     /// <summary>
00126     /// Center y position in local coordinate system
00127     /// </summary>
00128     static int _centerX;
00129 
00130     /// <summary>
00131     /// Center y position in local coordinate system
00132     /// </summary>
00133     static int _centerY;
00134 
00135     /// <summary>
00136     /// Selected range (0..MaxRangeNumber)
00137     /// </summary>
00138     static uint8_t _rangeNumber;
00139 
00140     static float _scaleRatio;
00141 
00142     // Can be canvas, display or SDL renderer
00143     Display* _display;
00144     
00145 };