FastLED 3.10.9
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
142 // found. Like Arduino's timedRead(), the timeout measures inactivity: it
143 // restarts on every received byte, so a long line arriving steadily over
144 // a slow link is not discarded midway (FastLED #4893).
145 u32 startTime = fl::millis();
146
147 // Read characters until we find delimiter or timeout
148 while (true) {
149 // Check timeout (only if timeout is set)
150 if (timeoutMs.has_value()) {
151 if (fl::millis() - startTime >= timeoutMs.value()) {
152 // Timeout occurred
153 return false;
154 }
155 }
156
157 // Try to read next character
158 int c = read();
159
160 // Handle -1 (no data available) like Arduino's timedRead():
161 // Keep trying until timeout (or forever if no timeout set)
162 if (c == -1) {
163 // Brief 1us yield to prevent busy loop without the 1ms
164 // minimum sleep that fl::delay(1) imposes on FreeRTOS
165 // (vTaskDelay(1) = 1 tick = 1ms). The 1ms delay was too
166 // slow for USB CDC multi-packet assembly (64-byte packets).
168 continue;
169 }
170
171 startTime = fl::millis();
172
173 // Found delimiter - complete
174 if (c == delimiter) {
175 break;
176 }
177
178 // Skip specified character (e.g., '\r' for cross-platform line endings)
179 if (c == skipChar) {
180 continue;
181 }
182
183 // Valid character - add to output stream
184 out << static_cast<char>(c);
185 }
186
187 // Successfully read until delimiter
188 return true;
189}
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: