mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 12:25:20 +03:00
Add OSD element variants for altitude
Variant 1 (default): Altitude displays with one decimal place. No change in behavior. Variant 2: Altitude displays as whole number (no decimal) so it will represent meters or feet depending on the units selected.
This commit is contained in:
parent
aeb2a4f381
commit
9b66ef31eb
1 changed files with 17 additions and 8 deletions
|
@ -259,16 +259,25 @@ int osdConvertTemperatureToSelectedUnit(int tempInDegreesCelcius)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void osdFormatAltitudeString(char * buff, int32_t altitudeCm)
|
||||
static void osdFormatAltitudeString(char * buff, int32_t altitudeCm, osdElementType_e variantType)
|
||||
{
|
||||
const int alt = osdGetMetersToSelectedUnit(altitudeCm) / 10;
|
||||
const int alt = ABS(osdGetMetersToSelectedUnit(altitudeCm) / 10);
|
||||
const char unitSymbol = osdGetMetersToSelectedUnitSymbol();
|
||||
|
||||
int pos = 0;
|
||||
buff[pos++] = SYM_ALTITUDE;
|
||||
if (alt < 0) {
|
||||
buff[pos++] = '-';
|
||||
*buff++ = SYM_ALTITUDE;
|
||||
if (altitudeCm < 0) {
|
||||
*buff++ = '-';
|
||||
}
|
||||
|
||||
switch (variantType) {
|
||||
case OSD_ELEMENT_TYPE_2: // whole number altitude (no decimal places)
|
||||
tfp_sprintf(buff, "%d%c", alt / 10, unitSymbol);
|
||||
break;
|
||||
case OSD_ELEMENT_TYPE_1: // one decimal place (default)
|
||||
default:
|
||||
tfp_sprintf(buff, "%01d.%01d%c", alt / 10 , alt % 10, unitSymbol);
|
||||
break;
|
||||
}
|
||||
tfp_sprintf(buff + pos, "%01d.%01d%c", abs(alt) / 10 , abs(alt) % 10, osdGetMetersToSelectedUnitSymbol());
|
||||
}
|
||||
|
||||
#ifdef USE_GPS
|
||||
|
@ -558,7 +567,7 @@ static void osdElementAltitude(osdElementParms_t *element)
|
|||
haveGps = sensors(SENSOR_GPS) && STATE(GPS_FIX);
|
||||
#endif // USE_GPS
|
||||
if (haveBaro || haveGps) {
|
||||
osdFormatAltitudeString(element->buff, getEstimatedAltitudeCm());
|
||||
osdFormatAltitudeString(element->buff, getEstimatedAltitudeCm(), element->type);
|
||||
} else {
|
||||
element->buff[0] = SYM_ALTITUDE;
|
||||
element->buff[1] = SYM_HYPHEN; // We use this symbol when we don't have a valid measure
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue