@@ -532,13 +532,23 @@ static void osdFormatWindSpeedStr(char *buff, int32_t ws, bool isValid)
532
532
*/
533
533
void osdFormatAltitudeSymbol (char * buff , int32_t alt )
534
534
{
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 ;
540
541
buff [0 ] = ' ' ;
541
542
}
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
+
542
552
switch ((osd_unit_e )osdConfig ()-> units ) {
543
553
case OSD_UNIT_UK :
544
554
FALLTHROUGH ;
@@ -547,25 +557,25 @@ void osdFormatAltitudeSymbol(char *buff, int32_t alt)
547
557
case OSD_UNIT_IMPERIAL :
548
558
if (osdFormatCentiNumber (buff + 4 - digits , CENTIMETERS_TO_CENTIFEET (alt ), 1000 , 0 , 2 , digits )) {
549
559
// Scaled to kft
550
- buff [4 ] = SYM_ALT_KFT ;
560
+ buff [symbolIndex ++ ] = symbolKFt ;
551
561
} else {
552
562
// Formatted in feet
553
- buff [4 ] = SYM_ALT_FT ;
563
+ buff [symbolIndex ++ ] = SYM_ALT_FT ;
554
564
}
555
- buff [5 ] = '\0' ;
565
+ buff [symbolIndex ] = '\0' ;
556
566
break ;
557
567
case OSD_UNIT_METRIC_MPH :
558
568
FALLTHROUGH ;
559
569
case OSD_UNIT_METRIC :
560
570
// alt is alredy in cm
561
571
if (osdFormatCentiNumber (buff + 4 - digits , alt , 1000 , 0 , 2 , digits )) {
562
572
// Scaled to km
563
- buff [4 ] = SYM_ALT_KM ;
573
+ buff [symbolIndex ++ ] = SYM_ALT_KM ;
564
574
} else {
565
575
// Formatted in m
566
- buff [4 ] = SYM_ALT_M ;
576
+ buff [symbolIndex ++ ] = SYM_ALT_M ;
567
577
}
568
- buff [5 ] = '\0' ;
578
+ buff [symbolIndex ] = '\0' ;
569
579
break ;
570
580
}
571
581
}
@@ -2001,18 +2011,7 @@ static bool osdDrawSingleElement(uint8_t item)
2001
2011
case OSD_ALTITUDE :
2002
2012
{
2003
2013
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
2014
2014
osdFormatAltitudeSymbol (buff , alt );
2015
- #endif
2016
2015
2017
2016
uint16_t alt_alarm = osdConfig ()-> alt_alarm ;
2018
2017
uint16_t neg_alt_alarm = osdConfig ()-> neg_alt_alarm ;
@@ -2027,17 +2026,7 @@ static bool osdDrawSingleElement(uint8_t item)
2027
2026
case OSD_ALTITUDE_MSL :
2028
2027
{
2029
2028
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
2039
2029
osdFormatAltitudeSymbol (buff , alt );
2040
- #endif
2041
2030
break ;
2042
2031
}
2043
2032
0 commit comments