mirror of https://github.com/arendst/Tasmota.git
Fix TasmotaSerial::read(buffer, size)
This commit is contained in:
parent
86fcaa1a8d
commit
47ee69137b
|
@ -321,7 +321,6 @@ int TasmotaSerial::read(void) {
|
||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
} else {
|
} else {
|
||||||
if ((-1 == m_rx_pin) || (m_in_pos == m_out_pos)) return -1;
|
if ((-1 == m_rx_pin) || (m_in_pos == m_out_pos)) return -1;
|
||||||
// m_overflow = false;
|
|
||||||
uint32_t ch = m_buffer[m_out_pos];
|
uint32_t ch = m_buffer[m_out_pos];
|
||||||
m_out_pos = (m_out_pos +1) % serial_buffer_size;
|
m_out_pos = (m_out_pos +1) % serial_buffer_size;
|
||||||
return ch;
|
return ch;
|
||||||
|
@ -338,9 +337,8 @@ size_t TasmotaSerial::read(char* buffer, size_t size) {
|
||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
} else {
|
} else {
|
||||||
if ((-1 == m_rx_pin) || (m_in_pos == m_out_pos)) { return 0; }
|
if ((-1 == m_rx_pin) || (m_in_pos == m_out_pos)) { return 0; }
|
||||||
// m_overflow = false;
|
|
||||||
size_t count = 0;
|
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];
|
*buffer++ = m_buffer[m_out_pos];
|
||||||
m_out_pos = (m_out_pos +1) % serial_buffer_size;
|
m_out_pos = (m_out_pos +1) % serial_buffer_size;
|
||||||
}
|
}
|
||||||
|
@ -359,6 +357,11 @@ int TasmotaSerial::available(void) {
|
||||||
} else {
|
} else {
|
||||||
int avail = m_in_pos - m_out_pos;
|
int avail = m_in_pos - m_out_pos;
|
||||||
if (avail < 0) avail += serial_buffer_size;
|
if (avail < 0) avail += serial_buffer_size;
|
||||||
|
|
||||||
|
// if (!avail) {
|
||||||
|
// optimistic_yield(10000);
|
||||||
|
// }
|
||||||
|
|
||||||
return avail;
|
return avail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,9 @@ class TasmotaSerial : public Stream {
|
||||||
size_t write(uint8_t byte) override;
|
size_t write(uint8_t byte) override;
|
||||||
int read(void) override;
|
int read(void) override;
|
||||||
size_t read(char* buffer, size_t size);
|
size_t read(char* buffer, size_t size);
|
||||||
|
size_t read(uint8_t* buffer, size_t size) {
|
||||||
|
return read(reinterpret_cast<char*>(buffer), size);
|
||||||
|
}
|
||||||
int available(void) override;
|
int available(void) override;
|
||||||
void flush(void) override;
|
void flush(void) override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue