mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 17:27:45 +01:00
Fix Rotary Encoder (#580)
Fixes https://github.com/esphome/issues/issues/360
This commit is contained in:
parent
ebb5d58c14
commit
2432901974
2 changed files with 5 additions and 5 deletions
|
@ -101,15 +101,15 @@ void RotaryEncoderSensor::setup() {
|
||||||
ESP_LOGCONFIG(TAG, "Setting up Rotary Encoder '%s'...", this->name_.c_str());
|
ESP_LOGCONFIG(TAG, "Setting up Rotary Encoder '%s'...", this->name_.c_str());
|
||||||
this->pin_a_->setup();
|
this->pin_a_->setup();
|
||||||
this->store_.pin_a = this->pin_a_->to_isr();
|
this->store_.pin_a = this->pin_a_->to_isr();
|
||||||
this->pin_a_->attach_interrupt(RotaryEncoderSensorStore::gpio_intr, &this->store_, CHANGE);
|
|
||||||
|
|
||||||
this->pin_b_->setup();
|
this->pin_b_->setup();
|
||||||
this->store_.pin_b = this->pin_b_->to_isr();
|
this->store_.pin_b = this->pin_b_->to_isr();
|
||||||
this->pin_b_->attach_interrupt(RotaryEncoderSensorStore::gpio_intr, &this->store_, CHANGE);
|
|
||||||
|
|
||||||
if (this->pin_i_ != nullptr) {
|
if (this->pin_i_ != nullptr) {
|
||||||
this->pin_i_->setup();
|
this->pin_i_->setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->pin_a_->attach_interrupt(RotaryEncoderSensorStore::gpio_intr, &this->store_, CHANGE);
|
||||||
|
this->pin_b_->attach_interrupt(RotaryEncoderSensorStore::gpio_intr, &this->store_, CHANGE);
|
||||||
}
|
}
|
||||||
void RotaryEncoderSensor::dump_config() {
|
void RotaryEncoderSensor::dump_config() {
|
||||||
LOG_SENSOR("", "Rotary Encoder", this);
|
LOG_SENSOR("", "Rotary Encoder", this);
|
||||||
|
|
|
@ -36,7 +36,7 @@ CONFIG_SCHEMA = cv.All(sensor.sensor_schema(UNIT_STEPS, ICON_ROTATE_RIGHT, 0).ex
|
||||||
pins.validate_has_interrupt),
|
pins.validate_has_interrupt),
|
||||||
cv.Required(CONF_PIN_B): cv.All(pins.internal_gpio_input_pin_schema,
|
cv.Required(CONF_PIN_B): cv.All(pins.internal_gpio_input_pin_schema,
|
||||||
pins.validate_has_interrupt),
|
pins.validate_has_interrupt),
|
||||||
cv.Optional(CONF_PIN_RESET): pins.internal_gpio_input_pin_schema,
|
cv.Optional(CONF_PIN_RESET): pins.internal_gpio_output_pin_schema,
|
||||||
cv.Optional(CONF_RESOLUTION, default=1): cv.enum(RESOLUTIONS, int=True),
|
cv.Optional(CONF_RESOLUTION, default=1): cv.enum(RESOLUTIONS, int=True),
|
||||||
cv.Optional(CONF_MIN_VALUE): cv.int_,
|
cv.Optional(CONF_MIN_VALUE): cv.int_,
|
||||||
cv.Optional(CONF_MAX_VALUE): cv.int_,
|
cv.Optional(CONF_MAX_VALUE): cv.int_,
|
||||||
|
@ -50,7 +50,7 @@ def to_code(config):
|
||||||
pin_a = yield cg.gpio_pin_expression(config[CONF_PIN_A])
|
pin_a = yield cg.gpio_pin_expression(config[CONF_PIN_A])
|
||||||
cg.add(var.set_pin_a(pin_a))
|
cg.add(var.set_pin_a(pin_a))
|
||||||
pin_b = yield cg.gpio_pin_expression(config[CONF_PIN_B])
|
pin_b = yield cg.gpio_pin_expression(config[CONF_PIN_B])
|
||||||
cg.add(var.set_pin_a(pin_b))
|
cg.add(var.set_pin_b(pin_b))
|
||||||
|
|
||||||
if CONF_PIN_RESET in config:
|
if CONF_PIN_RESET in config:
|
||||||
pin_i = yield cg.gpio_pin_expression(config[CONF_PIN_RESET])
|
pin_i = yield cg.gpio_pin_expression(config[CONF_PIN_RESET])
|
||||||
|
|
Loading…
Reference in a new issue