Hi,
I am using the following code to read the battery charge and the time left (pC equals pBatteryChargePercent when I want to read the battery charge, otherwise I want to read the time left. I know this temporary code is not fully clean, but I think it's not the point here).
This code is invoked when a BlueTooth characteristic is read, so when the ESP32 is in a woken-up mode (and not in sleep mode, neither in the wake stub). Board.init(1800)
has been called prior to this, as the first line in app_main
.
I face 2 issues:
1) while the battery is being charged (USB plugged), the battery charge is constantly 42 (for instance), for several minutes (say, at least 10 minutes), and then it suddenly changes to 92 (for instance). I would expect a more continuous progression instead of this 50% jump.
2) the getBatteryTimeLeft always returns -4 (NotReady), even when waiting some significant time, i.e. several minutes.
Most of the time, the application is in deep sleep. It wakes about every minute to do some code for a few milliseconds in the wake stub.
When the user triggers a touchpad, then the app wakes up, starts BlueTooth, and returns to deep sleep after 30 seconds. the code above is thus code during these 30 seconds.
Is there anything specific to do:
1) in order for getBatteryCharge to update more regularly (I would expect to read something more continuous like 42, 50, 60, 70, 80, 92, rather than 42, 42, 42, 42, 42, 42, 92)
2) in order for getBatteryTimeLeft to be successful instead of returning NotReady
?
Many thanks!
PowerFeather::Result res;
int value;
res = PowerFeather::Board.enableVSQT(true);
if (res != PowerFeather::Result::Ok) {
value = -1;
}
else {
res = PowerFeather::Board.enableBatteryFuelGauge(true);
if (res != PowerFeather::Result::Ok) {
value = -2;
}
else {
if (pC == pBatteryChargePercent) {
uint8_t batteryCharge;
res = PowerFeather::Board.getBatteryCharge(batteryCharge);
if (res != PowerFeather::Result::Ok) {
value = -3;
}
else {
value = batteryCharge;
}
}
else {
res = PowerFeather::Board.getBatteryTimeLeft(value);
if (res != PowerFeather::Result::Ok) {
if (res == PowerFeather::Result::NotReady) {
value = -4;
}
else {
value = -3;
}
}
}
PowerFeather::Board.enableBatteryFuelGauge(false);
}
res = PowerFeather::Board.enableVSQT(false);
}