diff --git a/ampel-firmware/src/lib/IotWebConf/src/IotWebConf.cpp b/ampel-firmware/src/lib/IotWebConf/src/IotWebConf.cpp index b0fca3c9fe73c7781a57ee21d5ad92fe82c90b13..5ad54270e4a41a5af53549aa78c9af7b1a61b677 100644 --- a/ampel-firmware/src/lib/IotWebConf/src/IotWebConf.cpp +++ b/ampel-firmware/src/lib/IotWebConf/src/IotWebConf.cpp @@ -246,6 +246,12 @@ void IotWebConf::setConfigSavedCallback(std::function<void()> func) this->_configSavedCallback = func; } +void IotWebConf::setStateChangedCallback(std::function<void( + NetworkState oldState, NetworkState newState)> func) +{ + this->_stateChangedCallback = func; +} + void IotWebConf::setFormValidator( std::function<bool(WebRequestWrapper* webRequestWrapper)> func) { @@ -617,6 +623,10 @@ void IotWebConf::changeState(NetworkState newState) NetworkState 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); @@ -983,4 +993,4 @@ WifiAuthInfo* IotWebConf::handleConnectWifiFailure() return nullptr; } -} // end namespace \ No newline at end of file +} // end namespace diff --git a/ampel-firmware/src/lib/IotWebConf/src/IotWebConf.h b/ampel-firmware/src/lib/IotWebConf/src/IotWebConf.h index ddf708b4b1b94891e91fc8e62abcc62bf7c2a9e4..4fa4bdac8f78d68f7bb4b0add4a1243210dd9e86 100644 --- a/ampel-firmware/src/lib/IotWebConf/src/IotWebConf.h +++ b/ampel-firmware/src/lib/IotWebConf/src/IotWebConf.h @@ -293,6 +293,13 @@ public: */ void setConfigSavedCallback(std::function<void()> func); + /** + * Specify a callback method, that will be called when ever the state is changed. + * See NetworkState enum for possible values + */ + void setStateChangedCallback(std::function<void( + NetworkState oldState, NetworkState newState)> 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. @@ -600,6 +607,8 @@ private: std::function<void()> _wifiConnectionCallback = nullptr; std::function<void(int)> _configSavingCallback = nullptr; std::function<void()> _configSavedCallback = nullptr; + std::function<void(NetworkState oldState, NetworkState newState)> + _stateChangedCallback = nullptr; std::function<bool(WebRequestWrapper* webRequestWrapper)> _formValidator = nullptr; std::function<void(const char*, const char*)> _apConnectionHandler = &(IotWebConf::connectAp);