Skip to content

Commit 424e55a

Browse files
authored
Merge pull request #7515 from iNavFlight/mrd-add-precision-to-osd-rpm
Added selectable precision to the OSD RPM
2 parents d752e64 + f9d68ce commit 424e55a

4 files changed

Lines changed: 45 additions & 7 deletions

File tree

docs/Settings.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,6 +4082,16 @@ Value above which to make the OSD distance from home indicator blink (meters)
40824082

40834083
---
40844084

4085+
### osd_esc_rpm_precision
4086+
4087+
Number of characters used to display the RPM value.
4088+
4089+
| Default | Min | Max |
4090+
| --- | --- | --- |
4091+
| 3 | 3 | 6 |
4092+
4093+
---
4094+
40854095
### osd_esc_temp_alarm_max
40864096

40874097
Temperature above which the IMU temperature OSD element will start blinking (decidegrees centigrade)

src/main/fc/settings.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3310,7 +3310,6 @@ groups:
33103310
description: "How many navigation waypoints are displayed, set to 0 (zero) to disable. As sample, if set to 2, and you just passed the 3rd waypoint of the mission, you'll see markers for the 4th waypoint (marked 1) and the 5th waypoint (marked 2)"
33113311
default_value: 0
33123312
field: hud_wp_disp
3313-
33143313
min: 0
33153314
max: 3
33163315
- name: osd_left_sidebar_scroll
@@ -3446,6 +3445,13 @@ groups:
34463445
min: -36
34473446
max: 36
34483447

3448+
- name: osd_esc_rpm_precision
3449+
description: Number of characters used to display the RPM value.
3450+
field: esc_rpm_precision
3451+
min: 3
3452+
max: 6
3453+
default_value: 3
3454+
34493455
- name: PG_OSD_COMMON_CONFIG
34503456
type: osdCommonConfig_t
34513457
headers: ["io/osd_common.h"]

src/main/io/osd.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,17 +1037,37 @@ static void osdFormatRpm(char *buff, uint32_t rpm)
10371037
{
10381038
buff[0] = SYM_RPM;
10391039
if (rpm) {
1040-
if (rpm >= 1000) {
1041-
osdFormatCentiNumber(buff + 1, rpm / 10, 0, 1, 1, 2);
1042-
buff[3] = 'K';
1043-
buff[4] = '\0';
1040+
if ( digitCount(rpm) > osdConfig()->esc_rpm_precision) {
1041+
uint8_t rpmMaxDecimals = (osdConfig()->esc_rpm_precision - 3);
1042+
osdFormatCentiNumber(buff + 1, rpm / 10, 0, rpmMaxDecimals, rpmMaxDecimals, osdConfig()->esc_rpm_precision-1);
1043+
buff[osdConfig()->esc_rpm_precision] = 'K';
1044+
buff[osdConfig()->esc_rpm_precision+1] = '\0';
10441045
}
10451046
else {
1046-
tfp_sprintf(buff + 1, "%3lu", rpm);
1047+
switch(osdConfig()->esc_rpm_precision) {
1048+
case 6:
1049+
tfp_sprintf(buff + 1, "%6lu", rpm);
1050+
break;
1051+
case 5:
1052+
tfp_sprintf(buff + 1, "%5lu", rpm);
1053+
break;
1054+
case 4:
1055+
tfp_sprintf(buff + 1, "%4lu", rpm);
1056+
break;
1057+
case 3:
1058+
default:
1059+
tfp_sprintf(buff + 1, "%3lu", rpm);
1060+
break;
1061+
}
1062+
1063+
10471064
}
10481065
}
10491066
else {
1050-
strcpy(buff + 1, "---");
1067+
uint8_t buffPos = 1;
1068+
while (buffPos <=( osdConfig()->esc_rpm_precision)) {
1069+
strcpy(buff + buffPos++, "-");
1070+
}
10511071
}
10521072
}
10531073
#endif
@@ -3148,6 +3168,7 @@ PG_RESET_TEMPLATE(osdConfig_t, osdConfig,
31483168
.osd_home_position_arm_screen = SETTING_OSD_HOME_POSITION_ARM_SCREEN_DEFAULT,
31493169
.pan_servo_index = SETTING_OSD_PAN_SERVO_INDEX_DEFAULT,
31503170
.pan_servo_pwm2centideg = SETTING_OSD_PAN_SERVO_PWM2CENTIDEG_DEFAULT,
3171+
.esc_rpm_precision = SETTING_OSD_ESC_RPM_PRECISION_DEFAULT,
31513172

31523173
.units = SETTING_OSD_UNITS_DEFAULT,
31533174
.main_voltage_decimals = SETTING_OSD_MAIN_VOLTAGE_DECIMALS_DEFAULT,

src/main/io/osd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ typedef struct osdConfig_s {
384384
uint8_t crsf_lq_format;
385385
uint8_t sidebar_height; // sidebar height in rows, 0 turns off sidebars leaving only level indicator arrows
386386
uint8_t telemetry; // use telemetry on displayed pixel line 0
387+
uint8_t esc_rpm_precision; // Number of characters used for the RPM numbers.
387388

388389
} osdConfig_t;
389390

0 commit comments

Comments
 (0)