diff --git a/src/boards_pinout.h b/src/boards_pinout.h index adb95e4..3a7290f 100644 --- a/src/boards_pinout.h +++ b/src/boards_pinout.h @@ -75,6 +75,7 @@ #define RADIO_CS_PIN 18 // CS --> NSS #define RADIO_RST_PIN 23 #define RADIO_BUSY_PIN 26 // IRQ --> DIO0 + #define RADIO_WAKEUP_PIN RADIO_BUSY_PIN #endif diff --git a/src/sleep_utils.cpp b/src/sleep_utils.cpp new file mode 100644 index 0000000..0531591 --- /dev/null +++ b/src/sleep_utils.cpp @@ -0,0 +1,36 @@ +#include "sleep_utils.h" +#include "boards_pinout.h" + +bool lowPowerModeActive = true; +bool wakeUpFlag = false; + +namespace SLEEP_Utils { + + void handle_wakeup() { + esp_sleep_wakeup_cause_t wakeup_cause = esp_sleep_get_wakeup_cause(); + switch (wakeup_cause) { + case ESP_SLEEP_WAKEUP_TIMER: + Serial.print("Woken up by timer (Sending Beacon) \n"); + break; + case ESP_SLEEP_WAKEUP_EXT1: + Serial.print("Woken up by EXT1 (GPIO) (Packet Received)\n"); + break; + default: + Serial.print("Woken up by unknown reason\n"); + break; + } + } + + void wakeUpLoRaPacketReceived() { + wakeUpFlag = true; + } + + void setup() { + if (lowPowerModeActive) { + pinMode(RADIO_WAKEUP_PIN, INPUT); + attachInterrupt(digitalPinToInterrupt(RADIO_WAKEUP_PIN), wakeUpLoRaPacketReceived, RISING); + //LoRa_Utils::wakeRadio(); + } + } + +} \ No newline at end of file diff --git a/src/sleep_utils.h b/src/sleep_utils.h new file mode 100644 index 0000000..2c6afde --- /dev/null +++ b/src/sleep_utils.h @@ -0,0 +1,14 @@ +#ifndef SLEEP_UTILS_H_ +#define SLEEP_UTILS_H_ + +#include + +namespace SLEEP_Utils { + + void handle_wakeup(); + void wakeUpLoRaPacketReceived(); + void setup(); + +} + +#endif \ No newline at end of file