Skip to content

Commit 5a55be0

Browse files
authored
I propose to make this modification so that the callback is only triggered when appropriate conditions are met, and passes the number of available bytes to the callback.
1 parent def319a commit 5a55be0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cores/esp32/HardwareSerial.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,11 @@ void HardwareSerial::_uartEventTask(void *args) {
241241
hardwareSerial_error_t currentErr = UART_NO_ERROR;
242242
switch (event.type) {
243243
case UART_DATA:
244-
if (uart->_onReceiveCB && uart->available() > 0 && ((uart->_onReceiveTimeout && event.timeout_flag) || !uart->_onReceiveTimeout)) {
245-
uart->_onReceiveCB();
244+
if (uart->_onReceiveCB && uart->available() > 0) {
245+
size_t available = uart->available();
246+
if ((uart->_onReceiveTimeout && event.timeout_flag) || (!uart->_onReceiveTimeout && available >= uart->_rxFIFOFull)) {
247+
uart->_onReceiveCB(available);
248+
}
246249
}
247250
break;
248251
case UART_FIFO_OVF:

0 commit comments

Comments
 (0)