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

Function readLine

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

Source from the content-addressed store, hash-verified

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).
187 // This is critical for USB CDC platforms (ESP32-C6/S3) where the native
188 // implementation uses yield() (immediate context switch) instead of
189 // delay(1) (1ms FreeRTOS sleep), enabling correct multi-packet assembly.
190 char nativeBuf[512];
191 int nativeLen = platforms::readLineNative(delimiter, nativeBuf, sizeof(nativeBuf));
192 if (nativeLen >= 0) {
193 fl::string result(nativeBuf, nativeLen);
194 return fl::string(result.trim());
195 }
196
197 // Fallback: character-by-character reading for non-Arduino platforms
198 sstream buffer;
199 if (!readStringUntil(buffer, delimiter, skipChar, timeoutMs)) {
200 return fl::nullopt; // Timeout occurred
201 }
202
203 // Convert to string and trim whitespace (trim() returns a new fl::string)
204 fl::string result = buffer.str();
205 return fl::string(result.trim());
206}
207
208bool flush(u32 timeoutMs) {
209#ifdef FASTLED_TESTING

Callers 8

readSerialLineFunction · 0.85
skipWhitespaceMethod · 0.85
readTokenMethod · 0.85
istream.cpp.hppFile · 0.85
getMethod · 0.85
peekMethod · 0.85
FL_TEST_FILEFunction · 0.85

Calls 5

readStringUntilFunction · 0.85
trimMethod · 0.80
stringClass · 0.70
readLineNativeFunction · 0.50
strMethod · 0.45

Tested by

no test coverage detected