diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 83cad0b73e..c0829e2718 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -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); } diff --git a/src/test/unit/osd_unittest.cc b/src/test/unit/osd_unittest.cc index 93fe9a604b..353fddcc9d 100644 --- a/src/test/unit/osd_unittest.cc +++ b/src/test/unit/osd_unittest.cc @@ -372,7 +372,7 @@ TEST(OsdTest, TestStatsImperial) displayPortTestBufferSubstring(2, row++, "MIN BATTERY : 14.7%c", SYM_VOLT); displayPortTestBufferSubstring(2, row++, "END BATTERY : 15.2%c", SYM_VOLT); 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++, "END BATTERY : 15.2%c", SYM_VOLT); 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(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); } /*