Skip to content

Commit

Permalink
Fix locking issues with the power manager and model gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
eberseth committed Oct 10, 2023
1 parent 3092c2f commit b311265
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,26 +347,29 @@ void Tracker::initBatteryMonitor() {
// In order to disable charging safely we want to enable the PMIC watchdog so that
// if anything happens during the procedure that the circuit can return to
// normal operation in the event the MCU doesn't complete.
PMIC pmic(true);
FuelGauge fuelGauge;

pmic.setWatchdog(0x1); // 40 seconds
pmic.disableCharging();
// Delay so that the bulk capacitance and battery can equalize
delay(_commonCfgData.postChargeSettleTime);

TrackerFuelGauge::instance().init();

fuelGauge.quickStart();
// Must delay at least 175ms after quickstart, before calling
// getSoC(), or reading will not have updated yet.
delay(200);

_forceDisableCharging = _deviceConfig.disableCharging();
if (_batterySafeToCharge && !_forceDisableCharging) {
pmic.enableCharging();
{
PMIC pmic(true);
FuelGauge fuelGauge;

pmic.setWatchdog(0x1); // 40 seconds
pmic.disableCharging();
// Delay so that the bulk capacitance and battery can equalize
delay(_commonCfgData.postChargeSettleTime);

fuelGauge.quickStart();
// Must delay at least 175ms after quickstart, before calling
// getSoC(), or reading will not have updated yet.
delay(200);

_forceDisableCharging = _deviceConfig.disableCharging();
if (_batterySafeToCharge && !_forceDisableCharging) {
pmic.enableCharging();
}
pmic.disableWatchdog();
}
pmic.disableWatchdog();
}

bool Tracker::getChargeEnabled() {
Expand Down

0 comments on commit b311265

Please sign in to comment.