🪄 Formats SleepService
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -29,25 +29,21 @@
|
|||||||
#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);
|
||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
static void sleepNow();
|
static void sleepNow();
|
||||||
|
|
||||||
void attachOnSleepCallback(void (*callbackSleep)())
|
void attachOnSleepCallback(void (*callbackSleep)()) { _callbackSleep = callbackSleep; }
|
||||||
{
|
|
||||||
_callbackSleep = callbackSleep;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PsychicHttpServer *_server;
|
PsychicHttpServer *_server;
|
||||||
SecurityManager *_securityManager;
|
SecurityManager *_securityManager;
|
||||||
esp_err_t sleep(PsychicRequest *request);
|
esp_err_t sleep(PsychicRequest *request);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void (*_callbackSleep)();
|
static void (*_callbackSleep)();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user