WordClockESP/src/InformationService.cpp

42 lines
1.1 KiB
C++

//
// Created by lukas on 09.03.21.
//
#include "InformationService.h"
InformationService::InformationService(AsyncWebServer* server, SecurityManager* securityManager) :
_webSocket(InformationState::read,
InformationState::update,
this,
server,
INFORMATION_SETTINGS_SOCKET_PATH,
securityManager,
AuthenticationPredicates::IS_AUTHENTICATED),
clock() {
// configure settings service update handler to update LED state
addUpdateHandler([&](const String& originId) { onConfigUpdated(); }, false);
}
void InformationService::begin() {
_state.wordClockOn = DEFAULT_CLOCK_STATE;
_state.twentyAfterSyntax = true;
_state.uhrAlwaysOn = false;
onConfigUpdated();
clock.init();
}
void InformationService::onConfigUpdated() {
// digitalWrite(LED_PIN, _state.ledOn ? LED_ON : LED_OFF);
if (_state.wordClockOn) {
clock.turnOn();
} else {
clock.turnOff();
}
clock.useAlwaysOnUhrSyntax(_state.uhrAlwaysOn);
clock.useTwentyAfterSyntax(_state.twentyAfterSyntax);
clock.update();
}