mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 21:44:55 +01:00
Limit Rx wait loop time to 3 seconds. (#6594)
Co-authored-by: descipher <mike.laspina@gelidus.ca>
This commit is contained in:
parent
217988fd99
commit
b03d0f37a4
1 changed files with 4 additions and 6 deletions
|
@ -493,19 +493,16 @@ void LD2420Component::handle_ack_data_(uint8_t *buffer, int len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int LD2420Component::send_cmd_from_array(CmdFrameT frame) {
|
int LD2420Component::send_cmd_from_array(CmdFrameT frame) {
|
||||||
|
uint32_t start_millis = millis();
|
||||||
uint8_t error = 0;
|
uint8_t error = 0;
|
||||||
uint8_t ack_buffer[64];
|
uint8_t ack_buffer[64];
|
||||||
uint8_t cmd_buffer[64];
|
uint8_t cmd_buffer[64];
|
||||||
uint16_t loop_count;
|
|
||||||
this->cmd_reply_.ack = false;
|
this->cmd_reply_.ack = false;
|
||||||
if (frame.command != CMD_RESTART)
|
if (frame.command != CMD_RESTART)
|
||||||
this->set_cmd_active_(true); // Restart does not reply, thus no ack state required.
|
this->set_cmd_active_(true); // Restart does not reply, thus no ack state required.
|
||||||
uint8_t retry = 3;
|
uint8_t retry = 3;
|
||||||
while (retry) {
|
while (retry) {
|
||||||
// TODO setup a dynamic method e.g. millis time count etc. to tune for non ESP32 240Mhz devices
|
|
||||||
// this is ok for now since the module firmware is changing like the weather atm
|
|
||||||
frame.length = 0;
|
frame.length = 0;
|
||||||
loop_count = 1250;
|
|
||||||
uint16_t frame_data_bytes = frame.data_length + 2; // Always add two bytes for the cmd size
|
uint16_t frame_data_bytes = frame.data_length + 2; // Always add two bytes for the cmd size
|
||||||
|
|
||||||
memcpy(&cmd_buffer[frame.length], &frame.header, sizeof(frame.header));
|
memcpy(&cmd_buffer[frame.length], &frame.header, sizeof(frame.header));
|
||||||
|
@ -538,12 +535,13 @@ int LD2420Component::send_cmd_from_array(CmdFrameT frame) {
|
||||||
this->readline_(read(), ack_buffer, sizeof(ack_buffer));
|
this->readline_(read(), ack_buffer, sizeof(ack_buffer));
|
||||||
}
|
}
|
||||||
delay_microseconds_safe(1450);
|
delay_microseconds_safe(1450);
|
||||||
if (loop_count <= 0) {
|
// Wait on an Rx from the LD2420 for up to 3 1 second loops, otherwise it could trigger a WDT.
|
||||||
|
if ((millis() - start_millis) > 1000) {
|
||||||
|
start_millis = millis();
|
||||||
error = LD2420_ERROR_TIMEOUT;
|
error = LD2420_ERROR_TIMEOUT;
|
||||||
retry--;
|
retry--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
loop_count--;
|
|
||||||
}
|
}
|
||||||
if (this->cmd_reply_.ack)
|
if (this->cmd_reply_.ack)
|
||||||
retry = 0;
|
retry = 0;
|
||||||
|
|
Loading…
Reference in a new issue