Skip to content
Snippets Groups Projects
Verified Commit 14af8745 authored by Zoe Michaela Dietmar Pfister's avatar Zoe Michaela Dietmar Pfister :gay_pride_flag:
Browse files

refactor f_deep_sleep.cpp into its own namespace, add boot counter, move to...

refactor f_deep_sleep.cpp into its own namespace, add boot counter, move to ESPLOG for wakeup reason
parent 20ebf25a
No related branches found
No related tags found
5 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!11refactor f_deep_sleep.cpp into its own namespace, add boot counter, move to...,!9Deep Sleep Namespace
#include "f_deep_sleep.hpp"
#include "esp32-hal-log.h"
#include "esp_log.h"
void print_wakeup_reason(){
esp_sleep_wakeup_cause_t wakeup_reason;
namespace DeepSleep {
static const std::string TAG = "DEEP_SLEEP";
wakeup_reason = esp_sleep_get_wakeup_cause();
switch(wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
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;
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;
}
}
void print_wakeup_reason()
{
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
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){
esp_sleep_enable_timer_wakeup(time_in_sec * 1000000);
esp_deep_sleep_start();
void deep_sleep(int time_in_sec)
{
esp_sleep_enable_timer_wakeup(time_in_sec * 1000000);
esp_deep_sleep_start();
}
}; // namespace DeepSleep
......@@ -3,7 +3,16 @@
#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();
} // namespace DeepSleep
#endif
#include "../lib/dr26_analogue/dr26.hpp"
#include "NoDataAvailableException.hpp"
#include "esp_log.h"
#include "f_deep_sleep.hpp"
#include <Arduino.h>
#include <drs26.hpp>
#include <ina219.hpp>
......@@ -13,6 +14,11 @@ ForteDRS26 drs26;
void setup()
{
Serial.begin(115200);
DeepSleep::print_wakeup_reason();
DeepSleep::bootCount++;
ESP_LOGD(TAG.c_str(), "Boot number: %d", DeepSleep::bootCount);
drs26.setup();
espnow_setup();
......@@ -22,10 +28,7 @@ void setup()
void loop()
{
out_data_drs26 data{};
try {
// data = drs26.readData();
auto messages = drs26.buildMessages();
for (const Message &message : messages) {
......@@ -36,9 +39,5 @@ void loop()
std::cerr << e.what() << '\n';
}
ESP_LOGE(TAG.c_str(), "Sensor Circumference: ");
// log_e("Temperature: ");
// log_e("Id: ");
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