M5Core2 icon indicating copy to clipboard operation
M5Core2 copied to clipboard

No detection of power button press

Open JasonPittenger opened this issue 3 years ago • 2 comments

Describe the bug

There's no way to use the power button as a soft power down option. The AXP192 does detect short presses of the power button, and stores it in register 0X46.

This could be solved by the addition of the following function.

bool AXP192::GetPowerPressed() { if (Read8bit(0x46) | 0x02) return true; else return false; }

To reproduce

In environments, this cannot be done.

Expected behavior

I would expect something like this behavior

if(AXP192::GetPowerPressed()) { //Do power down routine AXP192::PowerOff(); }

or

if(AXP192::GetPowerPressed()) { //Do power down routine AXP192::LightSleep(SLEEP_SEC(5)); }

Screenshots

No response

Environment

  • OS:
  • IDE &IDE Version:
  • Repository Version:

Additional context

No response

Issue checklist

  • [X] I searched for previous reports in the issue tracker
  • [X] My report contains all necessary details

JasonPittenger avatar Aug 29 '22 18:08 JasonPittenger

Is anyone looking into this issue?

I already have a soft power-down routine that uses the touch buttons. However, I'm using the m5 in an environment where I am often wearing gloves. Adding detection of presses to the physical power button would allow me to power up and power down without using any of the touch buttons or the touch screen.

JasonPittenger avatar Oct 28 '22 20:10 JasonPittenger

I added my own version, though it is not in the library. Here is my example code.

//Let's read the power button from the m5 AXP chip Wire1.beginTransmission(0x34); Wire1.write(0x46); Wire1.endTransmission(); Wire1.requestFrom(0x34, 1); u8_PowerWasPressed = Wire1.read(); Serial.println(u8_PowerWasPressed); if((u8_PowerWasPressed & 0x01) == 0x01) { //Power button was long pressed! Serial.println("Power Long Press"); //Save all data and safely stop all processes here. M5.Axp.PowerOff(); } else if((u8_PowerWasPressed & 0x02) == 0x02) { //Power button was short pressed! Serial.println("Power Short Press"); M5.Axp.SetPeripherialsPower(false); //Turn off all external peripherials (5V power) SleepProcessor(SLEEP_MSEC(10000)); //Sleep for 10 seconds M5.Axp.SetPeripherialsPower(true); //Turn on all external peripherials (5V power) M5.Axp.SetBusPowerMode(0); //Needed to Turn on all external peripherials for some reason } if(u8_PowerWasPressed & 0x03)

JasonPittenger avatar Nov 17 '22 18:11 JasonPittenger