1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 00:31:58 +00:00

Merge branch 'ld2410_batch_read' into integration

This commit is contained in:
J. Nick Koston
2026-02-06 23:40:20 +01:00

View File

@@ -275,8 +275,23 @@ void LD2410Component::restart_and_read_all_info() {
}
void LD2410Component::loop() {
while (this->available()) {
this->readline_(this->read());
int avail = this->available();
if (avail == 0) {
return;
}
// Read all available bytes in batches to reduce UART call overhead.
uint8_t buf[MAX_LINE_LENGTH];
while (avail > 0) {
size_t to_read = std::min(static_cast<size_t>(avail), sizeof(buf));
if (!this->read_array(buf, to_read)) {
break;
}
avail -= to_read;
for (size_t i = 0; i < to_read; i++) {
this->readline_(buf[i]);
}
}
}