Skip to content

Commit 5350e2f

Browse files
committed
Fix issue with DJI O3 showing miles instead of kFt
Fixes #9005 Tested on other systems via HITL. All fine. Should be tested by someone with the O3 system for final confirmation.
1 parent 2a696f2 commit 5350e2f

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

src/main/io/osd.c

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,23 @@ static void osdFormatWindSpeedStr(char *buff, int32_t ws, bool isValid)
532532
*/
533533
void osdFormatAltitudeSymbol(char *buff, int32_t alt)
534534
{
535-
int digits;
536-
if (alt < 0) {
537-
digits = 4;
538-
} else {
539-
digits = 3;
535+
uint8_t digits = 4U;
536+
uint8_t symbolIndex = 4U;
537+
uint8_t symbolKFt = SYM_ALT_KFT;
538+
539+
if (alt >= 0) {
540+
digits = 3U;
540541
buff[0] = ' ';
541542
}
543+
544+
#ifndef DISABLE_MSP_BF_COMPAT // IF BFCOMPAT is not supported, there's no need to check for it and change the values
545+
if (isBfCompatibleVideoSystem(osdConfig())) {
546+
digits++;
547+
symbolIndex++;
548+
symbolKFt = SYM_ALT_FT;
549+
}
550+
#endif
551+
542552
switch ((osd_unit_e)osdConfig()->units) {
543553
case OSD_UNIT_UK:
544554
FALLTHROUGH;
@@ -547,25 +557,25 @@ void osdFormatAltitudeSymbol(char *buff, int32_t alt)
547557
case OSD_UNIT_IMPERIAL:
548558
if (osdFormatCentiNumber(buff + 4 - digits, CENTIMETERS_TO_CENTIFEET(alt), 1000, 0, 2, digits)) {
549559
// Scaled to kft
550-
buff[4] = SYM_ALT_KFT;
560+
buff[symbolIndex++] = symbolKFt;
551561
} else {
552562
// Formatted in feet
553-
buff[4] = SYM_ALT_FT;
563+
buff[symbolIndex++] = SYM_ALT_FT;
554564
}
555-
buff[5] = '\0';
565+
buff[symbolIndex] = '\0';
556566
break;
557567
case OSD_UNIT_METRIC_MPH:
558568
FALLTHROUGH;
559569
case OSD_UNIT_METRIC:
560570
// alt is alredy in cm
561571
if (osdFormatCentiNumber(buff + 4 - digits, alt, 1000, 0, 2, digits)) {
562572
// Scaled to km
563-
buff[4] = SYM_ALT_KM;
573+
buff[symbolIndex++] = SYM_ALT_KM;
564574
} else {
565575
// Formatted in m
566-
buff[4] = SYM_ALT_M;
576+
buff[symbolIndex++] = SYM_ALT_M;
567577
}
568-
buff[5] = '\0';
578+
buff[symbolIndex] = '\0';
569579
break;
570580
}
571581
}
@@ -2001,18 +2011,7 @@ static bool osdDrawSingleElement(uint8_t item)
20012011
case OSD_ALTITUDE:
20022012
{
20032013
int32_t alt = osdGetAltitude();
2004-
2005-
#ifndef DISABLE_MSP_BF_COMPAT // IF BFCOMPAT is not supported, there's no need to check for it
2006-
if (isBfCompatibleVideoSystem(osdConfig())) {
2007-
// Use the same formatting function used for distance, which provides the proper scaling functionality
2008-
osdFormatDistanceSymbol(buff, alt, 0);
2009-
} else {
2010-
osdFormatAltitudeSymbol(buff, alt);
2011-
}
2012-
#else
2013-
// BFCOMPAT mode not supported, directly call original altitude formatting function
20142014
osdFormatAltitudeSymbol(buff, alt);
2015-
#endif
20162015

20172016
uint16_t alt_alarm = osdConfig()->alt_alarm;
20182017
uint16_t neg_alt_alarm = osdConfig()->neg_alt_alarm;
@@ -2027,17 +2026,7 @@ static bool osdDrawSingleElement(uint8_t item)
20272026
case OSD_ALTITUDE_MSL:
20282027
{
20292028
int32_t alt = osdGetAltitudeMsl();
2030-
#ifndef DISABLE_MSP_BF_COMPAT // IF BFCOMPAT is not supported, there's no need to check for it
2031-
if (isBfCompatibleVideoSystem(osdConfig())) {
2032-
// Use the same formatting function used for distance, which provides the proper scaling functionality
2033-
osdFormatDistanceSymbol(buff, alt, 0);
2034-
} else {
2035-
osdFormatAltitudeSymbol(buff, alt);
2036-
}
2037-
#else
2038-
// BFCOMPAT mode not supported, directly call original altitude formatting function
20392029
osdFormatAltitudeSymbol(buff, alt);
2040-
#endif
20412030
break;
20422031
}
20432032

0 commit comments

Comments
 (0)