From 5ebe5010ac1f5613308260062c130421b823fc8e Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Wed, 5 Jul 2017 07:28:49 -1000 Subject: [PATCH] Bugfix:Sensors battery_status Intance 0 voltage was 0V for Brick 2 Both PX4Test and Beat noted if only Brick to was connected battery_status Intance 0 voltage was 0V for Brick2 The priority selection logic is run prior to the subscription creation and only updated the priority on a change. Before the subscriotions were created. _battery_pub_intance0ndx is suposed track the location in the _battery_pub array that is instance 0. It is then used to associate (move) instance 0 with (to) the lowest brick (highest priority in HW) brick that is selected in HW. The Bug was that before the subscriptions are created, _battery_pub_intance0ndx set to 1. And then and never updated. The fix was to only run the priority selection logic once the subscriptions are created. --- src/modules/sensors/sensors.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/sensors/sensors.cpp b/src/modules/sensors/sensors.cpp index db54916bb1..7f6b0001f7 100644 --- a/src/modules/sensors/sensors.cpp +++ b/src/modules/sensors/sensors.cpp @@ -495,10 +495,10 @@ Sensors::adc_poll(struct sensor_combined_s &raw) { for (int b = 0; b < BOARD_NUMBER_BRICKS; b++) { - /* Do this once for the lowest (highest priority supply on power controller) - * that is valid + /* Once we have subscriptions, Do this once for the lowest (highest priority + * supply on power controller) that is valid. */ - if (selected_source < 0 && valid_chan[b]) { + if (_battery_pub[b] != nullptr && selected_source < 0 && valid_chan[b]) { /* Indicate the lowest brick (highest priority supply on power controller) * that is valid as the one that is the selected source for the * VDD_5V_IN