@@ -224,7 +224,7 @@ static bool osdDisplayHasCanvas;
224
224
225
225
#define AH_MAX_PITCH_DEFAULT 20 // Specify default maximum AHI pitch value displayed (degrees)
226
226
227
- PG_REGISTER_WITH_RESET_TEMPLATE (osdConfig_t , osdConfig , PG_OSD_CONFIG , 12 );
227
+ PG_REGISTER_WITH_RESET_TEMPLATE (osdConfig_t , osdConfig , PG_OSD_CONFIG , 13 );
228
228
PG_REGISTER_WITH_RESET_FN (osdLayoutsConfig_t , osdLayoutsConfig , PG_OSD_LAYOUTS_CONFIG , 2 );
229
229
230
230
void osdStartedSaveProcess (void ) {
@@ -259,10 +259,11 @@ bool osdIsNotMetric(void) {
259
259
* prefixed by a a symbol to indicate the unit used.
260
260
* @param dist Distance in centimeters
261
261
*/
262
- static void osdFormatDistanceSymbol (char * buff , int32_t dist , uint8_t decimals )
262
+ static void osdFormatDistanceSymbol (char * buff , int32_t dist , uint8_t decimals , uint8_t digits )
263
263
{
264
- uint8_t digits = 3U ; // Total number of digits (including decimal point)
265
- uint8_t sym_index = 3U ; // Position (index) at buffer of units symbol
264
+ if (digits == 0 ) // Total number of digits (including decimal point)
265
+ digits = 3U ;
266
+ uint8_t sym_index = digits ; // Position (index) at buffer of units symbol
266
267
uint8_t symbol_m = SYM_DIST_M ;
267
268
uint8_t symbol_km = SYM_DIST_KM ;
268
269
uint8_t symbol_ft = SYM_DIST_FT ;
@@ -485,13 +486,12 @@ static void osdFormatWindSpeedStr(char *buff, int32_t ws, bool isValid)
485
486
*/
486
487
void osdFormatAltitudeSymbol (char * buff , int32_t alt )
487
488
{
488
- uint8_t totalDigits = 4U ;
489
- uint8_t digits = 4U ;
490
- uint8_t symbolIndex = 4U ;
489
+ uint8_t digits = osdConfig () -> decimals_altitude ;
490
+ uint8_t totalDigits = digits + 1 ;
491
+ uint8_t symbolIndex = digits + 1 ;
491
492
uint8_t symbolKFt = SYM_ALT_KFT ;
492
493
493
494
if (alt >= 0 ) {
494
- digits = 3U ;
495
495
buff [0 ] = ' ' ;
496
496
}
497
497
@@ -806,7 +806,7 @@ static const char * osdArmingDisabledReasonMessage(void)
806
806
case NAV_ARMING_BLOCKER_NAV_IS_ALREADY_ACTIVE :
807
807
return OSD_MESSAGE_STR (OSD_MSG_DISABLE_NAV_FIRST );
808
808
case NAV_ARMING_BLOCKER_FIRST_WAYPOINT_TOO_FAR :
809
- osdFormatDistanceSymbol (buf , distanceToFirstWP (), 0 );
809
+ osdFormatDistanceSymbol (buf , distanceToFirstWP (), 0 , 3 );
810
810
tfp_sprintf (messageBuf , "FIRST WP TOO FAR (%s)" , buf );
811
811
return message = messageBuf ;
812
812
case NAV_ARMING_BLOCKER_JUMP_WAYPOINT_ERROR :
@@ -1767,7 +1767,7 @@ static bool osdDrawSingleElement(uint8_t item)
1767
1767
} else
1768
1768
#endif
1769
1769
{
1770
- if (osdFormatCentiNumber (buff , getMAhDrawn () * 100 , 1000 , 0 , ( mah_digits - 2 ) , mah_digits , false)) {
1770
+ if (osdFormatCentiNumber (buff , getMAhDrawn () * 100 , 1000 , 0 , 2 , mah_digits , false)) {
1771
1771
// Shown in Ah
1772
1772
buff [mah_digits ] = SYM_AH ;
1773
1773
} else {
@@ -1809,7 +1809,7 @@ static bool osdDrawSingleElement(uint8_t item)
1809
1809
} else
1810
1810
#endif
1811
1811
{
1812
- if (osdFormatCentiNumber (buff , getBatteryRemainingCapacity () * 100 , 1000 , 0 , ( mah_digits - 2 ) , mah_digits , false)) {
1812
+ if (osdFormatCentiNumber (buff , getBatteryRemainingCapacity () * 100 , 1000 , 0 , 2 , mah_digits , false)) {
1813
1813
// Shown in Ah
1814
1814
buff [mah_digits ] = SYM_AH ;
1815
1815
} else {
@@ -1966,7 +1966,7 @@ static bool osdDrawSingleElement(uint8_t item)
1966
1966
{
1967
1967
buff [0 ] = SYM_HOME ;
1968
1968
uint32_t distance_to_home_cm = GPS_distanceToHome * 100 ;
1969
- osdFormatDistanceSymbol (& buff [1 ], distance_to_home_cm , 0 );
1969
+ osdFormatDistanceSymbol (& buff [1 ], distance_to_home_cm , 0 , osdConfig () -> decimals_distance );
1970
1970
1971
1971
uint16_t dist_alarm = osdConfig ()-> dist_alarm ;
1972
1972
if (dist_alarm > 0 && GPS_distanceToHome > dist_alarm ) {
@@ -1977,7 +1977,7 @@ static bool osdDrawSingleElement(uint8_t item)
1977
1977
1978
1978
case OSD_TRIP_DIST :
1979
1979
buff [0 ] = SYM_TOTAL ;
1980
- osdFormatDistanceSymbol (buff + 1 , getTotalTravelDistance (), 0 );
1980
+ osdFormatDistanceSymbol (buff + 1 , getTotalTravelDistance (), 0 , osdConfig () -> decimals_distance );
1981
1981
break ;
1982
1982
1983
1983
case OSD_BLACKBOX :
@@ -2096,7 +2096,7 @@ static bool osdDrawSingleElement(uint8_t item)
2096
2096
{
2097
2097
if (isWaypointNavTrackingActive ()) {
2098
2098
buff [0 ] = SYM_CROSS_TRACK_ERROR ;
2099
- osdFormatDistanceSymbol (buff + 1 , navigationGetCrossTrackError (), 0 );
2099
+ osdFormatDistanceSymbol (buff + 1 , navigationGetCrossTrackError (), 0 , 3 );
2100
2100
} else {
2101
2101
displayWrite (osdDisplayPort , elemPosX , elemPosY , " " );
2102
2102
return true;
@@ -2255,7 +2255,7 @@ static bool osdDrawSingleElement(uint8_t item)
2255
2255
buff [1 ] = '-' ;
2256
2256
buff [2 ] = '-' ;
2257
2257
} else {
2258
- osdFormatDistanceSymbol (buff , range , 1 );
2258
+ osdFormatDistanceSymbol (buff , range , 1 , 3 );
2259
2259
}
2260
2260
}
2261
2261
break ;
@@ -2337,31 +2337,33 @@ static bool osdDrawSingleElement(uint8_t item)
2337
2337
displayWriteChar (osdDisplayPort , elemPosX , elemPosY , SYM_FLIGHT_DIST_REMAINING );
2338
2338
2339
2339
if ((!ARMING_FLAG (ARMED )) || (distanceMeters == -1 )) {
2340
- buff [3 ] = SYM_BLANK ;
2341
- buff [4 ] = '\0' ;
2340
+ buff [osdConfig () -> decimals_distance ] = SYM_BLANK ;
2341
+ buff [osdConfig () -> decimals_distance + 1 ] = '\0' ;
2342
2342
strcpy (buff , "---" );
2343
2343
} else if (distanceMeters == -2 ) {
2344
2344
// Wind is too strong to come back with cruise throttle
2345
- buff [0 ] = buff [1 ] = buff [2 ] = SYM_WIND_HORIZONTAL ;
2345
+ for (uint8_t i = 0 ; i < osdConfig ()-> decimals_distance ; i ++ ) {
2346
+ buff [i ] = SYM_WIND_HORIZONTAL ;
2347
+ }
2346
2348
switch ((osd_unit_e )osdConfig ()-> units ){
2347
2349
case OSD_UNIT_UK :
2348
2350
FALLTHROUGH ;
2349
2351
case OSD_UNIT_IMPERIAL :
2350
- buff [3 ] = SYM_DIST_MI ;
2352
+ buff [osdConfig () -> decimals_distance ] = SYM_DIST_MI ;
2351
2353
break ;
2352
2354
case OSD_UNIT_METRIC_MPH :
2353
2355
FALLTHROUGH ;
2354
2356
case OSD_UNIT_METRIC :
2355
- buff [3 ] = SYM_DIST_KM ;
2357
+ buff [osdConfig () -> decimals_distance ] = SYM_DIST_KM ;
2356
2358
break ;
2357
2359
case OSD_UNIT_GA :
2358
- buff [3 ] = SYM_DIST_NM ;
2360
+ buff [osdConfig () -> decimals_distance ] = SYM_DIST_NM ;
2359
2361
break ;
2360
2362
}
2361
- buff [4 ] = '\0' ;
2363
+ buff [osdConfig () -> decimals_distance + 1 ] = '\0' ;
2362
2364
TEXT_ATTRIBUTES_ADD_BLINK (elemAttr );
2363
2365
} else {
2364
- osdFormatDistanceSymbol (buff , distanceMeters * 100 , 0 );
2366
+ osdFormatDistanceSymbol (buff , distanceMeters * 100 , 0 , osdConfig () -> decimals_distance );
2365
2367
if (distanceMeters == 0 )
2366
2368
TEXT_ATTRIBUTES_ADD_BLINK (elemAttr );
2367
2369
}
@@ -2903,7 +2905,7 @@ static bool osdDrawSingleElement(uint8_t item)
2903
2905
buff [0 ] = SYM_GLIDE_DIST ;
2904
2906
if (glideSeconds > 0 ) {
2905
2907
uint32_t glideRangeCM = glideSeconds * gpsSol .groundSpeed ;
2906
- osdFormatDistanceSymbol (buff + 1 , glideRangeCM , 0 );
2908
+ osdFormatDistanceSymbol (buff + 1 , glideRangeCM , 0 , 3 );
2907
2909
} else {
2908
2910
tfp_sprintf (buff + 1 , "%s%c" , "---" , SYM_BLANK );
2909
2911
buff [5 ] = '\0' ;
@@ -4058,6 +4060,8 @@ PG_RESET_TEMPLATE(osdConfig_t, osdConfig,
4058
4060
.system_msg_display_time = SETTING_OSD_SYSTEM_MSG_DISPLAY_TIME_DEFAULT ,
4059
4061
.units = SETTING_OSD_UNITS_DEFAULT ,
4060
4062
.main_voltage_decimals = SETTING_OSD_MAIN_VOLTAGE_DECIMALS_DEFAULT ,
4063
+ .decimals_altitude = SETTING_OSD_DECIMALS_ALTITUDE_DEFAULT ,
4064
+ .decimals_distance = SETTING_OSD_DECIMALS_DISTANCE_DEFAULT ,
4061
4065
.use_pilot_logo = SETTING_OSD_USE_PILOT_LOGO_DEFAULT ,
4062
4066
.inav_to_pilot_logo_spacing = SETTING_OSD_INAV_TO_PILOT_LOGO_SPACING_DEFAULT ,
4063
4067
.arm_screen_display_time = SETTING_OSD_ARM_SCREEN_DISPLAY_TIME_DEFAULT ,
@@ -5857,7 +5861,7 @@ textAttributes_t osdGetSystemMessage(char *buff, size_t buff_size, bool isCenter
5857
5861
} else if (NAV_Status .state == MW_NAV_STATE_WP_ENROUTE ) {
5858
5862
// Countdown display for remaining Waypoints
5859
5863
char buf [6 ];
5860
- osdFormatDistanceSymbol (buf , posControl .wpDistance , 0 );
5864
+ osdFormatDistanceSymbol (buf , posControl .wpDistance , 0 , 3 );
5861
5865
tfp_sprintf (messageBuf , "TO WP %u/%u (%s)" , getGeoWaypointNumber (posControl .activeWaypointIndex ), posControl .geoWaypointCount , buf );
5862
5866
messages [messageCount ++ ] = messageBuf ;
5863
5867
} else if (NAV_Status .state == MW_NAV_STATE_HOLD_TIMED ) {
0 commit comments