1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-20 14:55:21 +03:00

Merge pull request #6031 from mikeller/fix_osd_altitude_display

Fixed OSD altitude display for negative altitude > -1.
This commit is contained in:
Michael Keller 2018-06-05 13:11:30 +12:00 committed by GitHub
commit 522e90ab17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 13 deletions

View file

@ -270,14 +270,13 @@ static char osdGetTemperatureSymbolForSelectedUnit(void)
} }
#endif #endif
static void osdFormatAltitudeString(char * buff, int altitude, bool pad) static void osdFormatAltitudeString(char * buff, int altitude)
{ {
const int alt = osdGetMetersToSelectedUnit(altitude); const int alt = osdGetMetersToSelectedUnit(altitude) / 10;
int altitudeIntergerPart = abs(alt / 100);
if (alt < 0) { tfp_sprintf(buff, "%5d %c", alt, osdGetMetersToSelectedUnitSymbol());
altitudeIntergerPart *= -1; buff[5] = buff[4];
} buff[4] = '.';
tfp_sprintf(buff, pad ? "%4d.%01d%c" : "%d.%01d%c", altitudeIntergerPart, abs((alt % 100) / 10), osdGetMetersToSelectedUnitSymbol());
} }
static void osdFormatPID(char * buff, const char * label, const pid8_t * pid) static void osdFormatPID(char * buff, const char * label, const pid8_t * pid)
@ -551,7 +550,7 @@ static bool osdDrawSingleElement(uint8_t item)
break; break;
case OSD_ALTITUDE: case OSD_ALTITUDE:
osdFormatAltitudeString(buff, getEstimatedAltitude(), true); osdFormatAltitudeString(buff, getEstimatedAltitude());
break; break;
case OSD_ITEM_TIMER_1: case OSD_ITEM_TIMER_1:
@ -1370,7 +1369,7 @@ static void osdShowStats(uint16_t endBatteryVoltage)
} }
if (osdStatGetState(OSD_STAT_MAX_ALTITUDE)) { if (osdStatGetState(OSD_STAT_MAX_ALTITUDE)) {
osdFormatAltitudeString(buff, stats.max_altitude, false); osdFormatAltitudeString(buff, stats.max_altitude);
osdDisplayStatisticLabel(top++, "MAX ALTITUDE", buff); osdDisplayStatisticLabel(top++, "MAX ALTITUDE", buff);
} }

View file

@ -372,7 +372,7 @@ TEST(OsdTest, TestStatsImperial)
displayPortTestBufferSubstring(2, row++, "MIN BATTERY : 14.7%c", SYM_VOLT); displayPortTestBufferSubstring(2, row++, "MIN BATTERY : 14.7%c", SYM_VOLT);
displayPortTestBufferSubstring(2, row++, "END BATTERY : 15.2%c", SYM_VOLT); displayPortTestBufferSubstring(2, row++, "END BATTERY : 15.2%c", SYM_VOLT);
displayPortTestBufferSubstring(2, row++, "MIN RSSI : 25%%"); displayPortTestBufferSubstring(2, row++, "MIN RSSI : 25%%");
displayPortTestBufferSubstring(2, row++, "MAX ALTITUDE : 6.5%c", SYM_FT); displayPortTestBufferSubstring(2, row++, "MAX ALTITUDE : 6.5%c", SYM_FT);
} }
/* /*
@ -423,7 +423,7 @@ TEST(OsdTest, TestStatsMetric)
displayPortTestBufferSubstring(2, row++, "MIN BATTERY : 14.7%c", SYM_VOLT); displayPortTestBufferSubstring(2, row++, "MIN BATTERY : 14.7%c", SYM_VOLT);
displayPortTestBufferSubstring(2, row++, "END BATTERY : 15.2%c", SYM_VOLT); displayPortTestBufferSubstring(2, row++, "END BATTERY : 15.2%c", SYM_VOLT);
displayPortTestBufferSubstring(2, row++, "MIN RSSI : 25%%"); displayPortTestBufferSubstring(2, row++, "MIN RSSI : 25%%");
displayPortTestBufferSubstring(2, row++, "MAX ALTITUDE : 2.0%c", SYM_M); displayPortTestBufferSubstring(2, row++, "MAX ALTITUDE : 2.0%c", SYM_M);
} }
/* /*
@ -486,7 +486,7 @@ TEST(OsdTest, TestAlarms)
displayPortTestBufferSubstring(12, 1, "%c16.8%c", SYM_BATT_FULL, SYM_VOLT); displayPortTestBufferSubstring(12, 1, "%c16.8%c", SYM_BATT_FULL, SYM_VOLT);
displayPortTestBufferSubstring(1, 1, "%c00:", SYM_FLY_M); // only test the minute part of the timer displayPortTestBufferSubstring(1, 1, "%c00:", SYM_FLY_M); // only test the minute part of the timer
displayPortTestBufferSubstring(20, 1, "%c01:", SYM_ON_M); // only test the minute part of the timer displayPortTestBufferSubstring(20, 1, "%c01:", SYM_ON_M); // only test the minute part of the timer
displayPortTestBufferSubstring(23, 7, " 0.0%c", SYM_M); displayPortTestBufferSubstring(23, 7, " .0%c", SYM_M);
} }
// when // when
@ -717,7 +717,7 @@ TEST(OsdTest, TestElementAltitude)
osdRefresh(simulationTime); osdRefresh(simulationTime);
// then // then
displayPortTestBufferSubstring(23, 7, " 0.0%c", SYM_M); displayPortTestBufferSubstring(23, 7, " .0%c", SYM_M);
// when // when
simulationAltitude = 247; simulationAltitude = 247;
@ -742,6 +742,14 @@ TEST(OsdTest, TestElementAltitude)
// then // then
displayPortTestBufferSubstring(23, 7, " -2.4%c", SYM_M); displayPortTestBufferSubstring(23, 7, " -2.4%c", SYM_M);
// when
simulationAltitude = -70;
displayClearScreen(&testDisplayPort);
osdRefresh(simulationTime);
// then
displayPortTestBufferSubstring(23, 7, " -.7%c", SYM_M);
} }
/* /*