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

◆ readLine()

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

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

185 {
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}
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
constexpr nullopt_t nullopt
Definition optional.h:13
bool readStringUntil(sstream &out, char delimiter, char skipChar, fl::optional< u32 > timeoutMs)

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

Referenced by createSerialRequestSource(), and readSerialLine().

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