From d422314020d6dddbc54e8b109d2c41cf185166ae Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Thu, 23 Apr 2020 13:22:17 -0300 Subject: [PATCH] AP_OSD: update to use capacity_remaining_pct() as a bool --- libraries/AP_OSD/AP_OSD_Screen.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/libraries/AP_OSD/AP_OSD_Screen.cpp b/libraries/AP_OSD/AP_OSD_Screen.cpp index 5d7be80879..bbe2d6b5ca 100644 --- a/libraries/AP_OSD/AP_OSD_Screen.cpp +++ b/libraries/AP_OSD/AP_OSD_Screen.cpp @@ -1225,16 +1225,22 @@ void AP_OSD_Screen::draw_altitude(uint8_t x, uint8_t y) void AP_OSD_Screen::draw_bat_volt(uint8_t x, uint8_t y) { AP_BattMonitor &battery = AP::battery(); - uint8_t pct = battery.capacity_remaining_pct(); - uint8_t p = (100 - pct) / 16.6; float v = battery.voltage(); + uint8_t pct; + if (!battery.capacity_remaining_pct(pct)) { + // Do not show battery percentage + backend->write(x,y, v < osd->warn_batvolt, "%2.1f%c", (double)v, SYM_VOLT); + return; + } + uint8_t p = (100 - pct) / 16.6; backend->write(x,y, v < osd->warn_batvolt, "%c%2.1f%c", SYM_BATT_FULL + p, (double)v, SYM_VOLT); } void AP_OSD_Screen::draw_avgcellvolt(uint8_t x, uint8_t y) { AP_BattMonitor &battery = AP::battery(); - uint8_t pct = battery.capacity_remaining_pct(); + uint8_t pct = 0; + IGNORE_RETURN(battery.capacity_remaining_pct(pct)); uint8_t p = (100 - pct) / 16.6; float v = battery.voltage(); // calculate cell count - WARNING this can be inaccurate if the LIPO/LIION battery is far from fully charged when attached and is used in this panel @@ -1253,7 +1259,8 @@ void AP_OSD_Screen::draw_avgcellvolt(uint8_t x, uint8_t y) void AP_OSD_Screen::draw_restvolt(uint8_t x, uint8_t y) { AP_BattMonitor &battery = AP::battery(); - uint8_t pct = battery.capacity_remaining_pct(); + uint8_t pct = 0; + IGNORE_RETURN(battery.capacity_remaining_pct(pct)); uint8_t p = (100 - pct) / 16.6; float v = battery.voltage_resting_estimate(); backend->write(x,y, v < osd->warn_restvolt, "%c%2.1f%c", SYM_BATT_FULL + p, (double)v, SYM_VOLT); @@ -1849,9 +1856,14 @@ void AP_OSD_Screen::draw_atemp(uint8_t x, uint8_t y) void AP_OSD_Screen::draw_bat2_vlt(uint8_t x, uint8_t y) { AP_BattMonitor &battery = AP::battery(); - uint8_t pct2 = battery.capacity_remaining_pct(1); - uint8_t p2 = (100 - pct2) / 16.6; + uint8_t pct2 = 0; float v2 = battery.voltage(1); + if (!battery.capacity_remaining_pct(pct2, 1)) { + // Do not show battery percentage + backend->write(x,y, v2 < osd->warn_bat2volt, "%2.1f%c", (double)v2, SYM_VOLT); + return; + } + uint8_t p2 = (100 - pct2) / 16.6; backend->write(x,y, v2 < osd->warn_bat2volt, "%c%2.1f%c", SYM_BATT_FULL + p2, (double)v2, SYM_VOLT); }