From 5489005e0b28118854e5ede6ecd45fae248a8c5e Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Thu, 1 Jul 2021 19:13:43 +0200 Subject: [PATCH] Commander: call battery_status_check on update instead of early return --- src/modules/commander/Commander.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/modules/commander/Commander.cpp b/src/modules/commander/Commander.cpp index 8e82458315..0260cc4ebd 100644 --- a/src/modules/commander/Commander.cpp +++ b/src/modules/commander/Commander.cpp @@ -2190,7 +2190,9 @@ Commander::run() _cpuload_sub.update(&_cpuload); - battery_status_check(); + if (_battery_status_subs.updated()) { + battery_status_check(); + } /* If in INIT state, try to proceed to STANDBY state */ if (!_status_flags.condition_calibration_enabled && _status.arming_state == vehicle_status_s::ARMING_STATE_INIT) { @@ -3604,13 +3606,6 @@ void Commander::avoidance_check() void Commander::battery_status_check() { - // We need to update the status flag if ANY battery is updated, because the system source might have - // changed, or might be nothing (if there is no battery connected) - if (!_battery_status_subs.updated()) { - // Nothing has changed since the last time this function was called, so nothing needs to be done now. - return; - } - battery_status_s batteries[_battery_status_subs.size()]; size_t num_connected_batteries = 0;