change callbacks to vector
This commit is contained in:
parent
71475ef2f1
commit
011710fe82
19 changed files with 207 additions and 109 deletions
|
@ -48,6 +48,10 @@ void AnalogIoT::publishADC(uint8_t pin) {
|
|||
this->publishRelative(topic, payload);
|
||||
delete[] topic;
|
||||
delete[] payload;
|
||||
// Call all callbacks
|
||||
for (int i = 0; i < this->adc_conversion_callbacks.size(); i++) {
|
||||
this->adc_conversion_callbacks[i](pin, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
void AnalogIoT::setADCsPublishInterval(uint32_t interval) {
|
||||
|
@ -60,18 +64,17 @@ void AnalogIoT::setADCsPublishEnabled(bool enabled) {
|
|||
adc_publish_enabled[i] = enabled;
|
||||
}
|
||||
}
|
||||
void AnalogIoT::registerDACChangeCallback(std::function<void(uint8_t, uint16_t)> callback) {
|
||||
dac_change_callback = callback;
|
||||
}
|
||||
void AnalogIoT::deregisterDACChangeCallback() {
|
||||
dac_change_callback = NULL;
|
||||
}
|
||||
void AnalogIoT::registerADCConversionCallback(std::function<void(uint8_t, uint16_t)> callback) {
|
||||
adc_conversion_callback = callback;
|
||||
}
|
||||
void AnalogIoT::deregisterADCConversionCallback() {
|
||||
adc_conversion_callback = NULL;
|
||||
this->adc_conversion_callbacks.push_back(callback);
|
||||
}
|
||||
// void AnalogIoT::deregisterADCConversionCallback(std::function<void(uint8_t, uint16_t)> callback) {
|
||||
// for (int i = 0; i < this->adc_conversion_callbacks.size(); i++) {
|
||||
// if (this->adc_conversion_callbacks[i].target<void(uint8_t, uint16_t)>() == callback.target<void(uint8_t, uint16_t)>()) {
|
||||
// this->adc_conversion_callbacks.erase(this->adc_conversion_callbacks.begin() + i);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
void AnalogIoT::setADCConversionInterval(uint8_t pin, uint16_t interval) {
|
||||
adc_conversion_interval[pin] = interval;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue