From 49d22edc337471337b5d53448f214bd604bca1cf Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Thu, 26 Mar 2020 15:14:27 +0100 Subject: [PATCH] battery: cell voltage fill refactor --- src/lib/battery/battery.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/lib/battery/battery.cpp b/src/lib/battery/battery.cpp index 855cc37040..df37600b9c 100644 --- a/src/lib/battery/battery.cpp +++ b/src/lib/battery/battery.cpp @@ -153,14 +153,10 @@ Battery::updateBatteryStatus(hrt_abstime timestamp, float voltage_v, float curre static constexpr int uorb_max_cells = sizeof(_battery_status.voltage_cell_v) / sizeof( _battery_status.voltage_cell_v[0]); - int i; - for (i = 0; i < _params.n_cells && i < uorb_max_cells; i++) { - _battery_status.voltage_cell_v[i] = _voltage_filtered_v / _params.n_cells; - } - - for (; i < uorb_max_cells; i++) { - _battery_status.voltage_cell_v[i] = 0.0f; + // Fill cell voltages with average values to work around BATTERY_STATUS message not allowing to report just total voltage + for (int i = 0; (i < _battery_status.cell_count) && (i < uorb_max_cells); i++) { + _battery_status.voltage_cell_v[i] = _battery_status.voltage_filtered_v / _battery_status.cell_count; } }