diff --git a/src/main/io/osd.c b/src/main/io/osd.c index d7a24c9ec..c7da460aa 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -700,7 +700,26 @@ static bool osdDrawSingleElement(uint8_t item) break; case OSD_ALTITUDE: - osdFormatAltitudeString(buff, getEstimatedAltitudeCm()); + { + bool haveBaro = false; + bool haveGps = false; +#ifdef USE_BARO + haveBaro = sensors(SENSOR_BARO); +#endif +#ifdef USE_GPS + haveGps = sensors(SENSOR_GPS) && STATE(GPS_FIX); +#endif + if (haveBaro || haveGps) { + osdFormatAltitudeString(buff, getEstimatedAltitudeCm()); + } else { + // We use this symbol when we don't have a valid measure + buff[0] = SYM_COLON; + // overwrite any previous altitude with blanks + memset(buff + 1, SYM_BLANK, 6); + buff[7] = '\0'; + } + } + break; case OSD_ITEM_TIMER_1: @@ -1169,9 +1188,25 @@ static bool osdDrawSingleElement(uint8_t item) #ifdef USE_VARIO case OSD_NUMERICAL_VARIO: { - const int verticalSpeed = osdGetMetersToSelectedUnit(getEstimatedVario()); - const char directionSymbol = verticalSpeed < 0 ? SYM_ARROW_SOUTH : SYM_ARROW_NORTH; - tfp_sprintf(buff, "%c%01d.%01d", directionSymbol, abs(verticalSpeed / 100), abs((verticalSpeed % 100) / 10)); + bool haveBaro = false; + bool haveGps = false; +#ifdef USE_BARO + haveBaro = sensors(SENSOR_BARO); +#endif +#ifdef USE_GPS + haveGps = sensors(SENSOR_GPS) && STATE(GPS_FIX); +#endif + if (haveBaro || haveGps) { + const int verticalSpeed = osdGetMetersToSelectedUnit(getEstimatedVario()); + const char directionSymbol = verticalSpeed < 0 ? SYM_ARROW_SOUTH : SYM_ARROW_NORTH; + tfp_sprintf(buff, "%c%01d.%01d", directionSymbol, abs(verticalSpeed / 100), abs((verticalSpeed % 100) / 10)); + } else { + // We use this symbol when we don't have a valid measure + buff[0] = SYM_COLON; + // overwrite any previous vertical speed with blanks + memset(buff + 1, SYM_BLANK, 6); + buff[7] = '\0'; + } break; } #endif diff --git a/src/test/unit/osd_unittest.cc b/src/test/unit/osd_unittest.cc index 787376c6a..23948be21 100644 --- a/src/test/unit/osd_unittest.cc +++ b/src/test/unit/osd_unittest.cc @@ -464,6 +464,7 @@ TEST(OsdTest, TestAlarms) // given // default state is set setDefaultSimulationState(); + sensorsSet(SENSOR_GPS); // and // the following OSD elements are visible @@ -740,12 +741,21 @@ TEST(OsdTest, TestElementAltitude) // and osdConfigMutable()->units = OSD_UNIT_METRIC; + sensorsClear(SENSOR_GPS); // when simulationAltitude = 0; displayClearScreen(&testDisplayPort); osdRefresh(simulationTime); + // then + displayPortTestBufferSubstring(23, 7, "- "); + + // when + sensorsSet(SENSOR_GPS); + displayClearScreen(&testDisplayPort); + osdRefresh(simulationTime); + // then displayPortTestBufferSubstring(23, 7, " .0%c", SYM_M);