Optimaze with new mbed os for study
Dependencies: TS_DISCO_F746NG BSP_DISCO_F746NG Graphics
Diff: RadarDemo/Radar.cpp
- Revision:
- 2:8db224cc1fcb
- Parent:
- 1:5e49b46de1b0
diff -r 5e49b46de1b0 -r 8db224cc1fcb RadarDemo/Radar.cpp --- a/RadarDemo/Radar.cpp Fri Nov 04 17:10:50 2016 +0000 +++ b/RadarDemo/Radar.cpp Fri Nov 04 23:07:04 2016 +0000 @@ -252,6 +252,57 @@ return _display; } +void Radar::DrawRangeButtons(uint16_t raSize) +{ + const uint16_t signSize = 5; + uint16_t centerX; + uint16_t centerY; + + // Increase buton on right top + if(_rangeNumber < MAX_RANGE_INDEX) { + centerX = window.x2-raSize/2; + centerY = raSize/2; + + _display->DrawRectangle(window.x2-raSize, window.y1, window.x2, raSize); + _display->DrawLine(centerX-signSize, centerY, centerX+signSize, centerY); + } + + // Decrease button on right bottom + if(_rangeNumber > 0) { + centerX = window.x2-raSize/2; + centerY = window.y2-raSize/2; + + _display->DrawRectangle(window.x2-raSize, window.y2-raSize, window.x2, window.y2); + _display->DrawLine(centerX-signSize, centerY, centerX+signSize, centerY); + _display->DrawLine(centerX, centerY-signSize, centerX, centerY+signSize); + } +} + + +void Radar::SetRange(uint8_t rangeNumber) +{ + if (rangeNumber <= MAX_RANGE_INDEX) { + _rangeNumber = rangeNumber; + + int localRange = (window.y2 - window.y1) / 2; + _scaleRatio = localRange / GetRange(); + } +} + + +bool Radar::ChangeRange(int change) +{ + if (change > 0 && _rangeNumber < MAX_RANGE_INDEX) { + SetRange( _rangeNumber + 1); + return true; + } + if (change < 0 && _rangeNumber > 0) { + SetRange( _rangeNumber - 1); + return true; + } + return false; +} + int Radar::_centerX; int Radar::_centerY;