Skip to content

Commit fccc76c

Browse files
authored
Merge pull request #10431 from iNavFlight/MrD_Set-OSD-elements-precision
Allow the pilot to set the precision for altitude and distance in the OSD
2 parents a7854b3 + 5a165de commit fccc76c

File tree

4 files changed

+70
-29
lines changed

4 files changed

+70
-29
lines changed

docs/Settings.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -4582,6 +4582,26 @@ Value above which the OSD current consumption element will start blinking. Measu
45824582

45834583
---
45844584

4585+
### osd_decimals_altitude
4586+
4587+
Number of decimals for the altitude displayed in the OSD [3-5].
4588+
4589+
| Default | Min | Max |
4590+
| --- | --- | --- |
4591+
| 3 | 3 | 5 |
4592+
4593+
---
4594+
4595+
### osd_decimals_distance
4596+
4597+
Number of decimals for distance displayed in the OSD [3-5]. This includes distance from home, total distance, and distance remaining.
4598+
4599+
| Default | Min | Max |
4600+
| --- | --- | --- |
4601+
| 3 | 3 | 5 |
4602+
4603+
---
4604+
45854605
### osd_dist_alarm
45864606

45874607
Value above which to make the OSD distance from home indicator blink (meters)
@@ -4948,7 +4968,7 @@ Number of digits used for mAh precision. Currently used by mAh Used and Battery
49484968

49494969
| Default | Min | Max |
49504970
| --- | --- | --- |
4951-
| 4 | 4 | 6 |
4971+
| 4 | 3 | 6 |
49524972

49534973
---
49544974

src/main/fc/settings.yaml

+16-1
Original file line numberDiff line numberDiff line change
@@ -3566,6 +3566,20 @@ groups:
35663566
field: main_voltage_decimals
35673567
min: 1
35683568
max: 2
3569+
- name: osd_decimals_altitude
3570+
description: "Number of decimals for the altitude displayed in the OSD [3-5]."
3571+
default_value: 3
3572+
field: decimals_altitude
3573+
type: uint8_t
3574+
min: 3
3575+
max: 5
3576+
- name: osd_decimals_distance
3577+
description: "Number of decimals for distance displayed in the OSD [3-5]. This includes distance from home, total distance, and distance remaining."
3578+
default_value: 3
3579+
field: decimals_distance
3580+
type: uint8_t
3581+
min: 3
3582+
max: 5
35693583
- name: osd_coordinate_digits
35703584
description: "Number of digits for the coordinates displayed in the OSD [8-11]."
35713585
field: coordinate_digits
@@ -3719,7 +3733,8 @@ groups:
37193733
- name: osd_mah_precision
37203734
description: Number of digits used for mAh precision. Currently used by mAh Used and Battery Remaining Capacity
37213735
field: mAh_precision
3722-
min: 4
3736+
default: 4
3737+
min: 3
37233738
max: 6
37243739
default_value: 4
37253740
- name: osd_use_pilot_logo

src/main/io/osd.c

+29-25
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static bool osdDisplayHasCanvas;
224224

225225
#define AH_MAX_PITCH_DEFAULT 20 // Specify default maximum AHI pitch value displayed (degrees)
226226

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);
228228
PG_REGISTER_WITH_RESET_FN(osdLayoutsConfig_t, osdLayoutsConfig, PG_OSD_LAYOUTS_CONFIG, 2);
229229

230230
void osdStartedSaveProcess(void) {
@@ -259,10 +259,11 @@ bool osdIsNotMetric(void) {
259259
* prefixed by a a symbol to indicate the unit used.
260260
* @param dist Distance in centimeters
261261
*/
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)
263263
{
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
266267
uint8_t symbol_m = SYM_DIST_M;
267268
uint8_t symbol_km = SYM_DIST_KM;
268269
uint8_t symbol_ft = SYM_DIST_FT;
@@ -485,13 +486,12 @@ static void osdFormatWindSpeedStr(char *buff, int32_t ws, bool isValid)
485486
*/
486487
void osdFormatAltitudeSymbol(char *buff, int32_t alt)
487488
{
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;
491492
uint8_t symbolKFt = SYM_ALT_KFT;
492493

493494
if (alt >= 0) {
494-
digits = 3U;
495495
buff[0] = ' ';
496496
}
497497

@@ -806,7 +806,7 @@ static const char * osdArmingDisabledReasonMessage(void)
806806
case NAV_ARMING_BLOCKER_NAV_IS_ALREADY_ACTIVE:
807807
return OSD_MESSAGE_STR(OSD_MSG_DISABLE_NAV_FIRST);
808808
case NAV_ARMING_BLOCKER_FIRST_WAYPOINT_TOO_FAR:
809-
osdFormatDistanceSymbol(buf, distanceToFirstWP(), 0);
809+
osdFormatDistanceSymbol(buf, distanceToFirstWP(), 0, 3);
810810
tfp_sprintf(messageBuf, "FIRST WP TOO FAR (%s)", buf);
811811
return message = messageBuf;
812812
case NAV_ARMING_BLOCKER_JUMP_WAYPOINT_ERROR:
@@ -1767,7 +1767,7 @@ static bool osdDrawSingleElement(uint8_t item)
17671767
} else
17681768
#endif
17691769
{
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)) {
17711771
// Shown in Ah
17721772
buff[mah_digits] = SYM_AH;
17731773
} else {
@@ -1809,7 +1809,7 @@ static bool osdDrawSingleElement(uint8_t item)
18091809
} else
18101810
#endif
18111811
{
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)) {
18131813
// Shown in Ah
18141814
buff[mah_digits] = SYM_AH;
18151815
} else {
@@ -1966,7 +1966,7 @@ static bool osdDrawSingleElement(uint8_t item)
19661966
{
19671967
buff[0] = SYM_HOME;
19681968
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);
19701970

19711971
uint16_t dist_alarm = osdConfig()->dist_alarm;
19721972
if (dist_alarm > 0 && GPS_distanceToHome > dist_alarm) {
@@ -1977,7 +1977,7 @@ static bool osdDrawSingleElement(uint8_t item)
19771977

19781978
case OSD_TRIP_DIST:
19791979
buff[0] = SYM_TOTAL;
1980-
osdFormatDistanceSymbol(buff + 1, getTotalTravelDistance(), 0);
1980+
osdFormatDistanceSymbol(buff + 1, getTotalTravelDistance(), 0, osdConfig()->decimals_distance);
19811981
break;
19821982

19831983
case OSD_BLACKBOX:
@@ -2096,7 +2096,7 @@ static bool osdDrawSingleElement(uint8_t item)
20962096
{
20972097
if (isWaypointNavTrackingActive()) {
20982098
buff[0] = SYM_CROSS_TRACK_ERROR;
2099-
osdFormatDistanceSymbol(buff + 1, navigationGetCrossTrackError(), 0);
2099+
osdFormatDistanceSymbol(buff + 1, navigationGetCrossTrackError(), 0, 3);
21002100
} else {
21012101
displayWrite(osdDisplayPort, elemPosX, elemPosY, " ");
21022102
return true;
@@ -2255,7 +2255,7 @@ static bool osdDrawSingleElement(uint8_t item)
22552255
buff[1] = '-';
22562256
buff[2] = '-';
22572257
} else {
2258-
osdFormatDistanceSymbol(buff, range, 1);
2258+
osdFormatDistanceSymbol(buff, range, 1, 3);
22592259
}
22602260
}
22612261
break;
@@ -2337,31 +2337,33 @@ static bool osdDrawSingleElement(uint8_t item)
23372337
displayWriteChar(osdDisplayPort, elemPosX, elemPosY, SYM_FLIGHT_DIST_REMAINING);
23382338

23392339
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';
23422342
strcpy(buff, "---");
23432343
} else if (distanceMeters == -2) {
23442344
// 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+
}
23462348
switch ((osd_unit_e)osdConfig()->units){
23472349
case OSD_UNIT_UK:
23482350
FALLTHROUGH;
23492351
case OSD_UNIT_IMPERIAL:
2350-
buff[3] = SYM_DIST_MI;
2352+
buff[osdConfig()->decimals_distance] = SYM_DIST_MI;
23512353
break;
23522354
case OSD_UNIT_METRIC_MPH:
23532355
FALLTHROUGH;
23542356
case OSD_UNIT_METRIC:
2355-
buff[3] = SYM_DIST_KM;
2357+
buff[osdConfig()->decimals_distance] = SYM_DIST_KM;
23562358
break;
23572359
case OSD_UNIT_GA:
2358-
buff[3] = SYM_DIST_NM;
2360+
buff[osdConfig()->decimals_distance] = SYM_DIST_NM;
23592361
break;
23602362
}
2361-
buff[4] = '\0';
2363+
buff[osdConfig()->decimals_distance+1] = '\0';
23622364
TEXT_ATTRIBUTES_ADD_BLINK(elemAttr);
23632365
} else {
2364-
osdFormatDistanceSymbol(buff, distanceMeters * 100, 0);
2366+
osdFormatDistanceSymbol(buff, distanceMeters * 100, 0, osdConfig()->decimals_distance);
23652367
if (distanceMeters == 0)
23662368
TEXT_ATTRIBUTES_ADD_BLINK(elemAttr);
23672369
}
@@ -2903,7 +2905,7 @@ static bool osdDrawSingleElement(uint8_t item)
29032905
buff[0] = SYM_GLIDE_DIST;
29042906
if (glideSeconds > 0) {
29052907
uint32_t glideRangeCM = glideSeconds * gpsSol.groundSpeed;
2906-
osdFormatDistanceSymbol(buff + 1, glideRangeCM, 0);
2908+
osdFormatDistanceSymbol(buff + 1, glideRangeCM, 0, 3);
29072909
} else {
29082910
tfp_sprintf(buff + 1, "%s%c", "---", SYM_BLANK);
29092911
buff[5] = '\0';
@@ -4058,6 +4060,8 @@ PG_RESET_TEMPLATE(osdConfig_t, osdConfig,
40584060
.system_msg_display_time = SETTING_OSD_SYSTEM_MSG_DISPLAY_TIME_DEFAULT,
40594061
.units = SETTING_OSD_UNITS_DEFAULT,
40604062
.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,
40614065
.use_pilot_logo = SETTING_OSD_USE_PILOT_LOGO_DEFAULT,
40624066
.inav_to_pilot_logo_spacing = SETTING_OSD_INAV_TO_PILOT_LOGO_SPACING_DEFAULT,
40634067
.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
58575861
} else if (NAV_Status.state == MW_NAV_STATE_WP_ENROUTE) {
58585862
// Countdown display for remaining Waypoints
58595863
char buf[6];
5860-
osdFormatDistanceSymbol(buf, posControl.wpDistance, 0);
5864+
osdFormatDistanceSymbol(buf, posControl.wpDistance, 0, 3);
58615865
tfp_sprintf(messageBuf, "TO WP %u/%u (%s)", getGeoWaypointNumber(posControl.activeWaypointIndex), posControl.geoWaypointCount, buf);
58625866
messages[messageCount++] = messageBuf;
58635867
} else if (NAV_Status.state == MW_NAV_STATE_HOLD_TIMED) {

src/main/io/osd.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ typedef struct osdConfig_s {
394394

395395
// Preferences
396396
uint8_t main_voltage_decimals;
397+
uint8_t decimals_altitude;
398+
uint8_t decimals_distance;
397399
uint8_t ahi_reverse_roll;
398400
uint8_t ahi_max_pitch;
399401
uint8_t crosshairs_style; // from osd_crosshairs_style_e
@@ -466,11 +468,11 @@ typedef struct osdConfig_s {
466468
#ifndef DISABLE_MSP_DJI_COMPAT
467469
bool highlight_djis_missing_characters; // If enabled, show question marks where there is no character in DJI's font to represent an OSD element symbol
468470
#endif
469-
#ifdef USE_ADSB
471+
#ifdef USE_ADSB
470472
uint16_t adsb_distance_warning; // in metres
471473
uint16_t adsb_distance_alert; // in metres
472474
uint16_t adsb_ignore_plane_above_me_limit; // in metres
473-
#endif
475+
#endif
474476
uint8_t radar_peers_display_time; // in seconds
475477
} osdConfig_t;
476478

0 commit comments

Comments
 (0)