Skip to content

Commit

Permalink
ina238: increase retries and only publish not connected if register c…
Browse files Browse the repository at this point in the history
…heck fails
  • Loading branch information
AlexKlimaj committed Jan 6, 2025
1 parent f7dd43e commit c90e87e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/drivers/power_monitor/ina238/ina238.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -240,6 +240,10 @@ int INA238::collect()
_battery.updateVoltage(static_cast<float>(bus_voltage * INA238_VSCALE));
_battery.updateCurrent(static_cast<float>(current * _current_lsb));
_battery.updateTemperature(static_cast<float>(temperature * INA238_TSCALE));

_battery.setConnected(success);

_battery.updateAndPublishBatteryStatus(hrt_absolute_time());
}

if (!success || hrt_elapsed_time(&_last_config_check_timestamp) > 100_ms) {
Expand All @@ -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);

Expand Down

0 comments on commit c90e87e

Please sign in to comment.