| 183 | } |
| 184 | |
| 185 | fl::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 | |
| 208 | bool flush(u32 timeoutMs) { |
| 209 | #ifdef FASTLED_TESTING |
no test coverage detected