Adjust timings

This commit is contained in:
Marius Muja 2024-01-12 16:00:54 -08:00
parent bf19a49fdb
commit 1cec8e881e
2 changed files with 19 additions and 17 deletions

View File

@ -106,7 +106,7 @@ namespace secplus1 {
if (action == LockAction::TOGGLE || if (action == LockAction::TOGGLE ||
(action == LockAction::LOCK && this->lock_state == LockState::UNLOCKED) || (action == LockAction::LOCK && this->lock_state == LockState::UNLOCKED) ||
(action == LockAction::UNLOCK && this->lock_state == LockState::LOCKED)) { (action == LockAction::UNLOCK && this->lock_state == LockState::LOCKED)) {
this->transmit_packet(toggle_lock, this->is_0x37_panel_); this->transmit_packet(toggle_lock);
} }
} }
@ -308,34 +308,35 @@ namespace secplus1 {
} }
} }
void Secplus1::transmit_packet(const TxPacket& packet, bool first_byte) void Secplus1::transmit_packet(const TxPacket& packet)
{ {
this->print_tx_packet(packet); this->print_tx_packet(packet);
int32_t tx_delay = static_cast<int32_t>(this->last_rx_ + 125) - millis(); transmit_byte(packet[0]);
this->scheduler_->set_timeout(this->ratgdo_, "", 1500, [=] {
transmit_byte(packet[1], true);
});
}
void Secplus1::transmit_byte(uint32_t value, bool twice)
{
int32_t tx_delay = static_cast<int32_t>(this->last_rx_ + 100) - millis();
while (tx_delay<0) { while (tx_delay<0) {
tx_delay += 250; tx_delay += 250;
} }
this->scheduler_->set_timeout(this->ratgdo_, "", tx_delay, [=] { this->scheduler_->set_timeout(this->ratgdo_, "", tx_delay, [=] {
this->sw_serial_.enableIntTx(false); this->sw_serial_.enableIntTx(false);
this->sw_serial_.write(packet[0]); this->sw_serial_.write(value);
this->sw_serial_.enableIntTx(true); this->sw_serial_.enableIntTx(true);
ESP_LOG2(TAG, "[%d] Sent byte: [%02X]", millis(), packet[0]); ESP_LOG2(TAG, "[%d] Sent byte: [%02X]", millis(), value);
}); });
if (twice) {
if (!first_byte) { this->scheduler_->set_timeout(this->ratgdo_, "", tx_delay+40, [=] {
this->scheduler_->set_timeout(this->ratgdo_, "", tx_delay+250, [=] {
this->sw_serial_.enableIntTx(false); this->sw_serial_.enableIntTx(false);
this->sw_serial_.write(packet[1]); this->sw_serial_.write(value);
this->sw_serial_.enableIntTx(true); this->sw_serial_.enableIntTx(true);
ESP_LOG2(TAG, "[%d] Sent byte: [%02X]", millis(), packet[1]); ESP_LOG2(TAG, "[%d] Sent byte: [%02X]", millis(), value);
});
this->scheduler_->set_timeout(this->ratgdo_, "", tx_delay+290, [=] {
this->sw_serial_.enableIntTx(false);
this->sw_serial_.write(packet[1]);
this->sw_serial_.enableIntTx(true);
ESP_LOG2(TAG, "[%d] Sent byte: [%02X]", millis(), packet[1]);
}); });
} }
} }

View File

@ -81,7 +81,8 @@ namespace secplus1 {
void print_tx_packet(const TxPacket& packet) const; void print_tx_packet(const TxPacket& packet) const;
optional<Command> decode_packet(const RxPacket& packet) const; optional<Command> decode_packet(const RxPacket& packet) const;
void transmit_packet(const TxPacket& packet, bool first_byte = false); void transmit_packet(const TxPacket& packet);
void transmit_byte(uint32_t value, bool twice = false);
LightState light_state { LightState::UNKNOWN }; LightState light_state { LightState::UNKNOWN };
LockState lock_state { LockState::UNKNOWN }; LockState lock_state { LockState::UNKNOWN };