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

View file

@ -486,7 +486,7 @@ TEST(OsdTest, TestAlarms)
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(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
@ -717,7 +717,7 @@ TEST(OsdTest, TestElementAltitude)
osdRefresh(simulationTime);
// then
displayPortTestBufferSubstring(23, 7, " 0.0%c", SYM_M);
displayPortTestBufferSubstring(23, 7, " .0%c", SYM_M);
// when
simulationAltitude = 247;
@ -742,6 +742,14 @@ TEST(OsdTest, TestElementAltitude)
// then
displayPortTestBufferSubstring(23, 7, " -2.4%c", SYM_M);
// when
simulationAltitude = -70;
displayClearScreen(&testDisplayPort);
osdRefresh(simulationTime);
// then
displayPortTestBufferSubstring(23, 7, " -.7%c", SYM_M);
}
/*