From 16746b89dc67d7a12cb1ae4cce9f861507513aea Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Fri, 25 Oct 2024 12:54:40 +0100 Subject: [PATCH 1/2] Allow setting of altitude and distance precision --- docs/Settings.md | 22 ++++++++++++++++- src/main/fc/settings.yaml | 17 ++++++++++++- src/main/io/osd.c | 50 +++++++++++++++++++++------------------ src/main/io/osd.h | 6 +++-- 4 files changed, 68 insertions(+), 27 deletions(-) diff --git a/docs/Settings.md b/docs/Settings.md index ae0d3006ae6..ce4ff9c1ce4 100644 --- a/docs/Settings.md +++ b/docs/Settings.md @@ -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) @@ -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 | --- diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index e43ad233b0c..a6e97e3811e 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -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 @@ -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 diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 1b88226b9cb..7174f0dfb7d 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -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) { @@ -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; @@ -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] = ' '; } @@ -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: @@ -1952,7 +1952,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) { @@ -1963,7 +1963,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: @@ -2082,7 +2082,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; @@ -2241,7 +2241,7 @@ static bool osdDrawSingleElement(uint8_t item) buff[1] = '-'; buff[2] = '-'; } else { - osdFormatDistanceSymbol(buff, range, 1); + osdFormatDistanceSymbol(buff, range, 1, 3); } } break; @@ -2323,31 +2323,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); } @@ -2889,7 +2891,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'; @@ -4044,6 +4046,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, @@ -5779,7 +5783,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) { diff --git a/src/main/io/osd.h b/src/main/io/osd.h index 0cf93b69162..b0423d40eff 100644 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -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 @@ -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; From 5a165dee9a3eb972e921aa6ae16f72c82089e874 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Fri, 25 Oct 2024 21:24:57 +0100 Subject: [PATCH 2/2] Fix decimal places for mAh --- src/main/io/osd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 3ebd71f11b8..95fef520b7a 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -1753,7 +1753,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 { @@ -1795,7 +1795,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 {