Fix Rotary Encoder (#580)

Fixes https://github.com/esphome/issues/issues/360
This commit is contained in:
Otto Winter 2019-05-31 10:37:40 +02:00 committed by GitHub
parent 01db114724
commit 3012fee013
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -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);

View file

@ -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])