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

◆ readLine()

fl::optional< fl::string > fl::readLine ( char delimiter,
char skipChar,
fl::optional< u32 > timeoutMs )

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

186 {
187 // Try platform-native line reading first (e.g., Arduino's Serial.readStringUntil).
188 // This is critical for USB CDC platforms (ESP32-C6/S3) where the native
189 // implementation uses yield() (immediate context switch) instead of
190 // delay(1) (1ms FreeRTOS sleep), enabling correct multi-packet assembly.
191 char nativeBuf[512];
192 int nativeLen = platforms::readLineNative(delimiter, nativeBuf, sizeof(nativeBuf));
193 if (nativeLen >= 0) {
194 fl::string result(nativeBuf, nativeLen);
195 return fl::string(result.trim());
196 }
197
198 // Fallback: character-by-character reading for non-Arduino platforms
199 sstream buffer;
200 if (!readStringUntil(buffer, delimiter, skipChar, timeoutMs)) {
201 return fl::nullopt; // Timeout occurred
202 }
203
204 // Convert to string and trim whitespace (trim() returns a new fl::string)
205 fl::string result = buffer.str();
206 return fl::string(result.trim());
207}
bool readStringUntil(sstream &out, char delimiter, char skipChar, fl::optional< u32 > timeoutMs) FL_NO_EXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
constexpr nullopt_t nullopt
Definition optional.h:13

References FL_NO_EXCEPT, nullopt, readStringUntil(), and fl::sstream::str().

Referenced by createSerialRequestSource(), fl::istream_real::operator>>(), readSerialLine(), and fl::istream_real::readToken().

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