mirror of
https://github.com/esphome/esphome.git
synced 2025-09-14 09:12:19 +01:00
Avoid polling for GPIO binary sensors when possible
This commit is contained in:
@@ -19,11 +19,12 @@ void GPIOBinarySensorStore::setup(InternalGPIOPin *pin, gpio::InterruptType type
|
|||||||
this->pin_ = pin;
|
this->pin_ = pin;
|
||||||
pin->setup();
|
pin->setup();
|
||||||
this->isr_pin_ = pin->to_isr();
|
this->isr_pin_ = pin->to_isr();
|
||||||
{
|
|
||||||
InterruptLock lock;
|
// Read initial state
|
||||||
this->last_state_ = pin->digital_read();
|
this->last_state_ = pin->digital_read();
|
||||||
this->state_ = this->last_state_;
|
this->state_ = this->last_state_;
|
||||||
}
|
|
||||||
|
// Attach interrupt - from this point on, any changes will be caught by the interrupt
|
||||||
pin->attach_interrupt(&GPIOBinarySensorStore::gpio_intr, this, type);
|
pin->attach_interrupt(&GPIOBinarySensorStore::gpio_intr, this, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user