starting sleep code

This commit is contained in:
richonguzman 2024-07-07 11:09:09 -04:00
parent 1e75dca592
commit 094565aefa
3 changed files with 51 additions and 0 deletions

View File

@ -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

36
src/sleep_utils.cpp Normal file
View File

@ -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();
}
}
}

14
src/sleep_utils.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef SLEEP_UTILS_H_
#define SLEEP_UTILS_H_
#include <Arduino.h>
namespace SLEEP_Utils {
void handle_wakeup();
void wakeUpLoRaPacketReceived();
void setup();
}
#endif