-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from ejalal/main
implement deep sleep
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <PowerManager.h> | ||
#include <ArduinoJson.h> | ||
#include "Globals.h" | ||
|
||
#define uS_TO_S_FACTOR 1000000L | ||
|
||
// The getter for the instantiated singleton instance | ||
PowerManager_ &PowerManager_::getInstance() | ||
{ | ||
static PowerManager_ instance; | ||
return instance; | ||
} | ||
|
||
// Initialize the global shared instance | ||
PowerManager_ &PowerManager = PowerManager.getInstance(); | ||
|
||
void PowerManager_::setup() | ||
{ | ||
|
||
} | ||
|
||
void PowerManager_::sleepParser(const char *json) | ||
{ | ||
StaticJsonDocument<128> doc; | ||
DeserializationError error = deserializeJson(doc, json); | ||
if (error) | ||
{ | ||
if (DEBUG_MODE) | ||
DEBUG_PRINTLN(F("Failed to parse json")); | ||
return; | ||
} | ||
|
||
if (doc.containsKey("sleep")) | ||
{ | ||
uint64_t seconds = doc["sleep"].as<uint64_t>(); | ||
sleep(seconds); | ||
} | ||
} | ||
|
||
void PowerManager_::sleep(uint64_t seconds) | ||
{ | ||
esp_sleep_enable_timer_wakeup(seconds * uS_TO_S_FACTOR); | ||
Serial.print("Going to sleep...\n"); | ||
esp_deep_sleep_start(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef PowerManager_h | ||
#define PowerManager_h | ||
|
||
#include <Arduino.h> | ||
|
||
class PowerManager_ | ||
{ | ||
private: | ||
PowerManager_() = default; | ||
public: | ||
static PowerManager_ &getInstance(); | ||
void setup(); | ||
void sleepParser(const char*); | ||
void sleep(uint64_t); | ||
}; | ||
|
||
extern PowerManager_ &PowerManager; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters