FastLED 3.10.9
Loading...
Searching...
No Matches

◆ readLine()

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

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

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