AP_OSD: use get_max_rpm_esc()

allow ESC index to be specified for OSD ESC info
This commit is contained in:
Andy Piper 2024-05-22 17:20:51 +01:00 committed by Andrew Tridgell
parent 038735657a
commit 451c1ae347
2 changed files with 33 additions and 9 deletions

View File

@ -259,6 +259,9 @@ private:
AP_Int8 txt_resolution; AP_Int8 txt_resolution;
AP_Int8 font_index; AP_Int8 font_index;
#endif #endif
#if HAL_WITH_ESC_TELEM
AP_Int8 esc_index;
#endif
void draw_altitude(uint8_t x, uint8_t y); void draw_altitude(uint8_t x, uint8_t y);
void draw_bat_volt(uint8_t instance,VoltageType type,uint8_t x, uint8_t y); void draw_bat_volt(uint8_t instance,VoltageType type,uint8_t x, uint8_t y);

View File

@ -358,7 +358,7 @@ const AP_Param::GroupInfo AP_OSD_Screen::var_info[] = {
#if HAL_WITH_ESC_TELEM #if HAL_WITH_ESC_TELEM
// @Param: ESCTEMP_EN // @Param: ESCTEMP_EN
// @DisplayName: ESCTEMP_EN // @DisplayName: ESCTEMP_EN
// @Description: Displays first esc's temp // @Description: Displays highest temp of all active ESCs, or of a specific ECS if OSDx_ESC_IDX is set
// @Values: 0:Disabled,1:Enabled // @Values: 0:Disabled,1:Enabled
// @Param: ESCTEMP_X // @Param: ESCTEMP_X
@ -374,7 +374,7 @@ const AP_Param::GroupInfo AP_OSD_Screen::var_info[] = {
// @Param: ESCRPM_EN // @Param: ESCRPM_EN
// @DisplayName: ESCRPM_EN // @DisplayName: ESCRPM_EN
// @Description: Displays first esc's rpm // @Description: Displays highest rpm of all active ESCs, or of a specific ESC if OSDx_ESC_IDX is set
// @Values: 0:Disabled,1:Enabled // @Values: 0:Disabled,1:Enabled
// @Param: ESCRPM_X // @Param: ESCRPM_X
@ -390,7 +390,7 @@ const AP_Param::GroupInfo AP_OSD_Screen::var_info[] = {
// @Param: ESCAMPS_EN // @Param: ESCAMPS_EN
// @DisplayName: ESCAMPS_EN // @DisplayName: ESCAMPS_EN
// @Description: Displays first esc's current // @Description: Displays the current of the ESC with the highest rpm of all active ESCs, or of a specific ESC if OSDx_ESC_IDX is set
// @Values: 0:Disabled,1:Enabled // @Values: 0:Disabled,1:Enabled
// @Param: ESCAMPS_X // @Param: ESCAMPS_X
@ -1166,6 +1166,14 @@ const AP_Param::GroupInfo AP_OSD_Screen::var_info2[] = {
AP_SUBGROUPINFO(rc_lq, "RC_LQ", 9, AP_OSD_Screen, AP_OSD_Setting), AP_SUBGROUPINFO(rc_lq, "RC_LQ", 9, AP_OSD_Screen, AP_OSD_Setting),
#endif #endif
#if HAL_WITH_ESC_TELEM
// @Param: ESC_IDX
// @DisplayName: ESC_IDX
// @Description: Index of the ESC to use for displaying ESC information. 0 means use the ESC with the highest value.
// @Range: 0 32
AP_GROUPINFO("ESC_IDX", 10, AP_OSD_Screen, esc_index, 0),
#endif
AP_GROUPEND AP_GROUPEND
}; };
@ -2003,8 +2011,13 @@ void AP_OSD_Screen::draw_vspeed(uint8_t x, uint8_t y)
void AP_OSD_Screen::draw_esc_temp(uint8_t x, uint8_t y) void AP_OSD_Screen::draw_esc_temp(uint8_t x, uint8_t y)
{ {
int16_t etemp; int16_t etemp;
// first parameter is index into array of ESC's. Hardwire to zero (first) for now.
if (!AP::esc_telem().get_temperature(0, etemp)) { if (esc_index > 0) {
if (!AP::esc_telem().get_motor_temperature(esc_index-1, etemp)) {
return;
}
}
else if (!AP::esc_telem().get_highest_motor_temperature(etemp)) {
return; return;
} }
@ -2014,8 +2027,12 @@ void AP_OSD_Screen::draw_esc_temp(uint8_t x, uint8_t y)
void AP_OSD_Screen::draw_esc_rpm(uint8_t x, uint8_t y) void AP_OSD_Screen::draw_esc_rpm(uint8_t x, uint8_t y)
{ {
float rpm; float rpm;
// first parameter is index into array of ESC's. Hardwire to zero (first) for now. uint8_t esc = AP::esc_telem().get_max_rpm_esc();
if (!AP::esc_telem().get_rpm(0, rpm)) { if (esc_index > 0) {
if (!AP::esc_telem().get_rpm(esc_index-1, rpm)) {
return;
}
} else if (!AP::esc_telem().get_rpm(esc, rpm)) {
return; return;
} }
float krpm = rpm * 0.001f; float krpm = rpm * 0.001f;
@ -2026,8 +2043,12 @@ void AP_OSD_Screen::draw_esc_rpm(uint8_t x, uint8_t y)
void AP_OSD_Screen::draw_esc_amps(uint8_t x, uint8_t y) void AP_OSD_Screen::draw_esc_amps(uint8_t x, uint8_t y)
{ {
float amps; float amps;
// first parameter is index into array of ESC's. Hardwire to zero (first) for now. uint8_t esc = AP::esc_telem().get_max_rpm_esc();
if (!AP::esc_telem().get_current(0, amps)) { if (esc_index > 0) {
if (!AP::esc_telem().get_current(esc_index-1, amps)) {
return;
}
} else if (!AP::esc_telem().get_current(esc, amps)) {
return; return;
} }
backend->write(x, y, false, "%4.1f%c", amps, SYMBOL(SYM_AMP)); backend->write(x, y, false, "%4.1f%c", amps, SYMBOL(SYM_AMP));