From 956fd05cf91ef9e8a6bde9add58605b84ca6d932 Mon Sep 17 00:00:00 2001 From: Paul Wieland Date: Mon, 1 Jul 2024 21:39:22 -0400 Subject: [PATCH 1/2] Auto detect obstruction sensors use toggle action instead of close if no sensors detected --- components/ratgdo/ratgdo.cpp | 31 ++++++++++++------------------- components/ratgdo/ratgdo.h | 2 +- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index a9f49c8..1cd837f 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -38,15 +38,9 @@ namespace ratgdo { this->input_gdo_pin_->setup(); this->input_gdo_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); - if (this->input_obst_pin_ == nullptr) { - // Our base.yaml is always going to set this so we check for 0 - // as well to avoid a breaking change. - this->obstruction_from_status_ = true; - } else { - this->input_obst_pin_->setup(); - this->input_obst_pin_->pin_mode(gpio::FLAG_INPUT); - this->input_obst_pin_->attach_interrupt(RATGDOStore::isr_obstruction, &this->isr_store_, gpio::INTERRUPT_FALLING_EDGE); - } + this->input_obst_pin_->setup(); + this->input_obst_pin_->pin_mode(gpio::FLAG_INPUT); + this->input_obst_pin_->attach_interrupt(RATGDOStore::isr_obstruction, &this->isr_store_, gpio::INTERRUPT_FALLING_EDGE); this->protocol_->setup(this, &App.scheduler, this->input_gdo_pin_, this->output_gdo_pin_); @@ -76,9 +70,7 @@ namespace ratgdo { void RATGDOComponent::loop() { - if (!this->obstruction_from_status_) { - this->obstruction_loop(); - } + this->obstruction_loop(); this->protocol_->loop(); } @@ -87,11 +79,7 @@ namespace ratgdo { ESP_LOGCONFIG(TAG, "Setting up RATGDO..."); LOG_PIN(" Output GDO Pin: ", this->output_gdo_pin_); LOG_PIN(" Input GDO Pin: ", this->input_gdo_pin_); - if (this->obstruction_from_status_) { - ESP_LOGCONFIG(TAG, " Input Obstruction Pin: not used, will detect from GDO status"); - } else { - LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_); - } + LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_); this->protocol_->dump_config(); } @@ -218,7 +206,7 @@ namespace ratgdo { void RATGDOComponent::received(const ObstructionState obstruction_state) { - if (this->obstruction_from_status_) { + if (!this->obstruction_sensor_detected_) { ESP_LOGD(TAG, "Obstruction: state=%s", ObstructionState_to_string(*this->obstruction_state)); this->obstruction_state = obstruction_state; @@ -378,6 +366,7 @@ namespace ratgdo { // check to see if we got more then PULSES_LOWER_LIMIT pulses if (this->isr_store_.obstruction_low_count > PULSES_LOWER_LIMIT) { this->obstruction_state = ObstructionState::CLEAR; + this->obstruction_sensor_detected_ = true; } else if (this->isr_store_.obstruction_low_count == 0) { // if there have been no pulses the line is steady high or low if (!this->input_obst_pin_->digital_read()) { @@ -471,7 +460,11 @@ namespace ratgdo { return; } - this->door_action(DoorAction::CLOSE); + if(this->obstruction_sensor_detected_){ + this->door_action(DoorAction::CLOSE); + }else{ + this->door_action(DoorAction::TOGGLE); + } if (*this->closing_duration > 0) { // query state in case we don't get a status message diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index fbb92b1..8cc1acd 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -176,7 +176,7 @@ namespace ratgdo { protected: RATGDOStore isr_store_ {}; protocol::Protocol* protocol_; - bool obstruction_from_status_ { false }; + bool obstruction_sensor_detected_ { false }; InternalGPIOPin* output_gdo_pin_; InternalGPIOPin* input_gdo_pin_; From 93abfa0b540f4c2f7b6e77ae59f6e3466be3055f Mon Sep 17 00:00:00 2001 From: Paul Wieland Date: Tue, 2 Jul 2024 10:21:35 -0400 Subject: [PATCH 2/2] Toggle for close only when door is open --- components/ratgdo/ratgdo.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 1cd837f..ae7b08f 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -461,8 +461,9 @@ namespace ratgdo { } if(this->obstruction_sensor_detected_){ - this->door_action(DoorAction::CLOSE); - }else{ + this->door_action(DoorAction::CLOSE); + }else if(*this->door_state == DoorState::OPEN){ + ESP_LOGD(TAG, "No obstruction sensors detected. Close using TOGGLE."); this->door_action(DoorAction::TOGGLE); }