Adjusted some timings
This commit is contained in:
parent
cebeacbd3c
commit
bbdbaa2f0d
|
@ -44,7 +44,7 @@ namespace secplus1 {
|
||||||
this->wall_panel_emulation_state_ = WallPanelEmulationState::WAITING;
|
this->wall_panel_emulation_state_ = WallPanelEmulationState::WAITING;
|
||||||
wall_panel_emulation_start_ = millis();
|
wall_panel_emulation_start_ = millis();
|
||||||
this->scheduler_->cancel_timeout(this->ratgdo_, "wall_panel_emulation");
|
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)
|
void Secplus1::wall_panel_emulation(size_t index)
|
||||||
|
@ -61,7 +61,7 @@ namespace secplus1 {
|
||||||
this->wall_panel_emulation_state_ = WallPanelEmulationState::RUNNING;
|
this->wall_panel_emulation_state_ = WallPanelEmulationState::RUNNING;
|
||||||
}
|
}
|
||||||
this->scheduler_->set_timeout(this->ratgdo_, "wall_panel_emulation", 2000, [=] {
|
this->scheduler_->set_timeout(this->ratgdo_, "wall_panel_emulation", 2000, [=] {
|
||||||
this->wall_panel_emulation(index);
|
this->wall_panel_emulation();
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
} else if (this->wall_panel_emulation_state_ == WallPanelEmulationState::RUNNING) {
|
} 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)
|
void Secplus1::transmit_packet(const TxPacket& packet)
|
||||||
{
|
{
|
||||||
this->print_tx_packet(packet);
|
this->print_tx_packet(packet);
|
||||||
|
|
||||||
auto delay = this->last_rx_ + 250 - millis();
|
auto tx_delay = this->last_rx_ + 125 - millis();
|
||||||
if (delay > 0) {
|
if (delay > 0) {
|
||||||
this->scheduler_->set_timeout(this->ratgdo_, "", delay, [=] {
|
this->scheduler_->set_timeout(this->ratgdo_, "", tx_delay, [=] {
|
||||||
this->transmit_packet_delayed(packet, TX_LENGTH, 25);
|
this->sw_serial_.enableIntTx(false);
|
||||||
|
this->sw_serial_.write(packet[0]);
|
||||||
|
this->sw_serial_.enableIntTx(true);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this->transmit_packet_delayed(packet, TX_LENGTH, 25);
|
tx_delay = 0;
|
||||||
}
|
this->sw_serial_.enableIntTx(false);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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]);
|
|
||||||
this->sw_serial_.write(packet[0]);
|
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 secplus1
|
||||||
} // namespace ratgdo
|
} // namespace ratgdo
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
|
@ -21,12 +21,12 @@ namespace secplus1 {
|
||||||
static const uint8_t RX_LENGTH = 2;
|
static const uint8_t RX_LENGTH = 2;
|
||||||
typedef uint8_t RxPacket[RX_LENGTH];
|
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];
|
typedef uint8_t TxPacket[TX_LENGTH];
|
||||||
|
|
||||||
static const TxPacket toggle_door = {0x30, 0x31, 0x31, 0xFE};
|
static const TxPacket toggle_door = {0x30, 0x31};
|
||||||
static const TxPacket toggle_light = {0x32, 0x33, 0x33, 0xFE};
|
static const TxPacket toggle_light = {0x32, 0x33};
|
||||||
static const TxPacket toggle_lock = {0x34, 0x35, 0x35, 0xFE};
|
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};
|
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);
|
Result call(Args args);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void wall_panel_emulation(size_t index);
|
void wall_panel_emulation(size_t index = 0);
|
||||||
|
|
||||||
optional<Command> read_command();
|
optional<Command> read_command();
|
||||||
void handle_command(const Command& cmd);
|
void handle_command(const Command& cmd);
|
||||||
|
@ -75,9 +75,7 @@ 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 uint8_t packet[], uint32_t len);
|
|
||||||
void transmit_packet(const TxPacket& packet);
|
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 };
|
LightState light_state { LightState::UNKNOWN };
|
||||||
LockState lock_state { LockState::UNKNOWN };
|
LockState lock_state { LockState::UNKNOWN };
|
||||||
|
|
Loading…
Reference in New Issue