From f6a7dc71ed9018e1276b764d7f03d39ccdeedd81 Mon Sep 17 00:00:00 2001 From: shaneapowell Date: Tue, 4 May 2021 19:54:39 -0500 Subject: [PATCH] Added a simple optional callback for state changes. --- src/IotWebConf.cpp | 9 +++++++++ src/IotWebConf.h | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/IotWebConf.cpp b/src/IotWebConf.cpp index cc23edd..4fba81a 100644 --- a/src/IotWebConf.cpp +++ b/src/IotWebConf.cpp @@ -256,6 +256,11 @@ void IotWebConf::setConfigSavedCallback(std::function func) this->_configSavedCallback = func; } +void IotWebConf::setStateChangedCallback(std::function func) +{ + this->_stateChangedCallback = func; +} + void IotWebConf::setFormValidator( std::function func) { @@ -623,6 +628,10 @@ void IotWebConf::changeState(byte newState) byte oldState = this->_state; this->_state = newState; this->stateChanged(oldState, newState); + if (this->_stateChangedCallback != nullptr) + { + this->_stateChangedCallback(oldState, newState); + } #ifdef IOTWEBCONF_DEBUG_TO_SERIAL Serial.print("State changed from: "); Serial.print(oldState); diff --git a/src/IotWebConf.h b/src/IotWebConf.h index 6ea1196..22d97c1 100644 --- a/src/IotWebConf.h +++ b/src/IotWebConf.h @@ -290,6 +290,12 @@ class IotWebConf */ void setConfigSavedCallback(std::function func); + /** + * Specify a callback method, that will be called when ever the state is changed. + * See IOTWEBCONF_STATE_* for possible values + */ + void setStateChangedCallback(std::function func); + /** * Specify a callback method, that will be called when form validation is required. * If the method will return false, the configuration will not be saved. @@ -572,6 +578,7 @@ class IotWebConf std::function _wifiConnectionCallback = nullptr; std::function _configSavingCallback = nullptr; std::function _configSavedCallback = nullptr; + std::function _stateChangedCallback = nullptr; std::function _formValidator = nullptr; std::function _apConnectionHandler = &(IotWebConf::connectAp);