return callback handler

This commit is contained in:
Siwat Sirichai 2023-12-31 13:32:38 +07:00
parent 5f6e586945
commit 724f8f42e9
8 changed files with 20 additions and 15 deletions

View File

@ -65,8 +65,9 @@ void AnalogIoT::setADCsPublishEnabled(bool enabled) {
adc_publish_enabled[i] = enabled; adc_publish_enabled[i] = enabled;
} }
} }
void AnalogIoT::registerADCConversionCallback(std::function<void(uint8_t, uint16_t)> callback) { uint8_t AnalogIoT::registerADCConversionCallback(std::function<void(uint8_t, uint16_t)> callback) {
this->adc_conversion_callbacks[this->adc_conversion_callback_index++] = callback; this->adc_conversion_callbacks[this->adc_conversion_callback_index] = callback;
return this->adc_conversion_callback_index++;
} }
void AnalogIoT::deregisterADCConversionCallback(uint8_t handler) { void AnalogIoT::deregisterADCConversionCallback(uint8_t handler) {
this->adc_conversion_callbacks.erase(handler); this->adc_conversion_callbacks.erase(handler);

View File

@ -25,7 +25,7 @@ class AnalogIoT : public IoTComponent {
void publishDACValue(uint8_t pin); void publishDACValue(uint8_t pin);
void setADCsPublishInterval(uint32_t interval); void setADCsPublishInterval(uint32_t interval);
void setADCsPublishEnabled(bool enabled); void setADCsPublishEnabled(bool enabled);
void registerADCConversionCallback(std::function<void(uint8_t, uint16_t)> callback); uint8_t registerADCConversionCallback(std::function<void(uint8_t, uint16_t)> callback);
void deregisterADCConversionCallback(uint8_t handler); void deregisterADCConversionCallback(uint8_t handler);
void setADCConversionInterval(uint8_t pin, uint16_t interval); void setADCConversionInterval(uint8_t pin, uint16_t interval);
void setADCConversionEnabled(uint8_t pin, bool enabled); void setADCConversionEnabled(uint8_t pin, bool enabled);

View File

@ -137,9 +137,10 @@ void ClimateCard::setFanSpeed(uint8_t fan_speed)
saveStateToFRAM(); saveStateToFRAM();
} }
void ClimateCard::registerChangeCallback(std::function<void(uint8_t, uint8_t, uint8_t)> callback) uint8_t ClimateCard::registerChangeCallback(std::function<void(uint8_t, uint8_t, uint8_t)> callback)
{ {
callbacks[callbacks_handler_count++] = callback; callbacks[callbacks_handler_count] = callback;
return callbacks_handler_count++;
} }
uint8_t ClimateCard::getType() uint8_t ClimateCard::getType()
@ -237,9 +238,10 @@ uint8_t ClimateCard::getFanSpeed()
return state.ac_fan_speed; return state.ac_fan_speed;
} }
void ClimateCard::registerSensorCallback(std::function<void(float, float)> callback) uint8_t ClimateCard::registerSensorCallback(std::function<void(float, float)> callback)
{ {
sensor_callbacks[sensor_callbacks_handler_count++] = callback; sensor_callbacks[sensor_callbacks_handler_count] = callback;
return sensor_callbacks_handler_count++;
} }
void ClimateCard::unregisterChangeCallback(uint8_t handler) void ClimateCard::unregisterChangeCallback(uint8_t handler)

View File

@ -58,8 +58,8 @@ class ClimateCard : public ExpansionCard {
float getRoomTemperature(); float getRoomTemperature();
float getHumidity(); float getHumidity();
uint8_t getSensorType(); uint8_t getSensorType();
void registerChangeCallback(std::function<void(uint8_t, uint8_t, uint8_t)> callback); uint8_t registerChangeCallback(std::function<void(uint8_t, uint8_t, uint8_t)> callback);
void registerSensorCallback(std::function<void(float, float)> callback); uint8_t registerSensorCallback(std::function<void(float, float)> callback);
void unregisterChangeCallback(uint8_t handler); void unregisterChangeCallback(uint8_t handler);
void unregisterSensorCallback(uint8_t handler); void unregisterSensorCallback(uint8_t handler);
uint8_t getType(); uint8_t getType();

View File

@ -157,9 +157,10 @@ uint8_t DigitalInputCard::getInputBufferB()
return inputBufferB_rearranged; return inputBufferB_rearranged;
} }
// Register a callback function to be called when a pin changes // Register a callback function to be called when a pin changes
void DigitalInputCard::registerCallback(std::function<void(uint8_t, bool)> callback) uint8_t DigitalInputCard::registerCallback(std::function<void(uint8_t, bool)> callback)
{ {
callbacks[this->callbacks_handler_index++] = callback; callbacks[this->callbacks_handler_index] = callback;
return this->callbacks_handler_index++;
} }
// Refresh the input buffer for bank A // Refresh the input buffer for bank A

View File

@ -26,7 +26,7 @@ class DigitalInputCard : public ExpansionCard {
// Set the debounce time for the specified pin // Set the debounce time for the specified pin
void setDebounceTime(uint8_t pin, uint32_t debounceTime); void setDebounceTime(uint8_t pin, uint32_t debounceTime);
// Register a callback function to be called when a pin changes // Register a callback function to be called when a pin changes
void registerCallback(std::function<void(uint8_t, bool)> callback); uint8_t registerCallback(std::function<void(uint8_t, bool)> callback);
// Unregister the callback function // Unregister the callback function
void unregisterCallback(uint8_t handler); void unregisterCallback(uint8_t handler);
// Load a new pin map // Load a new pin map

View File

@ -102,8 +102,9 @@ void DigitalOutputCard::setValue(uint8_t pin, uint16_t value) {
} }
} }
void DigitalOutputCard::registerChangeCallback(std::function<void(uint8_t, bool, uint16_t)> callback) { uint8_t DigitalOutputCard::registerChangeCallback(std::function<void(uint8_t, bool, uint16_t)> callback) {
this->change_callbacks[this->callbacks_handler_index++] = callback; this->change_callbacks[this->callbacks_handler_index] = callback;
return this->callbacks_handler_index++;
} }
void DigitalOutputCard::deregisterChangeCallback(uint8_t handler) { void DigitalOutputCard::deregisterChangeCallback(uint8_t handler) {

View File

@ -48,7 +48,7 @@ public:
// Get the pwm value of the specified pin // Get the pwm value of the specified pin
uint16_t getValue(uint8_t pin); uint16_t getValue(uint8_t pin);
// Register a callback function that will be called when the state of a pin changes // Register a callback function that will be called when the state of a pin changes
void registerChangeCallback(std::function<void(uint8_t, bool, uint16_t)> callback); uint8_t registerChangeCallback(std::function<void(uint8_t, bool, uint16_t)> callback);
// Deregister the callback function // Deregister the callback function
void deregisterChangeCallback(uint8_t handler); void deregisterChangeCallback(uint8_t handler);
// Load a new pin map // Load a new pin map