diff --git a/variants/wio-tracker-l2/WioTrackerL2Board.cpp b/variants/wio-tracker-l2/WioTrackerL2Board.cpp index edeaacce..ecdc25a7 100644 --- a/variants/wio-tracker-l2/WioTrackerL2Board.cpp +++ b/variants/wio-tracker-l2/WioTrackerL2Board.cpp @@ -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; } diff --git a/variants/wio-tracker-l2/WioTrackerL2Board.h b/variants/wio-tracker-l2/WioTrackerL2Board.h index c5644e2f..47ce561f 100644 --- a/variants/wio-tracker-l2/WioTrackerL2Board.h +++ b/variants/wio-tracker-l2/WioTrackerL2Board.h @@ -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