FastLED 3.10.8
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 155 of file serial.cpp.hpp.

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

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

+ Here is the call graph for this function: