diff --git a/examples/PrimoDeepSleep/PrimoDeepSleep.ino b/examples/PrimoDeepSleep/PrimoDeepSleep.ino index 9e7d9f8..fa24333 100644 --- a/examples/PrimoDeepSleep/PrimoDeepSleep.ino +++ b/examples/PrimoDeepSleep/PrimoDeepSleep.ino @@ -16,7 +16,7 @@ a wakeup source. The board will be reset when it wakes up from power off. You can use wakeUpCause() function to find out what signals woke up - the board if you use more than one wakeUpBy.. function. + the board if you use enableWakeUpFrom() function more than once.. This example code is in the public domain. */ @@ -31,13 +31,16 @@ const int digitalPin = 10; const int analogPin = A0; -void StmEspPM(bool sleep){ +void StmWifiPM(bool sleep){ // enable USER1_BUTTON to turn STM32 off and on when pressed. // note that when STM32 is off you cannot load any new sketch. - pinMode(USER1_BUTTON, STM32_IT); + LowPower.enableStm32Sleep(); - // turn ESP8266 off or on - digitalWrite(GPIO_ESP_PW, sleep ? LOW: HIGH); + // turn WiFi off or on + if(sleep) + LowPower.powerOffWifi(); + else + LowPower.powerOnWifi(); } void setup() { @@ -62,8 +65,8 @@ void setup() { Serial.println("Hi all, I return to sleep"); - LowPower.companionLowPowerCallback(StmEspPM); - // Send sleep command to ESP and enable USER1_BUTTON to turn STM off + LowPower.companionLowPowerCallback(StmWifiPM); + // Send sleep command to WiFi and enable USER1_BUTTON to turn STM off LowPower.companionSleep(); //set digital pin 10 to wake up the board when LOW level is detected diff --git a/keywords.txt b/keywords.txt index d0813b7..ceca4be 100644 --- a/keywords.txt +++ b/keywords.txt @@ -22,6 +22,10 @@ companionLowPowerCallback KEYWORD2 companionSleep KEYWORD2 companionWakeup KEYWORD2 wakeupReason KEYWORD2 +powerOnWifi KEYWORD2 +powerOffWifi KEYWORD2 +enableStm32Sleep KEYWORD2 +disableStm32Standby KEYWORD2 ####################################### # Constants (LITERAL1) diff --git a/src/ArduinoLowPower.h b/src/ArduinoLowPower.h index 474c879..b5f602b 100644 --- a/src/ArduinoLowPower.h +++ b/src/ArduinoLowPower.h @@ -66,6 +66,10 @@ class ArduinoLowPowerClass { #ifdef ARDUINO_ARCH_NRF52 void enableWakeupFrom(wakeup_reason peripheral, uint32_t pin = 0xFF, uint32_t event = 0xFF, uint32_t option = 0xFF); wakeup_reason wakeupReason(); + void powerOnWifi(void); + void powerOffWifi(void); + void enableStm32Sleep(void); + void disableStm32Standby(void); #endif private: diff --git a/src/nrf52/ArduinoLowPower.cpp b/src/nrf52/ArduinoLowPower.cpp index 75889a1..744be6d 100644 --- a/src/nrf52/ArduinoLowPower.cpp +++ b/src/nrf52/ArduinoLowPower.cpp @@ -154,6 +154,26 @@ wakeup_reason ArduinoLowPowerClass::wakeupReason(){ return OTHER_WAKEUP; } +void ArduinoLowPowerClass::powerOnWifi(){ + //turn the WiFi on + digitalWrite(GPIO_ESP_PW, HIGH); +} + +void ArduinoLowPowerClass::powerOffWifi(){ + //turn the WiFi off + digitalWrite(GPIO_ESP_PW, LOW); +} + +void ArduinoLowPowerClass::enableStm32Sleep(){ + //setup USER1_BUTTON as an interrupt to trigger STM32 enter to sleep mode or wake up from sleep mode + pinMode(USER1_BUTTON, STM32_IT); +} + +void ArduinoLowPowerClass::disableStm32Standby(){ + //disable STM32 enter to standby mode + pinMode(BAT_VOL, INPUT); +} + ArduinoLowPowerClass LowPower;