From 15f5eab643fc47e32d67791db48c797d88dbddee Mon Sep 17 00:00:00 2001 From: Marius Muja Date: Fri, 12 Jan 2024 16:56:26 -0800 Subject: [PATCH] More attempts to get lock/unlock to work --- components/ratgdo/secplus1.cpp | 29 ++++++++++++++++++++++------- components/ratgdo/secplus1.h | 5 +++-- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/components/ratgdo/secplus1.cpp b/components/ratgdo/secplus1.cpp index d6a5c62..f751c4d 100644 --- a/components/ratgdo/secplus1.cpp +++ b/components/ratgdo/secplus1.cpp @@ -106,7 +106,11 @@ namespace secplus1 { if (action == LockAction::TOGGLE || (action == LockAction::LOCK && this->lock_state == LockState::UNLOCKED) || (action == LockAction::UNLOCK && this->lock_state == LockState::LOCKED)) { - this->transmit_packet(toggle_lock); + if (this->is_0x37_panel_) { + this->request_lock_toggle_ = true; + } else { + this->transmit_packet(toggle_lock); + } } } @@ -276,10 +280,21 @@ namespace secplus1 { this->ratgdo_->received(door_state); this->ratgdo_->received(ButtonState::RELEASED); } - else if (cmd.type == CommandType::DOOR_STATUS_37) { + else if (cmd.type == CommandType::DOOR_STATUS_0x37) { this->is_0x37_panel_ = true; - // inject door status request - this->sw_serial_.write(0x38); + if (this->request_lock_toggle_) { + this->request_lock_toggle_ = false; + this->sw_serial_.enableIntTx(false); + this->sw_serial_.write(toggle_lock[0]); + ESP_LOG2(TAG, "[%d] Sent byte: [%02X]", millis(), toggle_lock[0]); + this->sw_serial_.enableIntTx(true); + this->scheduler_->set_timeout(this->ratgdo_, "", 3500, [=] { + transmit_byte(toggle_lock[1], false); + }); + } else { + // inject door status request + this->sw_serial_.write(0x38); + } } else if (cmd.type == CommandType::OTHER_STATUS) { LightState light_state = to_LightState((cmd.value >> 2) & 1, LightState::UNKNOWN); this->light_state = light_state; @@ -308,13 +323,13 @@ namespace secplus1 { } } - void Secplus1::transmit_packet(const TxPacket& packet) + void Secplus1::transmit_packet(const TxPacket& packet, bool twice, uint32_t delay) { this->print_tx_packet(packet); transmit_byte(packet[0]); - this->scheduler_->set_timeout(this->ratgdo_, "", 1500, [=] { - transmit_byte(packet[1], true); + this->scheduler_->set_timeout(this->ratgdo_, "", delay, [=] { + transmit_byte(packet[1], twice); }); } diff --git a/components/ratgdo/secplus1.h b/components/ratgdo/secplus1.h index 945d54c..e0ce0f5 100644 --- a/components/ratgdo/secplus1.h +++ b/components/ratgdo/secplus1.h @@ -37,7 +37,7 @@ namespace secplus1 { (TOGGLE_LIGHT_COMMIT, 0x33), (TOGGLE_LOCK_REQ, 0x34), (TOGGLE_LOCK_COMMIT, 0x35), - (DOOR_STATUS_37, 0x37), + (DOOR_STATUS_0x37, 0x37), (DOOR_STATUS, 0x38), (OBSTRUCTION, 0x39), (OTHER_STATUS, 0x3A), @@ -81,7 +81,7 @@ namespace secplus1 { void print_tx_packet(const TxPacket& packet) const; optional decode_packet(const RxPacket& packet) const; - void transmit_packet(const TxPacket& packet); + void transmit_packet(const TxPacket& packet, bool twice = true, uint32_t delay = 500); void transmit_byte(uint32_t value, bool twice = false); LightState light_state { LightState::UNKNOWN }; @@ -94,6 +94,7 @@ namespace secplus1 { WallPanelEmulationState wall_panel_emulation_state_ { WallPanelEmulationState::WAITING }; bool is_0x37_panel_ { false }; + bool request_lock_toggle_ { false }; // bool transmit_pending_ { false }; // uint32_t transmit_pending_start_ { 0 };