diff --git a/components/ratgdo/secplus1.cpp b/components/ratgdo/secplus1.cpp index 7a5e1c3..c6b6ea2 100644 --- a/components/ratgdo/secplus1.cpp +++ b/components/ratgdo/secplus1.cpp @@ -44,7 +44,7 @@ namespace secplus1 { this->wall_panel_emulation_state_ = WallPanelEmulationState::WAITING; wall_panel_emulation_start_ = millis(); this->scheduler_->cancel_timeout(this->ratgdo_, "wall_panel_emulation"); - this->wall_panel_emulation(0); + this->wall_panel_emulation(); } void Secplus1::wall_panel_emulation(size_t index) @@ -61,7 +61,7 @@ namespace secplus1 { this->wall_panel_emulation_state_ = WallPanelEmulationState::RUNNING; } this->scheduler_->set_timeout(this->ratgdo_, "wall_panel_emulation", 2000, [=] { - this->wall_panel_emulation(index); + this->wall_panel_emulation(); }); return; } else if (this->wall_panel_emulation_state_ == WallPanelEmulationState::RUNNING) { @@ -264,40 +264,34 @@ namespace secplus1 { } } - void Secplus1::transmit_packet(const uint8_t packet[], uint32_t len) - { - this->transmit_packet_delayed(packet, len, 25); - } - void Secplus1::transmit_packet(const TxPacket& packet) { this->print_tx_packet(packet); - auto delay = this->last_rx_ + 250 - millis(); + auto tx_delay = this->last_rx_ + 125 - millis(); if (delay > 0) { - this->scheduler_->set_timeout(this->ratgdo_, "", delay, [=] { - this->transmit_packet_delayed(packet, TX_LENGTH, 25); + this->scheduler_->set_timeout(this->ratgdo_, "", tx_delay, [=] { + this->sw_serial_.enableIntTx(false); + this->sw_serial_.write(packet[0]); + this->sw_serial_.enableIntTx(true); }); } else { - this->transmit_packet_delayed(packet, TX_LENGTH, 25); - } - - } - - void Secplus1::transmit_packet_delayed(const uint8_t* packet, uint32_t len, uint32_t delay) - { - if (len == 0) { - return; - } - - this->scheduler_->set_timeout(this->ratgdo_, "", delay, [=] { - ESP_LOG2(TAG, "Sending byte: [%02X]", packet[0]); + tx_delay = 0; + this->sw_serial_.enableIntTx(false); this->sw_serial_.write(packet[0]); - this->transmit_packet_delayed(packet+1, len-1, delay); + this->sw_serial_.enableIntTx(true); + } + this->scheduler_->set_timeout(this->ratgdo_, "", tx_delay+250, [=] { + this->sw_serial_.enableIntTx(false); + this->sw_serial_.write(packet[1]); + delay(40); + this->sw_serial_.write(packet[1]); + this->sw_serial_.enableIntTx(true); }); - } + } + } // namespace secplus1 } // namespace ratgdo } // namespace esphome diff --git a/components/ratgdo/secplus1.h b/components/ratgdo/secplus1.h index bccac15..bef405b 100644 --- a/components/ratgdo/secplus1.h +++ b/components/ratgdo/secplus1.h @@ -21,12 +21,12 @@ namespace secplus1 { static const uint8_t RX_LENGTH = 2; typedef uint8_t RxPacket[RX_LENGTH]; - static const uint8_t TX_LENGTH = 4; + static const uint8_t TX_LENGTH = 2; typedef uint8_t TxPacket[TX_LENGTH]; - static const TxPacket toggle_door = {0x30, 0x31, 0x31, 0xFE}; - static const TxPacket toggle_light = {0x32, 0x33, 0x33, 0xFE}; - static const TxPacket toggle_lock = {0x34, 0x35, 0x35, 0xFE}; + static const TxPacket toggle_door = {0x30, 0x31}; + static const TxPacket toggle_light = {0x32, 0x33}; + static const TxPacket toggle_lock = {0x34, 0x35}; static const uint8_t secplus1_states[] = {0x35,0x35,0x35,0x35,0x33,0x33,0x53,0x53,0x38,0x3A,0x3A,0x3A,0x39,0x38,0x3A, 0x38,0x3A,0x39,0x3A}; @@ -66,7 +66,7 @@ namespace secplus1 { Result call(Args args); protected: - void wall_panel_emulation(size_t index); + void wall_panel_emulation(size_t index = 0); optional read_command(); void handle_command(const Command& cmd); @@ -75,9 +75,7 @@ namespace secplus1 { void print_tx_packet(const TxPacket& packet) const; optional decode_packet(const RxPacket& packet) const; - void transmit_packet(const uint8_t packet[], uint32_t len); void transmit_packet(const TxPacket& packet); - void transmit_packet_delayed(const uint8_t* packet, uint32_t len, uint32_t delay); LightState light_state { LightState::UNKNOWN }; LockState lock_state { LockState::UNKNOWN };