diff --git a/src/main/io/osd.c b/src/main/io/osd.c index a584ce731..51e2d0b46 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -151,6 +151,25 @@ static char osdGetAltitudeSymbol() } } +/** + * Gets average battery cell voltage in 0.01V units. + */ +static int osdGetBatteryAverageCellVoltage(void) +{ + return (getBatteryVoltage() * 10) / getBatteryCellCount(); +} + +static char osdGetBatterySymbol(int cellVoltage) +{ + if(getBatteryState() == BATTERY_CRITICAL) { + return SYM_MAIN_BATT; // FIXME: currently the BAT- symbol, ideally replace with a battery with exclamation mark + } else { + /* Calculate a symbol offset using cell voltage over full cell voltage range */ + int symOffset = scaleRange(cellVoltage, batteryConfig()->vbatmincellvoltage * 10, batteryConfig()->vbatmaxcellvoltage * 10, 0, 7); + return SYM_BATT_EMPTY - constrain(symOffset, 0, 6); + } +} + /** * Converts altitude based on the current unit system. * @param alt Raw altitude (i.e. as taken from BaroAlt) @@ -195,7 +214,7 @@ static void osdDrawSingleElement(uint8_t item) } case OSD_MAIN_BATT_VOLTAGE: - buff[0] = SYM_BATT_5; + buff[0] = osdGetBatterySymbol(osdGetBatteryAverageCellVoltage()); tfp_sprintf(buff + 1, "%d.%1dV", getBatteryVoltage() / 10, getBatteryVoltage() % 10); break; @@ -443,8 +462,8 @@ static void osdDrawSingleElement(uint8_t item) case OSD_AVG_CELL_VOLTAGE: { - const int cellV = getBatteryVoltage() * 10 / getBatteryCellCount(); - buff[0] = SYM_BATT_5; + const int cellV = osdGetBatteryAverageCellVoltage(); + buff[0] = osdGetBatterySymbol(cellV); tfp_sprintf(buff + 1, "%d.%02dV", cellV / 100, cellV % 100); break; } diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index c2b296e85..9b02c2ff4 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -433,7 +433,6 @@ uint8_t getBatteryCellCount(void) return batteryCellCount; } - int32_t getAmperage(void) { return currentMeter.amperage; }