mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-05 20:38:27 +02:00
Add restore_mode to rotary_encoder (#2643)
This commit is contained in:
@@ -10,6 +10,12 @@
|
||||
namespace esphome {
|
||||
namespace rotary_encoder {
|
||||
|
||||
/// All possible restore modes for the rotary encoder
|
||||
enum RotaryEncoderRestoreMode {
|
||||
ROTARY_ENCODER_RESTORE_DEFAULT_ZERO, /// try to restore counter, otherwise set to zero
|
||||
ROTARY_ENCODER_ALWAYS_ZERO, /// do not restore counter, always set to zero
|
||||
};
|
||||
|
||||
/// All possible resolutions for the rotary encoder
|
||||
enum RotaryEncoderResolution {
|
||||
ROTARY_ENCODER_1_PULSE_PER_CYCLE =
|
||||
@@ -40,6 +46,15 @@ class RotaryEncoderSensor : public sensor::Sensor, public Component {
|
||||
void set_pin_a(InternalGPIOPin *pin_a) { pin_a_ = pin_a; }
|
||||
void set_pin_b(InternalGPIOPin *pin_b) { pin_b_ = pin_b; }
|
||||
|
||||
/** Set the restore mode of the rotary encoder.
|
||||
*
|
||||
* By default (if possible) the last known counter state is restored. Otherwise the value 0 is used.
|
||||
* Restoring the state can also be turned off.
|
||||
*
|
||||
* @param restore_mode The restore mode to use.
|
||||
*/
|
||||
void set_restore_mode(RotaryEncoderRestoreMode restore_mode);
|
||||
|
||||
/** Set the resolution of the rotary encoder.
|
||||
*
|
||||
* By default, this component will increment the counter by 1 with every A-B input cycle.
|
||||
@@ -81,6 +96,8 @@ class RotaryEncoderSensor : public sensor::Sensor, public Component {
|
||||
InternalGPIOPin *pin_b_;
|
||||
GPIOPin *pin_i_{nullptr}; /// Index pin, if this is not nullptr, the counter will reset to 0 once this pin is HIGH.
|
||||
bool publish_initial_value_;
|
||||
ESPPreferenceObject rtc_;
|
||||
RotaryEncoderRestoreMode restore_mode_{ROTARY_ENCODER_RESTORE_DEFAULT_ZERO};
|
||||
|
||||
RotaryEncoderSensorStore store_{};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user