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

Add function deepSleepExt0 #2358

Merged
merged 1 commit into from
May 10, 2023
Merged

Add function deepSleepExt0 #2358

merged 1 commit into from
May 10, 2023

Conversation

cwilling
Copy link
Contributor

@cwilling cwilling commented May 9, 2023

This PR adds ability for ESP32 boards to wake from deep sleep by trigger from external interrupt (setting a GPIO pin). It may be confirmed with this example code:

const buttonPin = D4;
pinMode(buttonPin, 'input');

// Flash LED1 (while awake)
var on = false;
setInterval(function() {
  on = !on;
  LED1.write(on);
}, 500);

// Every 10secs, sleep until buttonPin is pressed
setInterval(function() {
  console.log("Time to sleep");
  ESP32.deepSleepExt0(buttonPin, 1);
}, 10000);

Signed-off-by: Christoph Willing <[email protected]>
@cwilling cwilling mentioned this pull request May 9, 2023
33 tasks
@gfwilliams
Copy link
Member

Looks great - thanks! Very happy to have stuff like this if it makes the ESP32 port more usable.

I'm merging now, but quick question: Can esp_sleep_enable_ext0_wakeup return an error code (eg if the wrong pin is specified like esp_sleep_enable_ext0_wakeup(700, ...)?)

If so it might be worth checking it and doing jsExceptionHere(JSET_ERROR, "Invalid Arguments") rather than trying to sleep the ESP32 with no way to wake it?

@gfwilliams gfwilliams merged commit 4485ec3 into espruino:master May 10, 2023
@cwilling cwilling deleted the ext0wakeup branch May 10, 2023 09:12
@cwilling
Copy link
Contributor Author

Thanks for the merge. I'll have a look at how to do the jsExceptionHere thing (still new to Espruino).

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

Successfully merging this pull request may close these issues.

2 participants