FastLED 3.10.8
Loading...
Searching...
No Matches

◆ readStringUntil()

bool fl::readStringUntil ( sstream & out,
char delimiter,
char skipChar,
fl::optional< u32 > timeoutMs )

Definition at line 140 of file cstdio.cpp.hpp.

140 {
141 // Follows Arduino Serial.readStringUntil() API - blocks until delimiter found
142 u32 startTime = fl::millis();
143
144 // Read characters until we find delimiter or timeout
145 while (true) {
146 // Check timeout (only if timeout is set)
147 if (timeoutMs.has_value()) {
148 if (fl::millis() - startTime >= timeoutMs.value()) {
149 // Timeout occurred
150 return false;
151 }
152 }
153
154 // Try to read next character
155 int c = read();
156
157 // Handle -1 (no data available) like Arduino's timedRead():
158 // Keep trying until timeout (or forever if no timeout set)
159 if (c == -1) {
160 // Brief 1us yield to prevent busy loop without the 1ms
161 // minimum sleep that fl::delay(1) imposes on FreeRTOS
162 // (vTaskDelay(1) = 1 tick = 1ms). The 1ms delay was too
163 // slow for USB CDC multi-packet assembly (64-byte packets).
165 continue;
166 }
167
168 // Found delimiter - complete
169 if (c == delimiter) {
170 break;
171 }
172
173 // Skip specified character (e.g., '\r' for cross-platform line endings)
174 if (c == skipChar) {
175 continue;
176 }
177
178 // Valid character - add to output stream
179 out << static_cast<char>(c);
180 }
181
182 // Successfully read until delimiter
183 return true;
184}
T & value() FL_NO_EXCEPT
Definition optional.h:112
bool has_value() const FL_NO_EXCEPT
Definition optional.h:42
fl::u32 millis() FL_NO_EXCEPT
Universal millisecond timer - returns milliseconds since system startup.
int read() FL_NO_EXCEPT
void delayMicroseconds(u32 us) FL_NO_EXCEPT
Delay for a given number of microseconds.

References delayMicroseconds(), FL_NO_EXCEPT, millis(), and read().

Referenced by readLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: