Skip to content
Snippets Groups Projects
Commit f8318530 authored by Moritz Perschke's avatar Moritz Perschke
Browse files

merge deep sleep changes to local

parents 0fcc3b94 17d39415
No related branches found
No related tags found
4 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!6Espnow
#include "f_deep_sleep.hpp" #include "f_deep_sleep.hpp"
#include "esp32-hal-log.h"
#include "esp_log.h"
void print_wakeup_reason(){ namespace DeepSleep {
esp_sleep_wakeup_cause_t wakeup_reason; static const std::string TAG = "DEEP_SLEEP";
wakeup_reason = esp_sleep_get_wakeup_cause();
switch(wakeup_reason) void print_wakeup_reason()
{ {
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break; esp_sleep_wakeup_cause_t wakeup_reason;
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break; wakeup_reason = esp_sleep_get_wakeup_cause();
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
}
}
switch (wakeup_reason) {
case ESP_SLEEP_WAKEUP_EXT0:
ESP_LOGD(TAG.c_str(), "Wakeup caused by external signal using RTC_IO");
break;
case ESP_SLEEP_WAKEUP_EXT1:
ESP_LOGD(TAG.c_str(), "Wakeup caused by external signal using RTC_CNTL");
break;
case ESP_SLEEP_WAKEUP_TIMER:
ESP_LOGD(TAG.c_str(), "Wakeup caused by timer");
break;
case ESP_SLEEP_WAKEUP_TOUCHPAD:
ESP_LOGD(TAG.c_str(), "Wakeup caused by touchpad");
break;
case ESP_SLEEP_WAKEUP_ULP:
ESP_LOGD(TAG.c_str(), "Wakeup caused by ULP program");
break;
default:
ESP_LOGD(TAG.c_str(), "Wakeup was not caused by deep sleep: %d\n", wakeup_reason);
break;
}
}
void deep_sleep(int time_in_sec){ void deep_sleep(int time_in_sec)
esp_sleep_enable_timer_wakeup(time_in_sec * 1000000); {
esp_deep_sleep_start(); esp_sleep_enable_timer_wakeup(time_in_sec * 1000000);
esp_deep_sleep_start();
} }
}; // namespace DeepSleep
...@@ -3,7 +3,16 @@ ...@@ -3,7 +3,16 @@
#include <Arduino.h> #include <Arduino.h>
void deep_sleep(int time_to_sleep); namespace DeepSleep {
// https://en.cppreference.com/w/cpp/language/storage_duration
// When used in a declaration at namespace scope, it specifies internal linkage.
// internal linkage. The variable can be referred to from all scopes in the current translation unit. All variables
// which are declared at file scope have this linkage, including variables declared static at file scope.
static RTC_DATA_ATTR int bootCount = 0;
void deep_sleep(int time_to_sleep_in_seconds);
void print_wakeup_reason(); void print_wakeup_reason();
} // namespace DeepSleep
#endif #endif
#include "../lib/dr26_analogue/dr26.hpp" #include "../lib/dr26_analogue/dr26.hpp"
#include "NoDataAvailableException.hpp" #include "NoDataAvailableException.hpp"
#include "esp_log.h" #include "esp_log.h"
#include "f_deep_sleep.hpp"
#include <Arduino.h> #include <Arduino.h>
#include <drs26.hpp> #include <drs26.hpp>
#include <ina219.hpp> #include <ina219.hpp>
...@@ -13,6 +14,11 @@ ForteDRS26 drs26; ...@@ -13,6 +14,11 @@ ForteDRS26 drs26;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
DeepSleep::print_wakeup_reason();
DeepSleep::bootCount++;
ESP_LOGD(TAG.c_str(), "Boot number: %d", DeepSleep::bootCount);
drs26.setup(); drs26.setup();
espnow_setup(); espnow_setup();
...@@ -22,10 +28,7 @@ void setup() ...@@ -22,10 +28,7 @@ void setup()
void loop() void loop()
{ {
out_data_drs26 data{};
try { try {
// data = drs26.readData();
auto messages = drs26.buildMessages(); auto messages = drs26.buildMessages();
for (const Message &message : messages) { for (const Message &message : messages) {
...@@ -44,4 +47,5 @@ void loop() ...@@ -44,4 +47,5 @@ void loop()
Serial.println(WiFi.macAddress()); Serial.println(WiFi.macAddress());
Serial.println("\n"); Serial.println("\n");
delay(5000); delay(5000);
DeepSleep::deep_sleep(5);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment