battery: check source param inside battery lib

This moves the handling of the BAT%d_SOURCE param inside of the battery
library. Users of the library now pass the source instead of the flag
whether to publish. The battery library then checks if the source is
selected using the param and publishes accordingly.

Since we removed the strange system_source flag, we now need to look at
all batteries in commander.
For current estimation - I think - it makes sense to sum them up.
This commit is contained in:
Julian Oes
2020-03-25 11:27:05 +01:00
parent 641612468b
commit f650b91718
13 changed files with 55 additions and 61 deletions
+4 -3
View File
@@ -3821,6 +3821,8 @@ void Commander::battery_status_check()
// oldest timestamp.
hrt_abstime oldest_update = hrt_absolute_time();
_battery_current = 0.0f;
// Only iterate over connected batteries. We don't care if a disconnected battery is not regularly publishing.
for (size_t i = 0; i < num_connected_batteries; i++) {
if (batteries[i].warning > worst_warning) {
@@ -3831,9 +3833,8 @@ void Commander::battery_status_check()
oldest_update = batteries[i].timestamp;
}
if (batteries[i].system_source) {
_battery_current = batteries[i].current_filtered_a;
}
// Sum up current from all batteries.
_battery_current += batteries[i].current_filtered_a;
}
bool battery_warning_level_increased_while_armed = false;