Xinyuan-LilyGO / TTGO_TWatch_Library

MIT License
890 stars 284 forks source link

Battery Percentage shows 127% after wake from deep sleep #128

Closed dominicklee closed 3 years ago

dominicklee commented 3 years ago

I have the following code to retrieve the battery percentage:

AXP20X_Class *power;
power = device->power;              //define power object

int battPercent = power->getBattPercentage();

This is the code I used to sleep the device when power key is pressed:

    power->clearIRQ();
    // We are sleeping the device when power button pressed
    device->displaySleep();
    device->powerOff();
    esp_sleep_enable_ext1_wakeup(GPIO_SEL_35, ESP_EXT1_WAKEUP_ALL_LOW);
    esp_deep_sleep_start();

However, after I sleep the device, battPercent shows 127 instead of the actual battery percentage. When the device is plugged in, the percentage is normal, but when unplugged, it goes back to 127. The value does not change despite the battery continuing to drain.

Can someone please try this and let me know why it is happening and how we can fix it? Thanks

dominicklee commented 3 years ago

After trying several approached, I figured out that this line of code is essential for obtaining the battery percentage:

power->adc1Enable(AXP202_VBUS_VOL_ADC1 | AXP202_VBUS_CUR_ADC1 | AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true);

With that said, I have resolved my own issue.