From 892c4e2872f120d84b172a6f130c706ceec9930b Mon Sep 17 00:00:00 2001 From: Marius Muja Date: Fri, 15 Dec 2023 22:26:30 -0800 Subject: [PATCH] Detect "not connected to GDO" condition (#143) Co-authored-by: J. Nick Koston --- components/ratgdo/ratgdo.cpp | 23 +++++++++++++++++++---- components/ratgdo/ratgdo.h | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index b6ad370..66fb3fd 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -446,9 +446,13 @@ namespace ratgdo { if (!this->transmit_pending_) { // have an untransmitted packet this->encode_packet(command, data, increment, this->tx_packet_); } else { - // unlikely this would happed, we're ensuring any pending packet + // unlikely this would happed (unless not connected to GDO), we're ensuring any pending packet // is transmitted each loop before doing anyting else - ESP_LOGW(TAG, "Have untransmitted packet, ignoring command: %s", Command_to_string(command)); + if (this->transmit_pending_start_ > 0) { + ESP_LOGW(TAG, "Have untransmitted packet, ignoring command: %s", Command_to_string(command)); + } else { + ESP_LOGW(TAG, "Not connected to GDO, ignoring command: %s", Command_to_string(command)); + } } this->transmit_packet(); } @@ -462,10 +466,20 @@ namespace ratgdo { bool RATGDOComponent::transmit_packet() { auto now = micros(); + while (micros() - now < 1300) { if (this->input_gdo_pin_->digital_read()) { - ESP_LOGD(TAG, "Collision detected, waiting to send packet"); - this->transmit_pending_ = true; + if (!this->transmit_pending_) { + this->transmit_pending_ = true; + this->transmit_pending_start_ = millis(); + ESP_LOGD(TAG, "Collision detected, waiting to send packet"); + } else { + if (millis() - this->transmit_pending_start_ < 5000) { + ESP_LOGD(TAG, "Collision detected, waiting to send packet"); + } else { + this->transmit_pending_start_ = 0; // to indicate GDO not connected state + } + } return false; } delayMicroseconds(100); @@ -484,6 +498,7 @@ namespace ratgdo { this->sw_serial_.write(this->tx_packet_, PACKET_LENGTH); this->transmit_pending_ = false; + this->transmit_pending_start_ = 0; this->command_sent(); return true; } diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index a42af7e..147b012 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -195,6 +195,7 @@ namespace ratgdo { protected: // tx data bool transmit_pending_ { false }; + uint32_t transmit_pending_start_ { 0 }; WirePacket tx_packet_; RATGDOStore isr_store_ {};