From ba41f520b0a8405081960fbfc497bdc258aaba81 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Tue, 9 Jul 2024 20:00:42 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=84=20Formats=20SleepService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp32/lib/ESP32-sveltekit/SleepService.cpp | 22 +++++++--------------- esp32/lib/ESP32-sveltekit/SleepService.h | 14 +++++--------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/esp32/lib/ESP32-sveltekit/SleepService.cpp b/esp32/lib/ESP32-sveltekit/SleepService.cpp index 04857f4..00dadc7 100644 --- a/esp32/lib/ESP32-sveltekit/SleepService.cpp +++ b/esp32/lib/ESP32-sveltekit/SleepService.cpp @@ -16,36 +16,28 @@ // Definition of static member variable void (*SleepService::_callbackSleep)() = nullptr; -SleepService::SleepService(PsychicHttpServer *server, - SecurityManager *securityManager) : _server(server), - _securityManager(securityManager) -{ -} +SleepService::SleepService(PsychicHttpServer *server, SecurityManager *securityManager) + : _server(server), _securityManager(securityManager) {} -void SleepService::begin() -{ - _server->on(SLEEP_SERVICE_PATH, - HTTP_POST, +void SleepService::begin() { + _server->on(SLEEP_SERVICE_PATH, HTTP_POST, _securityManager->wrapRequest(std::bind(&SleepService::sleep, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED)); 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); sleepNow(); return ESP_OK; } -void SleepService::sleepNow() -{ +void SleepService::sleepNow() { ESP_LOGI("SleepService", "Going into deep sleep now"); // Callback for main code sleep preparation - if (_callbackSleep != nullptr) - { + if (_callbackSleep != nullptr) { _callbackSleep(); } delay(100); diff --git a/esp32/lib/ESP32-sveltekit/SleepService.h b/esp32/lib/ESP32-sveltekit/SleepService.h index f9514ba..3b02a7c 100644 --- a/esp32/lib/ESP32-sveltekit/SleepService.h +++ b/esp32/lib/ESP32-sveltekit/SleepService.h @@ -29,25 +29,21 @@ #define WAKEUP_SIGNAL 0 #endif -class SleepService -{ -public: +class SleepService { + public: SleepService(PsychicHttpServer *server, SecurityManager *securityManager); void begin(); static void sleepNow(); - void attachOnSleepCallback(void (*callbackSleep)()) - { - _callbackSleep = callbackSleep; - } + void attachOnSleepCallback(void (*callbackSleep)()) { _callbackSleep = callbackSleep; } -private: + private: PsychicHttpServer *_server; SecurityManager *_securityManager; esp_err_t sleep(PsychicRequest *request); -protected: + protected: static void (*_callbackSleep)(); };