From c90e87e82958589ff86c89721edaaa89ebd9b84c Mon Sep 17 00:00:00 2001 From: alexklimaj Date: Mon, 6 Jan 2025 15:50:31 -0700 Subject: [PATCH] ina238: increase retries and only publish not connected if register check fails --- src/drivers/power_monitor/ina238/ina238.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/drivers/power_monitor/ina238/ina238.cpp b/src/drivers/power_monitor/ina238/ina238.cpp index e4c552a3a605..df7d0079fc04 100644 --- a/src/drivers/power_monitor/ina238/ina238.cpp +++ b/src/drivers/power_monitor/ina238/ina238.cpp @@ -98,7 +98,7 @@ int INA238::read(uint8_t address, uint16_t &data) uint16_t received_bytes; int ret = PX4_ERROR; - for (size_t i = 0; i < 3; i++) { + for (size_t i = 0; i < 6; i++) { ret = transfer(&address, 1, (uint8_t *)&received_bytes, sizeof(received_bytes)); if (ret == PX4_OK) { @@ -240,6 +240,10 @@ int INA238::collect() _battery.updateVoltage(static_cast(bus_voltage * INA238_VSCALE)); _battery.updateCurrent(static_cast(current * _current_lsb)); _battery.updateTemperature(static_cast(temperature * INA238_TSCALE)); + + _battery.setConnected(success); + + _battery.updateAndPublishBatteryStatus(hrt_absolute_time()); } if (!success || hrt_elapsed_time(&_last_config_check_timestamp) > 100_ms) { @@ -253,12 +257,12 @@ int INA238::collect() PX4_DEBUG("register check failed"); perf_count(_bad_register_perf); success = false; - } - } - _battery.setConnected(success); + _battery.setConnected(success); - _battery.updateAndPublishBatteryStatus(hrt_absolute_time()); + _battery.updateAndPublishBatteryStatus(hrt_absolute_time()); + } + } perf_end(_sample_perf);