From 3518d1013e572733e5411a5f9bfd155e32fbec0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Tue, 29 May 2018 23:39:24 +0200 Subject: [PATCH] RELOAD terminal command forces modules to reload settings from config (#816) --- code/espurna/settings.ino | 5 +++++ code/espurna/ws.ino | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/code/espurna/settings.ino b/code/espurna/settings.ino index ce98370a..9d5767b3 100644 --- a/code/espurna/settings.ino +++ b/code/espurna/settings.ino @@ -269,6 +269,11 @@ void _settingsInitCommands() { DEBUG_MSG_P(PSTR("+OK\n")); }); + settingsRegisterCommand(F("RELOAD"), [](Embedis* e) { + wsReload(); + DEBUG_MSG_P(PSTR("+OK\n")); + }); + settingsRegisterCommand(F("RESET"), [](Embedis* e) { DEBUG_MSG_P(PSTR("+OK\n")); deferredReset(100, CUSTOM_RESET_TERMINAL); diff --git a/code/espurna/ws.ino b/code/espurna/ws.ino index 265172f3..68a18ba2 100644 --- a/code/espurna/ws.ino +++ b/code/espurna/ws.ino @@ -205,9 +205,7 @@ void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) { if (save) { // Callbacks - for (unsigned char i = 0; i < _ws_on_after_parse_callbacks.size(); i++) { - (_ws_on_after_parse_callbacks[i])(); - } + wsReload(); // This should got to callback as well // but first change management has to be in place @@ -434,6 +432,15 @@ void wsConfigure() { #endif } +// This method being public makes +// _ws_on_after_parse_callbacks strange here, +// it should belong somewhere else. +void wsReload() { + for (unsigned char i = 0; i < _ws_on_after_parse_callbacks.size(); i++) { + (_ws_on_after_parse_callbacks[i])(); + } +} + void wsSetup() { _ws.onEvent(_wsEvent); wsConfigure();