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

◆ readStringUntil()

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

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

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

References delayMicroseconds(), fl::Optional< T >::has_value(), millis(), read(), and fl::Optional< T >::value().

Referenced by readLine().

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