FastLED 3.9.15
Loading...
Searching...
No Matches

◆ readStringUntil()

fl::string fl::SerialPort::readStringUntil ( char delimiter)

Read characters until delimiter is found.

Parameters
delimiterCharacter to stop reading at (not included in result)
Returns
String containing all characters up to delimiter

Reads characters from serial until delimiter is found or timeout expires. The delimiter character is discarded (not included in the returned string).

Definition at line 158 of file serial.cpp.hpp.

158 {
159 fl::string result;
160 u32 startTime = fl::millis();
161
162 while (fl::millis() - startTime < mTimeoutMs) {
163 if (available() > 0) {
164 int c = read();
165 if (c == -1) {
166 continue; // No data
167 }
168 if (c == delimiter) {
169 break; // Found delimiter, stop reading
170 }
171 result += static_cast<char>(c);
172 startTime = fl::millis(); // Reset timeout on successful read
173 }
174 }
175
176 return result;
177}
int available()
Check how many bytes are available to read.
int read()
Read next byte from serial input.
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References available(), fl::millis(), mTimeoutMs, and read().

+ Here is the call graph for this function: