MCPcopy Create free account
hub / github.com/FastLED/FastLED / readStringUntil

Function readStringUntil

src/fl/stl/cstdio.cpp.hpp:139–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137}
138
139bool readStringUntil(sstream& out, char delimiter, char skipChar, fl::optional<u32> timeoutMs) {
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).
163 fl::delayMicroseconds(1);
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}
184
185fl::optional<fl::string> readLine(char delimiter, char skipChar, fl::optional<u32> timeoutMs) {
186 // Try platform-native line reading first (e.g., Arduino's Serial.readStringUntil).

Callers 2

readLineFunction · 0.85
FL_TEST_FILEFunction · 0.85

Calls 5

millisFunction · 0.70
readFunction · 0.70
delayMicrosecondsFunction · 0.50
has_valueMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected