Merge pull request #871 from claesg/master

Low battery level counter for NRF52
This commit is contained in:
Kevin Hester 2021-10-12 23:12:36 +08:00 committed by GitHub
commit 128a481259
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -192,6 +192,7 @@ bool Power::setup()
found = analogInit();
}
enabled = found;
low_voltage_counter = 0;
return found;
}
@ -238,9 +239,24 @@ void Power::readPowerStatus()
powerStatus.getIsCharging(), powerStatus.getBatteryVoltageMv(), powerStatus.getBatteryChargePercent());
newStatus.notifyObservers(&powerStatus);
// If we have a battery at all and it is less than 10% full, force deep sleep if we have more than 3 low readings in a row
// Supect fluctuating voltage on the RAK4631 to force it to deep sleep even if battery is at 85% after only a few days
#ifdef NRF52_SERIES
if (powerStatus.getHasBattery() && !powerStatus.getHasUSB()){
if (batteryLevel->getBattVoltage() < MIN_BAT_MILLIVOLTS){
low_voltage_counter++;
if (low_voltage_counter>3)
powerFSM.trigger(EVENT_LOW_BATTERY);
} else {
low_voltage_counter = 0;
}
}
#else
// If we have a battery at all and it is less than 10% full, force deep sleep
if (powerStatus.getHasBattery() && !powerStatus.getHasUSB() && batteryLevel->getBattVoltage() < MIN_BAT_MILLIVOLTS)
powerFSM.trigger(EVENT_LOW_BATTERY);
#endif
} else {
// No power sensing on this board - tell everyone else we have no idea what is happening
const PowerStatus powerStatus = PowerStatus(OptUnknown, OptUnknown, OptUnknown, -1, -1);

View File

@ -37,6 +37,9 @@ class Power : private concurrency::OSThread
/// Setup a simple ADC input based battery sensor
bool analogInit();
private:
uint8_t low_voltage_counter;
};
extern Power *power;