mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 02:26:01 +00:00
Merge remote-tracking branch 'upstream/dev' into integration
This commit is contained in:
@@ -460,6 +460,10 @@ void LD2420Component::handle_energy_mode_(uint8_t *buffer, int len) {
|
||||
uint8_t index = 6; // Start at presence byte position
|
||||
uint16_t range;
|
||||
const uint8_t elements = sizeof(this->gate_energy_) / sizeof(this->gate_energy_[0]);
|
||||
if (len < static_cast<int>(index + 1 + sizeof(range) + elements * sizeof(this->gate_energy_[0]))) {
|
||||
ESP_LOGW(TAG, "Energy frame too short: %d bytes", len);
|
||||
return;
|
||||
}
|
||||
this->set_presence_(buffer[index]);
|
||||
index++;
|
||||
memcpy(&range, &buffer[index], sizeof(range));
|
||||
@@ -471,8 +475,11 @@ void LD2420Component::handle_energy_mode_(uint8_t *buffer, int len) {
|
||||
}
|
||||
|
||||
if (this->current_operating_mode == OP_CALIBRATE_MODE) {
|
||||
this->update_radar_data(gate_energy_, sample_number_counter);
|
||||
this->sample_number_counter > CALIBRATE_SAMPLES ? this->sample_number_counter = 0 : this->sample_number_counter++;
|
||||
this->update_radar_data(gate_energy_, this->sample_number_counter);
|
||||
this->sample_number_counter++;
|
||||
if (this->sample_number_counter >= CALIBRATE_SAMPLES) {
|
||||
this->sample_number_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Resonable refresh rate for home assistant database size health
|
||||
@@ -503,22 +510,20 @@ void LD2420Component::handle_simple_mode_(const uint8_t *inbuf, int len) {
|
||||
char *endptr{nullptr};
|
||||
char outbuf[bufsize]{0};
|
||||
while (true) {
|
||||
if (inbuf[pos - 2] == 'O' && inbuf[pos - 1] == 'F' && inbuf[pos] == 'F') {
|
||||
if (pos >= 2 && inbuf[pos - 2] == 'O' && inbuf[pos - 1] == 'F' && inbuf[pos] == 'F') {
|
||||
this->set_presence_(false);
|
||||
} else if (inbuf[pos - 1] == 'O' && inbuf[pos] == 'N') {
|
||||
} else if (pos >= 1 && inbuf[pos - 1] == 'O' && inbuf[pos] == 'N') {
|
||||
this->set_presence_(true);
|
||||
}
|
||||
if (inbuf[pos] >= '0' && inbuf[pos] <= '9') {
|
||||
if (index < bufsize - 1) {
|
||||
outbuf[index++] = inbuf[pos];
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
if (pos < len - 1) {
|
||||
pos++;
|
||||
} else {
|
||||
if (pos < len - 1) {
|
||||
pos++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
outbuf[index] = '\0';
|
||||
|
||||
Reference in New Issue
Block a user