1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 01:35:41 +03:00

Add altitude variant for OSD (#13716)

This commit is contained in:
Mark Haslinghuis 2024-06-26 22:19:06 +02:00 committed by GitHub
parent 2ceb8e0417
commit 0686b74197
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 31 additions and 11 deletions

View file

@ -223,6 +223,13 @@ float getAltitude(void)
return zeroedAltitudeCm; return zeroedAltitudeCm;
} }
#ifdef USE_GPS
float getAltitudeAsl(void)
{
return gpsSol.llh.altCm;
}
#endif
#ifdef USE_VARIO #ifdef USE_VARIO
int16_t getEstimatedVario(void) int16_t getEstimatedVario(void)
{ {

View file

@ -37,4 +37,5 @@ void calculateEstimatedAltitude(void);
void positionInit(void); void positionInit(void);
int32_t getEstimatedAltitudeCm(void); int32_t getEstimatedAltitudeCm(void);
float getAltitude(void); float getAltitude(void);
float getAltitudeAsl(void);
int16_t getEstimatedVario(void); int16_t getEstimatedVario(void);

View file

@ -318,19 +318,26 @@ int osdConvertTemperatureToSelectedUnit(int tempInDegreesCelcius)
static void osdFormatAltitudeString(char * buff, int32_t altitudeCm, osdElementType_e variantType) static void osdFormatAltitudeString(char * buff, int32_t altitudeCm, osdElementType_e variantType)
{ {
const char unitSymbol = osdGetMetersToSelectedUnitSymbol(); static const struct {
unsigned decimalPlaces; uint8_t decimals;
bool asl;
} variantMap[] = {
[OSD_ELEMENT_TYPE_1] = { 1, false },
[OSD_ELEMENT_TYPE_2] = { 0, false },
[OSD_ELEMENT_TYPE_3] = { 1, true },
[OSD_ELEMENT_TYPE_4] = { 0, true },
};
switch (variantType) { int32_t alt = altitudeCm;
case OSD_ELEMENT_TYPE_2: // whole number altitude (no decimal places) #ifdef USE_GPS
decimalPlaces = 0; if (variantMap[variantType].asl) {
break; alt = getAltitudeAsl();
case OSD_ELEMENT_TYPE_1: // one decimal place (default)
default:
decimalPlaces = 1;
break;
} }
osdPrintFloat(buff, SYM_ALTITUDE, osdGetMetersToSelectedUnit(altitudeCm) / 100.0f, "", decimalPlaces, true, unitSymbol); #endif
unsigned decimalPlaces = variantMap[variantType].decimals;
const char unitSymbol = osdGetMetersToSelectedUnitSymbol();
osdPrintFloat(buff, SYM_ALTITUDE, osdGetMetersToSelectedUnit(alt) / 100.0f, "", decimalPlaces, true, unitSymbol);
} }
#ifdef USE_GPS #ifdef USE_GPS

View file

@ -482,6 +482,7 @@ extern "C" {
int32_t getMAhDrawn() { return 0; } int32_t getMAhDrawn() { return 0; }
float getWhDrawn() { return 0.0; } float getWhDrawn() { return 0.0; }
int32_t getEstimatedAltitudeCm() { return 0; } int32_t getEstimatedAltitudeCm() { return 0; }
int32_t getAltitudeAsl() { return 0; }
int32_t getEstimatedVario() { return 0; } int32_t getEstimatedVario() { return 0; }
int32_t blackboxGetLogNumber() { return 0; } int32_t blackboxGetLogNumber() { return 0; }
bool isBlackboxDeviceWorking() { return true; } bool isBlackboxDeviceWorking() { return true; }

View file

@ -1357,6 +1357,10 @@ extern "C" {
return simulationAltitude; return simulationAltitude;
} }
int32_t getAltitudeAsl() {
return simulationAltitude;
}
int32_t getEstimatedVario() { int32_t getEstimatedVario() {
return simulationVerticalSpeed; return simulationVerticalSpeed;
} }