Detect "not connected to GDO" condition (#143)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Marius Muja 2023-12-15 22:26:30 -08:00 committed by GitHub
parent 2ea7ca6e3e
commit 892c4e2872
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

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

View File

@ -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_ {};