Skip to content

Commit

Permalink
Merge pull request #10431 from iNavFlight/MrD_Set-OSD-elements-precision
Browse files Browse the repository at this point in the history
Allow the pilot to set the precision for altitude and distance in the OSD
  • Loading branch information
MrD-RC authored Oct 28, 2024
2 parents a7854b3 + 5a165de commit fccc76c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 29 deletions.
22 changes: 21 additions & 1 deletion docs/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -4582,6 +4582,26 @@ Value above which the OSD current consumption element will start blinking. Measu

---

### osd_decimals_altitude

Number of decimals for the altitude displayed in the OSD [3-5].

| Default | Min | Max |
| --- | --- | --- |
| 3 | 3 | 5 |

---

### osd_decimals_distance

Number of decimals for distance displayed in the OSD [3-5]. This includes distance from home, total distance, and distance remaining.

| Default | Min | Max |
| --- | --- | --- |
| 3 | 3 | 5 |

---

### osd_dist_alarm

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

| Default | Min | Max |
| --- | --- | --- |
| 4 | 4 | 6 |
| 4 | 3 | 6 |

---

Expand Down
17 changes: 16 additions & 1 deletion src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3566,6 +3566,20 @@ groups:
field: main_voltage_decimals
min: 1
max: 2
- name: osd_decimals_altitude
description: "Number of decimals for the altitude displayed in the OSD [3-5]."
default_value: 3
field: decimals_altitude
type: uint8_t
min: 3
max: 5
- name: osd_decimals_distance
description: "Number of decimals for distance displayed in the OSD [3-5]. This includes distance from home, total distance, and distance remaining."
default_value: 3
field: decimals_distance
type: uint8_t
min: 3
max: 5
- name: osd_coordinate_digits
description: "Number of digits for the coordinates displayed in the OSD [8-11]."
field: coordinate_digits
Expand Down Expand Up @@ -3719,7 +3733,8 @@ groups:
- name: osd_mah_precision
description: Number of digits used for mAh precision. Currently used by mAh Used and Battery Remaining Capacity
field: mAh_precision
min: 4
default: 4
min: 3
max: 6
default_value: 4
- name: osd_use_pilot_logo
Expand Down
54 changes: 29 additions & 25 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static bool osdDisplayHasCanvas;

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

PG_REGISTER_WITH_RESET_TEMPLATE(osdConfig_t, osdConfig, PG_OSD_CONFIG, 12);
PG_REGISTER_WITH_RESET_TEMPLATE(osdConfig_t, osdConfig, PG_OSD_CONFIG, 13);
PG_REGISTER_WITH_RESET_FN(osdLayoutsConfig_t, osdLayoutsConfig, PG_OSD_LAYOUTS_CONFIG, 2);

void osdStartedSaveProcess(void) {
Expand Down Expand Up @@ -259,10 +259,11 @@ bool osdIsNotMetric(void) {
* prefixed by a a symbol to indicate the unit used.
* @param dist Distance in centimeters
*/
static void osdFormatDistanceSymbol(char *buff, int32_t dist, uint8_t decimals)
static void osdFormatDistanceSymbol(char *buff, int32_t dist, uint8_t decimals, uint8_t digits)
{
uint8_t digits = 3U; // Total number of digits (including decimal point)
uint8_t sym_index = 3U; // Position (index) at buffer of units symbol
if (digits == 0) // Total number of digits (including decimal point)
digits = 3U;
uint8_t sym_index = digits; // Position (index) at buffer of units symbol
uint8_t symbol_m = SYM_DIST_M;
uint8_t symbol_km = SYM_DIST_KM;
uint8_t symbol_ft = SYM_DIST_FT;
Expand Down Expand Up @@ -485,13 +486,12 @@ static void osdFormatWindSpeedStr(char *buff, int32_t ws, bool isValid)
*/
void osdFormatAltitudeSymbol(char *buff, int32_t alt)
{
uint8_t totalDigits = 4U;
uint8_t digits = 4U;
uint8_t symbolIndex = 4U;
uint8_t digits = osdConfig()->decimals_altitude;
uint8_t totalDigits = digits + 1;
uint8_t symbolIndex = digits + 1;
uint8_t symbolKFt = SYM_ALT_KFT;

if (alt >= 0) {
digits = 3U;
buff[0] = ' ';
}

Expand Down Expand Up @@ -806,7 +806,7 @@ static const char * osdArmingDisabledReasonMessage(void)
case NAV_ARMING_BLOCKER_NAV_IS_ALREADY_ACTIVE:
return OSD_MESSAGE_STR(OSD_MSG_DISABLE_NAV_FIRST);
case NAV_ARMING_BLOCKER_FIRST_WAYPOINT_TOO_FAR:
osdFormatDistanceSymbol(buf, distanceToFirstWP(), 0);
osdFormatDistanceSymbol(buf, distanceToFirstWP(), 0, 3);
tfp_sprintf(messageBuf, "FIRST WP TOO FAR (%s)", buf);
return message = messageBuf;
case NAV_ARMING_BLOCKER_JUMP_WAYPOINT_ERROR:
Expand Down Expand Up @@ -1767,7 +1767,7 @@ static bool osdDrawSingleElement(uint8_t item)
} else
#endif
{
if (osdFormatCentiNumber(buff, getMAhDrawn() * 100, 1000, 0, (mah_digits - 2), mah_digits, false)) {
if (osdFormatCentiNumber(buff, getMAhDrawn() * 100, 1000, 0, 2, mah_digits, false)) {
// Shown in Ah
buff[mah_digits] = SYM_AH;
} else {
Expand Down Expand Up @@ -1809,7 +1809,7 @@ static bool osdDrawSingleElement(uint8_t item)
} else
#endif
{
if (osdFormatCentiNumber(buff, getBatteryRemainingCapacity() * 100, 1000, 0, (mah_digits - 2), mah_digits, false)) {
if (osdFormatCentiNumber(buff, getBatteryRemainingCapacity() * 100, 1000, 0, 2, mah_digits, false)) {
// Shown in Ah
buff[mah_digits] = SYM_AH;
} else {
Expand Down Expand Up @@ -1966,7 +1966,7 @@ static bool osdDrawSingleElement(uint8_t item)
{
buff[0] = SYM_HOME;
uint32_t distance_to_home_cm = GPS_distanceToHome * 100;
osdFormatDistanceSymbol(&buff[1], distance_to_home_cm, 0);
osdFormatDistanceSymbol(&buff[1], distance_to_home_cm, 0, osdConfig()->decimals_distance);

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

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

case OSD_BLACKBOX:
Expand Down Expand Up @@ -2096,7 +2096,7 @@ static bool osdDrawSingleElement(uint8_t item)
{
if (isWaypointNavTrackingActive()) {
buff[0] = SYM_CROSS_TRACK_ERROR;
osdFormatDistanceSymbol(buff + 1, navigationGetCrossTrackError(), 0);
osdFormatDistanceSymbol(buff + 1, navigationGetCrossTrackError(), 0, 3);
} else {
displayWrite(osdDisplayPort, elemPosX, elemPosY, " ");
return true;
Expand Down Expand Up @@ -2255,7 +2255,7 @@ static bool osdDrawSingleElement(uint8_t item)
buff[1] = '-';
buff[2] = '-';
} else {
osdFormatDistanceSymbol(buff, range, 1);
osdFormatDistanceSymbol(buff, range, 1, 3);
}
}
break;
Expand Down Expand Up @@ -2337,31 +2337,33 @@ static bool osdDrawSingleElement(uint8_t item)
displayWriteChar(osdDisplayPort, elemPosX, elemPosY, SYM_FLIGHT_DIST_REMAINING);

if ((!ARMING_FLAG(ARMED)) || (distanceMeters == -1)) {
buff[3] = SYM_BLANK;
buff[4] = '\0';
buff[osdConfig()->decimals_distance] = SYM_BLANK;
buff[osdConfig()->decimals_distance + 1] = '\0';
strcpy(buff, "---");
} else if (distanceMeters == -2) {
// Wind is too strong to come back with cruise throttle
buff[0] = buff[1] = buff[2] = SYM_WIND_HORIZONTAL;
for (uint8_t i = 0; i < osdConfig()->decimals_distance; i++) {
buff[i] = SYM_WIND_HORIZONTAL;
}
switch ((osd_unit_e)osdConfig()->units){
case OSD_UNIT_UK:
FALLTHROUGH;
case OSD_UNIT_IMPERIAL:
buff[3] = SYM_DIST_MI;
buff[osdConfig()->decimals_distance] = SYM_DIST_MI;
break;
case OSD_UNIT_METRIC_MPH:
FALLTHROUGH;
case OSD_UNIT_METRIC:
buff[3] = SYM_DIST_KM;
buff[osdConfig()->decimals_distance] = SYM_DIST_KM;
break;
case OSD_UNIT_GA:
buff[3] = SYM_DIST_NM;
buff[osdConfig()->decimals_distance] = SYM_DIST_NM;
break;
}
buff[4] = '\0';
buff[osdConfig()->decimals_distance+1] = '\0';
TEXT_ATTRIBUTES_ADD_BLINK(elemAttr);
} else {
osdFormatDistanceSymbol(buff, distanceMeters * 100, 0);
osdFormatDistanceSymbol(buff, distanceMeters * 100, 0, osdConfig()->decimals_distance);
if (distanceMeters == 0)
TEXT_ATTRIBUTES_ADD_BLINK(elemAttr);
}
Expand Down Expand Up @@ -2903,7 +2905,7 @@ static bool osdDrawSingleElement(uint8_t item)
buff[0] = SYM_GLIDE_DIST;
if (glideSeconds > 0) {
uint32_t glideRangeCM = glideSeconds * gpsSol.groundSpeed;
osdFormatDistanceSymbol(buff + 1, glideRangeCM, 0);
osdFormatDistanceSymbol(buff + 1, glideRangeCM, 0, 3);
} else {
tfp_sprintf(buff + 1, "%s%c", "---", SYM_BLANK);
buff[5] = '\0';
Expand Down Expand Up @@ -4058,6 +4060,8 @@ PG_RESET_TEMPLATE(osdConfig_t, osdConfig,
.system_msg_display_time = SETTING_OSD_SYSTEM_MSG_DISPLAY_TIME_DEFAULT,
.units = SETTING_OSD_UNITS_DEFAULT,
.main_voltage_decimals = SETTING_OSD_MAIN_VOLTAGE_DECIMALS_DEFAULT,
.decimals_altitude = SETTING_OSD_DECIMALS_ALTITUDE_DEFAULT,
.decimals_distance = SETTING_OSD_DECIMALS_DISTANCE_DEFAULT,
.use_pilot_logo = SETTING_OSD_USE_PILOT_LOGO_DEFAULT,
.inav_to_pilot_logo_spacing = SETTING_OSD_INAV_TO_PILOT_LOGO_SPACING_DEFAULT,
.arm_screen_display_time = SETTING_OSD_ARM_SCREEN_DISPLAY_TIME_DEFAULT,
Expand Down Expand Up @@ -5857,7 +5861,7 @@ textAttributes_t osdGetSystemMessage(char *buff, size_t buff_size, bool isCenter
} else if (NAV_Status.state == MW_NAV_STATE_WP_ENROUTE) {
// Countdown display for remaining Waypoints
char buf[6];
osdFormatDistanceSymbol(buf, posControl.wpDistance, 0);
osdFormatDistanceSymbol(buf, posControl.wpDistance, 0, 3);
tfp_sprintf(messageBuf, "TO WP %u/%u (%s)", getGeoWaypointNumber(posControl.activeWaypointIndex), posControl.geoWaypointCount, buf);
messages[messageCount++] = messageBuf;
} else if (NAV_Status.state == MW_NAV_STATE_HOLD_TIMED) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/io/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ typedef struct osdConfig_s {

// Preferences
uint8_t main_voltage_decimals;
uint8_t decimals_altitude;
uint8_t decimals_distance;
uint8_t ahi_reverse_roll;
uint8_t ahi_max_pitch;
uint8_t crosshairs_style; // from osd_crosshairs_style_e
Expand Down Expand Up @@ -466,11 +468,11 @@ typedef struct osdConfig_s {
#ifndef DISABLE_MSP_DJI_COMPAT
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
#endif
#ifdef USE_ADSB
#ifdef USE_ADSB
uint16_t adsb_distance_warning; // in metres
uint16_t adsb_distance_alert; // in metres
uint16_t adsb_ignore_plane_above_me_limit; // in metres
#endif
#endif
uint8_t radar_peers_display_time; // in seconds
} osdConfig_t;

Expand Down

0 comments on commit fccc76c

Please sign in to comment.