Optimaze with new mbed os for study

Dependencies:   TS_DISCO_F746NG BSP_DISCO_F746NG Graphics

RadarDemo/Radar.h

Committer:
karpent
Date:
2016-11-04
Revision:
0:d8b9955d2b36
Child:
1:5e49b46de1b0

File content as of revision 0:d8b9955d2b36:

//
// 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;

};