From c8a93f31e99a183426a65eda3cf4ba754545786b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 9 Feb 2026 09:28:15 -0600 Subject: [PATCH 1/2] Add comment explaining early guard --- esphome/components/dfplayer/dfplayer.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/esphome/components/dfplayer/dfplayer.cpp b/esphome/components/dfplayer/dfplayer.cpp index 6ef9be3865..91aa608d01 100644 --- a/esphome/components/dfplayer/dfplayer.cpp +++ b/esphome/components/dfplayer/dfplayer.cpp @@ -132,9 +132,8 @@ void DFPlayer::send_cmd_(uint8_t cmd, uint16_t argument) { } void DFPlayer::loop() { - // Read message - // All current UART available() implementations return >= 0, - // use <= 0 to future-proof against any that may return negative on error. + // Early return avoids stack adjustment for the batch buffer below. + // loop() runs ~7000/min so most calls have nothing to read. int avail = this->available(); if (avail <= 0) return; From 1c4cf1a3e87e11e552559d37123775ed6c8f9bb4 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 9 Feb 2026 09:40:05 -0600 Subject: [PATCH 2/2] Remove unnecessary early guard --- esphome/components/dfplayer/dfplayer.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/esphome/components/dfplayer/dfplayer.cpp b/esphome/components/dfplayer/dfplayer.cpp index 91aa608d01..48c06be558 100644 --- a/esphome/components/dfplayer/dfplayer.cpp +++ b/esphome/components/dfplayer/dfplayer.cpp @@ -132,12 +132,8 @@ void DFPlayer::send_cmd_(uint8_t cmd, uint16_t argument) { } void DFPlayer::loop() { - // Early return avoids stack adjustment for the batch buffer below. - // loop() runs ~7000/min so most calls have nothing to read. + // Read all available bytes in batches to reduce UART call overhead. int avail = this->available(); - if (avail <= 0) - return; - uint8_t buf[64]; while (avail > 0) { size_t to_read = std::min(static_cast(avail), sizeof(buf));