8000 Obey timeout value on SerialUART.read/.peek (#211) · Robotonics/arduino-pico@30704a7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 30704a7

Browse files
Obey timeout value on SerialUART.read/.peek (earlephilhower#211)
Fixes a hang when reading from the Serial UART ports because before the core would pause indefinitely for the next character. Now, wait up to Serial.setTimeout() milliseconds and if it times out return -1 to the app. Fixes earlephilhower#210
1 parent 08b6748 commit 30704a7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cores/rp2040/SerialUART.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ int SerialUART::peek() {
115115
if (_peek >= 0) {
116116
return _peek;
117117
}
118-
_peek = uart_getc(_uart);
118+
if (uart_is_readable_within_us(_uart, _timeout * 1000)) {
119+
_peek = uart_getc(_uart);
120+
} else {
121+
_peek = -1; // Timeout
122+
}
119123
return _peek;
120124
}
121125

@@ -129,7 +133,11 @@ int SerialUART::read() {
129133
_peek = -1;
130134
return ret;
131135
}
132-
return uart_getc(_uart);
136+
if (uart_is_readable_within_us(_uart, _timeout * 1000)) {
137+
return uart_getc(_uart);
138+
} else {
139+
return -1; // Timeout
140+
}
133141
}
134142

135143
int SerialUART::available() {

0 commit comments

Comments
 (0)
0