remote var callback docs

This commit is contained in:
Siwat Sirichai 2024-02-13 01:00:20 +07:00
parent 57dfa30cf0
commit 1dd0862834
1 changed files with 12 additions and 0 deletions

View File

@ -135,10 +135,22 @@ void RemoteVariable::setValue(const char* value) {
this->iot->publish(this->setValueTopic, value);
}
/**
* @brief Register a callback for value change
* This method will be called when the value of the variable changes on the remote device
* @param callback The callback function
* @return uint8_t The handler for the callback
*/
uint8_t RemoteVariable::registerCallback(std::function<void(char*)> callback) {
this->valueChangeCallback[this->valueChangeCallbackCount] = callback;
return valueChangeCallbackCount++;
}
/**
* @brief Unregister a callback
* This method is used to unregister a callback
* @param handler The handler of the callback
*/
void RemoteVariable::unregisterCallback(uint8_t handler) {
this->valueChangeCallback.erase(handler);
}