mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 10:00:36 +01:00
Add state listeners to rotary_encoder
(#6035)
This commit is contained in:
parent
501973e07b
commit
dfb14fc6ea
@ -226,6 +226,7 @@ void RotaryEncoderSensor::loop() {
|
||||
}
|
||||
this->store_.last_read = counter;
|
||||
this->publish_state(counter);
|
||||
this->listeners_.call(counter);
|
||||
this->publish_initial_value_ = false;
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,8 @@ class RotaryEncoderSensor : public sensor::Sensor, public Component {
|
||||
this->on_anticlockwise_callback_.add(std::move(callback));
|
||||
}
|
||||
|
||||
void register_listener(std::function<void(uint32_t)> listener) { this->listeners_.add(std::move(listener)); }
|
||||
|
||||
protected:
|
||||
InternalGPIOPin *pin_a_;
|
||||
InternalGPIOPin *pin_b_;
|
||||
@ -102,8 +104,9 @@ class RotaryEncoderSensor : public sensor::Sensor, public Component {
|
||||
|
||||
RotaryEncoderSensorStore store_{};
|
||||
|
||||
CallbackManager<void()> on_clockwise_callback_;
|
||||
CallbackManager<void()> on_anticlockwise_callback_;
|
||||
CallbackManager<void()> on_clockwise_callback_{};
|
||||
CallbackManager<void()> on_anticlockwise_callback_{};
|
||||
CallbackManager<void(int32_t)> listeners_{};
|
||||
};
|
||||
|
||||
template<typename... Ts> class RotaryEncoderSetValueAction : public Action<Ts...> {
|
||||
|
Loading…
Reference in New Issue
Block a user