Skip to content

Commit f9d68ce

Browse files
committed
Added selectable precision to the OSD RPM
I've added selectable precision to the ESC RPM, as shown in the OSD. The default is 3, which is the same as the current RPM display.
1 parent 430a194 commit f9d68ce

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
@@ -4122,6 +4122,16 @@ Value above which to make the OSD distance from home indicator blink (meters)
41224122

41234123
---
41244124

4125+
### osd_esc_rpm_precision
4126+
4127+
Number of characters used to display the RPM value.
4128+
4129+
| Default | Min | Max |
4130+
| --- | --- | --- |
4131+
| 3 | 3 | 6 |
4132+
4133+
---
4134+
41254135
### osd_esc_temp_alarm_max
41264136

41274137
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
@@ -3340,7 +3340,6 @@ groups:
33403340
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)"
33413341
default_value: 0
33423342
field: hud_wp_disp
3343-
33443343
min: 0
33453344
max: 3
33463345
- name: osd_left_sidebar_scroll
@@ -3476,6 +3475,13 @@ groups:
34763475
min: -36
34773476
max: 36
34783477

3478+
- name: osd_esc_rpm_precision
3479+
description: Number of characters used to display the RPM value.
3480+
field: esc_rpm_precision
3481+
min: 3
3482+
max: 6
3483+
default_value: 3
3484+
34793485
- name: PG_OSD_COMMON_CONFIG
34803486
type: osdCommonConfig_t
34813487
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
@@ -383,6 +383,7 @@ typedef struct osdConfig_s {
383383
uint8_t crsf_lq_format;
384384
uint8_t sidebar_height; // sidebar height in rows, 0 turns off sidebars leaving only level indicator arrows
385385
uint8_t telemetry; // use telemetry on displayed pixel line 0
386+
uint8_t esc_rpm_precision; // Number of characters used for the RPM numbers.
386387

387388
} osdConfig_t;
388389

0 commit comments

Comments
 (0)