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

Function readLineNative

src/platforms/arm/lpc/io_lpc.cpp.hpp:57–87  ·  view source on GitHub ↗

LPC's HardwareSerial lacks readStringUntil(), so read the line manually.

Source from the content-addressed store, hash-verified

55
56// LPC's HardwareSerial lacks readStringUntil(), so read the line manually.
57int readLineNative(char delimiter, char* out, int outLen) FL_NOEXCEPT {
58 if (outLen <= 0) {
59 return 0;
60 }
61 const unsigned long timeoutMs = 1000UL;
62 unsigned long start = fl::millis();
63 int len = 0;
64 while (true) {
65 if (!Serial.available()) {
66 if (fl::millis() - start >= timeoutMs) {
67 break;
68 }
69 fl::yield();
70 continue;
71 }
72 const int value = Serial.read();
73 if (value < 0) {
74 break;
75 }
76 const char c = static_cast<char>(value);
77 if (c == delimiter) {
78 break;
79 }
80 if (len < outLen - 1) {
81 out[len++] = c;
82 }
83 start = fl::millis();
84 }
85 out[len] = '\0';
86 return len;
87}
88
89bool flush(u32 timeoutMs) FL_NOEXCEPT {
90 (void)timeoutMs;

Callers

nothing calls this directly

Calls 4

millisFunction · 0.50
yieldFunction · 0.50
availableMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected