Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No detection of power button press #100

Open
2 tasks done
JasonPittenger opened this issue Aug 29, 2022 · 2 comments
Open
2 tasks done

No detection of power button press #100

JasonPittenger opened this issue Aug 29, 2022 · 2 comments

Comments

@JasonPittenger
Copy link

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

  • I searched for previous reports in the issue tracker
  • My report contains all necessary details
@JasonPittenger
Copy link
Author

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
Copy link
Author

JasonPittenger commented Nov 17, 2022

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)

drtrigon added a commit to drtrigon/singsang that referenced this issue Dec 7, 2023
…M5.BtnA.read() does not work)

           ! option to e.g. use A and B for multipage GUI
         * store index of song played last as json to SPIFFS
           * identify SD and apply last index to correct SD
             ! consider storing config for more than one SD - but how to limit data size?
           * also store last volume
             ! however always use safe low default volume
           ! having a callback/event/interrupt on power press would allow to store config state at power-off only
           ! storing actual playing position is more complex and costly (needs timer e.g. 1s or power-off method)
             * see m5stack/M5Core2#100 ("No detection of power button press · Issue #100 · m5stack/M5Core2 · GitHub")
             * power button press is not suficient, what happens when SD gets removed while playing (temp. store until power button?)
               what happens when bat gets empty? -> timer might be only general solution, may be combined with power button detection
           * see also https://github.com/vshymanskyy/Preferences (by default does not use SPIFFS but flash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant