From 47ee69137b5691308e0927b0bd0b963312ffe06f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 28 Nov 2022 18:14:44 +0100 Subject: [PATCH] Fix TasmotaSerial::read(buffer, size) --- lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp | 9 ++++++--- lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.h | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp b/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp index ef72dce1c..99241a44f 100644 --- a/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp +++ b/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp @@ -321,7 +321,6 @@ int TasmotaSerial::read(void) { #endif // ESP32 } else { if ((-1 == m_rx_pin) || (m_in_pos == m_out_pos)) return -1; -// m_overflow = false; uint32_t ch = m_buffer[m_out_pos]; m_out_pos = (m_out_pos +1) % serial_buffer_size; return ch; @@ -338,9 +337,8 @@ size_t TasmotaSerial::read(char* buffer, size_t size) { #endif // ESP32 } else { if ((-1 == m_rx_pin) || (m_in_pos == m_out_pos)) { return 0; } -// m_overflow = false; size_t count = 0; - for( ; size && (m_in_pos == m_out_pos) ; --size, ++count) { + for( ; size && (m_in_pos != m_out_pos) ; --size, ++count) { *buffer++ = m_buffer[m_out_pos]; m_out_pos = (m_out_pos +1) % serial_buffer_size; } @@ -359,6 +357,11 @@ int TasmotaSerial::available(void) { } else { int avail = m_in_pos - m_out_pos; if (avail < 0) avail += serial_buffer_size; + +// if (!avail) { +// optimistic_yield(10000); +// } + return avail; } } diff --git a/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.h b/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.h index e62d75316..b9542699e 100644 --- a/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.h +++ b/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.h @@ -51,6 +51,9 @@ class TasmotaSerial : public Stream { size_t write(uint8_t byte) override; int read(void) override; size_t read(char* buffer, size_t size); + size_t read(uint8_t* buffer, size_t size) { + return read(reinterpret_cast(buffer), size); + } int available(void) override; void flush(void) override;