🪄 Formats SleepService

This commit is contained in:
Rune Harlyk
2024-07-09 20:00:42 +02:00
committed by Rune Harlyk
parent 03e21beddd
commit ba41f520b0
2 changed files with 12 additions and 24 deletions
+7 -15
View File
@@ -16,36 +16,28 @@
// Definition of static member variable // Definition of static member variable
void (*SleepService::_callbackSleep)() = nullptr; void (*SleepService::_callbackSleep)() = nullptr;
SleepService::SleepService(PsychicHttpServer *server, SleepService::SleepService(PsychicHttpServer *server, SecurityManager *securityManager)
SecurityManager *securityManager) : _server(server), : _server(server), _securityManager(securityManager) {}
_securityManager(securityManager)
{
}
void SleepService::begin() void SleepService::begin() {
{ _server->on(SLEEP_SERVICE_PATH, HTTP_POST,
_server->on(SLEEP_SERVICE_PATH,
HTTP_POST,
_securityManager->wrapRequest(std::bind(&SleepService::sleep, this, std::placeholders::_1), _securityManager->wrapRequest(std::bind(&SleepService::sleep, this, std::placeholders::_1),
AuthenticationPredicates::IS_AUTHENTICATED)); AuthenticationPredicates::IS_AUTHENTICATED));
ESP_LOGV("SleepService", "Registered POST endpoint: %s", SLEEP_SERVICE_PATH); ESP_LOGV("SleepService", "Registered POST endpoint: %s", SLEEP_SERVICE_PATH);
} }
esp_err_t SleepService::sleep(PsychicRequest *request) esp_err_t SleepService::sleep(PsychicRequest *request) {
{
request->reply(200); request->reply(200);
sleepNow(); sleepNow();
return ESP_OK; return ESP_OK;
} }
void SleepService::sleepNow() void SleepService::sleepNow() {
{
ESP_LOGI("SleepService", "Going into deep sleep now"); ESP_LOGI("SleepService", "Going into deep sleep now");
// Callback for main code sleep preparation // Callback for main code sleep preparation
if (_callbackSleep != nullptr) if (_callbackSleep != nullptr) {
{
_callbackSleep(); _callbackSleep();
} }
delay(100); delay(100);
+2 -6
View File
@@ -29,8 +29,7 @@
#define WAKEUP_SIGNAL 0 #define WAKEUP_SIGNAL 0
#endif #endif
class SleepService class SleepService {
{
public: public:
SleepService(PsychicHttpServer *server, SecurityManager *securityManager); SleepService(PsychicHttpServer *server, SecurityManager *securityManager);
@@ -38,10 +37,7 @@ public:
static void sleepNow(); static void sleepNow();
void attachOnSleepCallback(void (*callbackSleep)()) void attachOnSleepCallback(void (*callbackSleep)()) { _callbackSleep = callbackSleep; }
{
_callbackSleep = callbackSleep;
}
private: private:
PsychicHttpServer *_server; PsychicHttpServer *_server;