From e30f1fadd945e7ad34a5d4497119adf5358505b9 Mon Sep 17 00:00:00 2001 From: mikeller Date: Sun, 3 Jun 2018 17:29:48 +1200 Subject: [PATCH 1/4] Fixed OSD altitude display for negative altitude > -1. --- src/main/io/osd.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 83cad0b73e..fb5c682d32 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -270,14 +270,10 @@ 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, "%s%d.%01d%c", alt < 0 ? "-" : "", abs(alt / 10), abs(alt % 10), osdGetMetersToSelectedUnitSymbol()); } static void osdFormatPID(char * buff, const char * label, const pid8_t * pid) @@ -551,7 +547,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 +1366,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); } From 0aba86ccb41f491dc9ea87c6642fe455ddf43612 Mon Sep 17 00:00:00 2001 From: mikeller Date: Sun, 3 Jun 2018 22:40:01 +1200 Subject: [PATCH 2/4] Converted it to fixed width. --- src/main/io/osd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index fb5c682d32..f4051ff1a9 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -273,7 +273,11 @@ static char osdGetTemperatureSymbolForSelectedUnit(void) static void osdFormatAltitudeString(char * buff, int altitude) { const int alt = osdGetMetersToSelectedUnit(altitude) / 10; - tfp_sprintf(buff, "%s%d.%01d%c", alt < 0 ? "-" : "", abs(alt / 10), abs(alt % 10), osdGetMetersToSelectedUnitSymbol()); + + tfp_sprintf(buff, "%5d", alt); + buff[5] = buff[4]; + buff[4] = '.'; + buff[6] = osdGetMetersToSelectedUnitSymbol(); } static void osdFormatPID(char * buff, const char * label, const pid8_t * pid) From fa24697df6ea09c2aa8df6668e9adb2ffeeae4c2 Mon Sep 17 00:00:00 2001 From: mikeller Date: Sun, 3 Jun 2018 22:43:12 +1200 Subject: [PATCH 3/4] Make it terminate the string properly. --- src/main/io/osd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index f4051ff1a9..c0829e2718 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -274,10 +274,9 @@ static void osdFormatAltitudeString(char * buff, int altitude) { const int alt = osdGetMetersToSelectedUnit(altitude) / 10; - tfp_sprintf(buff, "%5d", alt); + tfp_sprintf(buff, "%5d %c", alt, osdGetMetersToSelectedUnitSymbol()); buff[5] = buff[4]; buff[4] = '.'; - buff[6] = osdGetMetersToSelectedUnitSymbol(); } static void osdFormatPID(char * buff, const char * label, const pid8_t * pid) From df06b9b4cbc59603e13205563eebb737936db1c1 Mon Sep 17 00:00:00 2001 From: mikeller Date: Mon, 4 Jun 2018 00:23:45 +1200 Subject: [PATCH 4/4] Fixed tests. --- src/test/unit/osd_unittest.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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); } /*