diff --git a/src/Power.cpp b/src/Power.cpp index 162047fa..731bf7c7 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -138,39 +138,38 @@ int32_t Power::runOnce() { readPowerStatus(); -#ifdef PMU_IRQ - if (pmu_irq) { - pmu_irq = false; - axp.readIRQ(); + // WE no longer use the IRQ line to wake the CPU (due to false wakes from sleep), but we do poll + // the IRQ status by reading the registers over I2C + axp.readIRQ(); - DEBUG_MSG("pmu irq!\n"); - - if (axp.isChargingIRQ()) { - DEBUG_MSG("Battery start charging\n"); - } - if (axp.isChargingDoneIRQ()) { - DEBUG_MSG("Battery fully charged\n"); - } - if (axp.isVbusRemoveIRQ()) { - DEBUG_MSG("USB unplugged\n"); - powerFSM.trigger(EVENT_POWER_DISCONNECTED); - } - if (axp.isVbusPlugInIRQ()) { - DEBUG_MSG("USB plugged In\n"); - powerFSM.trigger(EVENT_POWER_CONNECTED); - } - if (axp.isBattPlugInIRQ()) { - DEBUG_MSG("Battery inserted\n"); - } - if (axp.isBattRemoveIRQ()) { - DEBUG_MSG("Battery removed\n"); - } - if (axp.isPEKShortPressIRQ()) { - DEBUG_MSG("PEK short button press\n"); - } - axp.clearIRQ(); + if (axp.isVbusRemoveIRQ()) { + DEBUG_MSG("USB unplugged\n"); + powerFSM.trigger(EVENT_POWER_DISCONNECTED); } -#endif + if (axp.isVbusPlugInIRQ()) { + DEBUG_MSG("USB plugged In\n"); + powerFSM.trigger(EVENT_POWER_CONNECTED); + } + /* + Other things we could check if we cared... + + if (axp.isChargingIRQ()) { + DEBUG_MSG("Battery start charging\n"); + } + if (axp.isChargingDoneIRQ()) { + DEBUG_MSG("Battery fully charged\n"); + } + if (axp.isBattPlugInIRQ()) { + DEBUG_MSG("Battery inserted\n"); + } + if (axp.isBattRemoveIRQ()) { + DEBUG_MSG("Battery removed\n"); + } + if (axp.isPEKShortPressIRQ()) { + DEBUG_MSG("PEK short button press\n"); + } + */ + axp.clearIRQ(); // Only read once every 20 seconds once the power status for the app has been initialized return (statusHandler && statusHandler->isInitialized()) ? (1000 * 20) : RUN_SAME; diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index ede68258..454a8bdf 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -118,12 +118,21 @@ static void serialEnter() { setBluetoothEnable(false); screen->setOn(true); + screen->print("Using API...\n"); } static void powerEnter() { screen->setOn(true); setBluetoothEnable(true); + screen->print("Powered...\n"); +} + +static void powerExit() +{ + screen->setOn(true); + setBluetoothEnable(true); + screen->print("Unpowered...\n"); } static void onEnter() @@ -156,7 +165,7 @@ State stateDARK(darkEnter, NULL, NULL, "DARK"); State stateSERIAL(serialEnter, NULL, NULL, "SERIAL"); State stateBOOT(bootEnter, NULL, NULL, "BOOT"); State stateON(onEnter, NULL, NULL, "ON"); -State statePOWER(powerEnter, NULL, NULL, "POWER"); +State statePOWER(powerEnter, NULL, powerExit, "POWER"); Fsm powerFSM(&stateBOOT); void PowerFSM_setup() diff --git a/src/PowerFSM.h b/src/PowerFSM.h index d996acbd..4af62040 100644 --- a/src/PowerFSM.h +++ b/src/PowerFSM.h @@ -20,6 +20,6 @@ #define EVENT_POWER_DISCONNECTED 14 extern Fsm powerFSM; -extern State statePOWER; +extern State statePOWER, stateSERIAL; void PowerFSM_setup(); diff --git a/src/main.cpp b/src/main.cpp index 21805e60..f082c8f7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -128,7 +128,8 @@ class PowerFSMThread : public OSThread /// If we are in power state we force the CPU to wake every 10ms to check for serial characters (we don't yet wake /// cpu for serial rx - FIXME) - canSleep = (powerFSM.getState() != &statePOWER); + auto state = powerFSM.getState(); + canSleep = (state != &statePOWER) && (state != &stateSERIAL); return 10; }