mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-10-09 11:16:39 +00:00
fix(wio-tracker-l2): keep the last good battery reading when the ADC read fails
A failed ADS1115 read returned 0 mV, so the status bar showed 0 % (and the low-battery shutdown could see an empty battery) until a reboot. Retry once, then keep the last good value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -194,11 +194,18 @@ int16_t WioTrackerL2Board::adsReadRaw() {
|
||||
return raw < 0 ? 0 : raw;
|
||||
}
|
||||
|
||||
// A failed or zero ADS1115 read (the I2C bus busy or the ADC not answering)
|
||||
// keeps the last good value instead of reporting 0 mV -- that read as 0 % in
|
||||
// the status bar and could trip the low-battery shutdown. Retried once first.
|
||||
uint16_t WioTrackerL2Board::getBattMilliVolts() {
|
||||
if (!expander_ok) return 0; // BAT_ADC_EN rail never came up
|
||||
|
||||
int16_t raw = adsReadRaw();
|
||||
if (raw < 0) return 0;
|
||||
|
||||
return (uint16_t)(raw * ADS_MV_PER_LSB);
|
||||
for (int attempt = 0; attempt < 2; attempt++) {
|
||||
int16_t raw = adsReadRaw();
|
||||
if (raw > 0) {
|
||||
batt_mv_last = (uint16_t)(raw * ADS_MV_PER_LSB);
|
||||
return batt_mv_last;
|
||||
}
|
||||
}
|
||||
return batt_mv_last;
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ private:
|
||||
bool expander_ok = false;
|
||||
bool aw_ok = false; // AW35615 USB-C controller responded at probe
|
||||
uint8_t wake_btn_baseline = 0; // idle level of P00, captured at init
|
||||
uint16_t batt_mv_last = 0; // last good battery reading (a failed read keeps it)
|
||||
|
||||
int expReadInputs(); // 16-bit input register pair, -1 on error
|
||||
|
||||
|
||||
Reference in New Issue
Block a user