mirror of
https://github.com/esphome/esphome.git
synced 2026-08-24 23:26:20 +00:00
[uart] Report no data available while the bus is not ready
A stale peeked byte was still counted by available() while the read paths refused to deliver it, so a caller looping on available() would spin forever.
This commit is contained in:
@@ -371,7 +371,10 @@ size_t IDFUARTComponent::available() {
|
||||
if (!this->is_ready()) {
|
||||
// The driver is not installed yet (or the bus failed); asking the driver
|
||||
// would fail and mark the whole bus failed, so report no data instead.
|
||||
return this->has_peek_ ? 1 : 0;
|
||||
// A stale peeked byte must not be counted either: the read paths refuse
|
||||
// to deliver it while the bus is not ready, so advertising it would make
|
||||
// the common `while (available()) read()` pattern spin forever.
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = uart_get_buffered_data_len(this->uart_num_, &available);
|
||||
|
||||
Reference in New Issue
Block a user