Xinyuan-LilyGO / LilyGo-T-SIM7080G

47 stars 24 forks source link

Power button multi usage #46

Closed spatcho closed 4 months ago

spatcho commented 6 months ago

Good day,

I would like to keep using the power button on / off functionality, and also use the button to i.e. turn on an oled screen. Per example 4s press to turn off, 2s press to turn on, and short press to catch specific code. I see there is interrupt available but if my use case is possible, could I have a short code example ?

hugo8873 commented 6 months ago

Hi there, In my case, I use long press to turn on/off and short press to wakeup/sleep, try twist your code inside,

1st, make a bool pmu_flag = false;

bool pmu_flag = false; 

2nd, custom function,

void setFlag(void) {
  pmu_flag = true;
}

3rd, setup the interrupt in setup(),

  pinMode(PMU_INPUT_PIN, INPUT_PULLUP);  // the shared pin 6 of SoC and PMU.  While DC1 power supply remained, SoC can be wakeup by this pin.  And PMU can also be forced power off by long press this pin.
  attachInterrupt(PMU_INPUT_PIN, setFlag, FALLING);
  // Close other IRQs
  PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ);
  // Clear all interrupt flags
  PMU.clearIrqStatus();
  // Enable the required interrupt function
  PMU.enableIRQ(XPOWERS_AXP2101_PKEY_SHORT_IRQ);  //POWER KEY

4th, put a trigger in loop();

if (pmu_flag) {
    pmu_flag = false;
    // Get PMU Interrupt Status Register
    uint32_t status = PMU.getIrqStatus();
    if (PMU.isPekeyShortPressIrq()) {
      // your codes here...
    }
  }
spatcho commented 6 months ago

It worked, thank you

spatcho commented 6 months ago

Shall I close it ?

github-actions[bot] commented 5 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 4 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.