From b00be9b4ec4fd91647dac2b68a8eebacbccad2c3 Mon Sep 17 00:00:00 2001 From: DHJeff Date: Thu, 4 May 2017 11:06:43 +0800 Subject: [PATCH 1/4] Added stm32pwr functions to API --- src/ArduinoLowPower.h | 4 ++++ src/nrf52/ArduinoLowPower.cpp | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) 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; From 342af9011aa125ea9609046422e8d28f54c11f66 Mon Sep 17 00:00:00 2001 From: DHJeff Date: Thu, 4 May 2017 11:18:27 +0800 Subject: [PATCH 2/4] Modified keywords --- keywords.txt | 4 ++++ 1 file changed, 4 insertions(+) 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) From 1f5dbc723ca521417f791806af3cc2cb76d62dda Mon Sep 17 00:00:00 2001 From: DHJeff Date: Thu, 4 May 2017 11:20:51 +0800 Subject: [PATCH 3/4] Modified PrimoDeepSleep example --- examples/PrimoDeepSleep/PrimoDeepSleep.ino | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/PrimoDeepSleep/PrimoDeepSleep.ino b/examples/PrimoDeepSleep/PrimoDeepSleep.ino index 9e7d9f8..b1796bd 100644 --- a/examples/PrimoDeepSleep/PrimoDeepSleep.ino +++ b/examples/PrimoDeepSleep/PrimoDeepSleep.ino @@ -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 From f424c30ebb0a65711d6696ff7e5fc53f51448c7c Mon Sep 17 00:00:00 2001 From: DHJeff Date: Thu, 4 May 2017 17:23:42 +0800 Subject: [PATCH 4/4] Modified comment in PrimoDeepSleep example --- examples/PrimoDeepSleep/PrimoDeepSleep.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/PrimoDeepSleep/PrimoDeepSleep.ino b/examples/PrimoDeepSleep/PrimoDeepSleep.ino index b1796bd..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. */