Skip to content

Commit 53bd231

Browse files
authored
Merge pull request #2359 from cwilling/wakeupCause
Add function getWakeupCause for ESP32
2 parents a816743 + 0d64aa2 commit 53bd231

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

targets/esp32/jswrap_esp32.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,29 @@ void jswrap_ESP32_deepSleep_ext0(Pin pin, int level) {
106106
esp_deep_sleep_start(); // This function does not return.
107107
} // End of jswrap_ESP32_deepSleep_ext0
108108

109+
/*JSON{
110+
"type" : "staticmethod",
111+
"class" : "ESP32",
112+
"ifdef" : "ESP32",
113+
"name" : "getWakeupCause",
114+
"generate" : "jswrap_ESP32_getWakeupCause",
115+
"return" : ["int", "The cause of the ESP32's wakeup from sleep"]
116+
}
117+
Returns a variable identifying the cause of wakeup from deep sleep.
118+
Possible causes include:
119+
120+
* `0: ESP_SLEEP_WAKEUP_UNDEFINED` - reset was not caused by exit from deep sleep
121+
* `2: ESP_SLEEP_WAKEUP_EXT0` - Wakeup caused by external signal using RTC_IO
122+
* `3: ESP_SLEEP_WAKEUP_EXT1` - Wakeup caused by external signal using RTC_CNTL
123+
* `4: ESP_SLEEP_WAKEUP_TIMER` - Wakeup caused by timer
124+
* `5: ESP_SLEEP_WAKEUP_TOUCHPAD` - Wakeup caused by touchpad
125+
* `6: ESP_SLEEP_WAKEUP_ULP` - Wakeup caused by ULP program
126+
127+
*/
128+
int jswrap_ESP32_getWakeupCause() {
129+
return esp_sleep_get_wakeup_cause();
130+
} // End of jswrap_ESP32_getWakeupCause
131+
109132

110133
/*JSON{
111134
"type" : "staticmethod",

targets/esp32/jswrap_esp32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ JsVar *jswrap_ESP32_setBoot(JsVar *jsPartitionName);
2424
void jswrap_ESP32_reboot();
2525
void jswrap_ESP32_deepSleep(int us);
2626
void jswrap_ESP32_deepSleep_ext0(Pin pin,int level);
27+
int jswrap_ESP32_getWakeupCause();
2728
void jswrap_ESP32_setAtten(Pin pin,int atten);
2829

2930
#ifdef BLUETOOTH

0 commit comments

Comments
 (0)