Commit 1264c29c authored by Eric Duminil's avatar Eric Duminil
Browse files

Trying StateChangedCallback

parent 90f80906
......@@ -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
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment