mirror of
https://github.com/esphome/esphome.git
synced 2025-09-21 20:52:20 +01:00
Avoid polling for GPIO binary sensors when possible
This commit is contained in:
@@ -16,7 +16,6 @@ void IRAM_ATTR GPIOBinarySensorStore::gpio_intr(GPIOBinarySensorStore *arg) {
|
||||
}
|
||||
|
||||
void GPIOBinarySensorStore::setup(InternalGPIOPin *pin, gpio::InterruptType type) {
|
||||
this->pin_ = pin;
|
||||
pin->setup();
|
||||
this->isr_pin_ = pin->to_isr();
|
||||
|
||||
@@ -28,19 +27,6 @@ void GPIOBinarySensorStore::setup(InternalGPIOPin *pin, gpio::InterruptType type
|
||||
pin->attach_interrupt(&GPIOBinarySensorStore::gpio_intr, this, type);
|
||||
}
|
||||
|
||||
void GPIOBinarySensorStore::detach() {
|
||||
if (this->pin_ != nullptr) {
|
||||
this->pin_->detach_interrupt();
|
||||
this->pin_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
GPIOBinarySensor::~GPIOBinarySensor() {
|
||||
if (this->use_interrupt_) {
|
||||
this->store_.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void GPIOBinarySensor::setup() {
|
||||
if (this->use_interrupt_ && !this->pin_->is_internal()) {
|
||||
ESP_LOGW(TAG, "Interrupts not supported for this pin type, falling back to polling");
|
||||
|
@@ -12,7 +12,6 @@ namespace gpio {
|
||||
class GPIOBinarySensorStore {
|
||||
public:
|
||||
void setup(InternalGPIOPin *pin, gpio::InterruptType type);
|
||||
void detach();
|
||||
|
||||
static void gpio_intr(GPIOBinarySensorStore *arg);
|
||||
|
||||
@@ -29,7 +28,6 @@ class GPIOBinarySensorStore {
|
||||
}
|
||||
|
||||
protected:
|
||||
InternalGPIOPin *pin_{nullptr};
|
||||
ISRInternalGPIOPin isr_pin_;
|
||||
volatile bool state_{false};
|
||||
volatile bool last_state_{false};
|
||||
@@ -38,8 +36,6 @@ class GPIOBinarySensorStore {
|
||||
|
||||
class GPIOBinarySensor : public binary_sensor::BinarySensor, public Component {
|
||||
public:
|
||||
~GPIOBinarySensor();
|
||||
|
||||
void set_pin(GPIOPin *pin) { pin_ = pin; }
|
||||
void set_use_interrupt(bool use_interrupt) { use_interrupt_ = use_interrupt; }
|
||||
void set_interrupt_type(gpio::InterruptType type) { interrupt_type_ = type; }
|
||||
|
Reference in New Issue
Block a user