diff --git a/src/main/osd/osd_elements.c b/src/main/osd/osd_elements.c index 509bc02663..f6c3a813ea 100644 --- a/src/main/osd/osd_elements.c +++ b/src/main/osd/osd_elements.c @@ -211,9 +211,12 @@ static void osdFormatAltitudeString(char * buff, int32_t altitudeCm) { const int alt = osdGetMetersToSelectedUnit(altitudeCm) / 10; - tfp_sprintf(buff, "%c%5d %c", SYM_ALTITUDE, alt, osdGetMetersToSelectedUnitSymbol()); - buff[6] = buff[5]; - buff[5] = '.'; + int pos = 0; + buff[pos++] = SYM_ALTITUDE; + if (alt < 0) { + buff[pos++] = '-'; + } + tfp_sprintf(buff + pos, "%01d.%01d%c", abs(alt) / 10 , abs(alt) % 10, osdGetMetersToSelectedUnitSymbol()); } #ifdef USE_GPS diff --git a/src/test/unit/osd_unittest.cc b/src/test/unit/osd_unittest.cc index fc22bd57ec..61cb8097ff 100644 --- a/src/test/unit/osd_unittest.cc +++ b/src/test/unit/osd_unittest.cc @@ -524,7 +524,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, "%c .0%c", SYM_ALTITUDE, SYM_M); + displayPortTestBufferSubstring(23, 7, "%c0.0%c", SYM_ALTITUDE, SYM_M); } // when @@ -553,7 +553,7 @@ TEST(OsdTest, TestAlarms) displayPortTestBufferSubstring(12, 1, "%c13.5%c", SYM_MAIN_BATT, SYM_VOLT); displayPortTestBufferSubstring(1, 1, "%c01:", SYM_FLY_M); // only test the minute part of the timer displayPortTestBufferSubstring(20, 1, "%c02:", SYM_ON_M); // only test the minute part of the timer - displayPortTestBufferSubstring(23, 7, "%c 120.0%c", SYM_ALTITUDE, SYM_M); + displayPortTestBufferSubstring(23, 7, "%c120.0%c", SYM_ALTITUDE, SYM_M); } else { displayPortTestBufferIsEmpty(); } @@ -774,7 +774,7 @@ TEST(OsdTest, TestElementAltitude) osdRefresh(simulationTime); // then - displayPortTestBufferSubstring(23, 7, "%c .0%c", SYM_ALTITUDE, SYM_M); + displayPortTestBufferSubstring(23, 7, "%c0.0%c", SYM_ALTITUDE, SYM_M); // when simulationAltitude = 247; @@ -782,7 +782,7 @@ TEST(OsdTest, TestElementAltitude) osdRefresh(simulationTime); // then - displayPortTestBufferSubstring(23, 7, "%c 2.4%c", SYM_ALTITUDE, SYM_M); + displayPortTestBufferSubstring(23, 7, "%c2.4%c", SYM_ALTITUDE, SYM_M); // when simulationAltitude = 4247; @@ -790,7 +790,7 @@ TEST(OsdTest, TestElementAltitude) osdRefresh(simulationTime); // then - displayPortTestBufferSubstring(23, 7, "%c 42.4%c", SYM_ALTITUDE, SYM_M); + displayPortTestBufferSubstring(23, 7, "%c42.4%c", SYM_ALTITUDE, SYM_M); // when simulationAltitude = -247; @@ -798,7 +798,7 @@ TEST(OsdTest, TestElementAltitude) osdRefresh(simulationTime); // then - displayPortTestBufferSubstring(23, 7, "%c -2.4%c", SYM_ALTITUDE, SYM_M); + displayPortTestBufferSubstring(23, 7, "%c-2.4%c", SYM_ALTITUDE, SYM_M); // when simulationAltitude = -70; @@ -806,7 +806,8 @@ TEST(OsdTest, TestElementAltitude) osdRefresh(simulationTime); // then - displayPortTestBufferSubstring(23, 7, "%c -.7%c", SYM_ALTITUDE, SYM_M); + displayPortTestBufferSubstring(23, 7, "%c-0.7%c", SYM_ALTITUDE, SYM_M); + } /*