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

◆ readBytesUntil()

size_t fl::SerialPort::readBytesUntil ( char delimiter,
u8 * buffer,
size_t length )

Read bytes until delimiter is found.

Parameters
bufferPointer to destination buffer
lengthMaximum number of bytes to read
delimiterCharacter to stop reading at (not included in result)
Returns
Number of bytes actually read (not including delimiter)

Reads bytes from serial until delimiter is found, timeout occurs, or buffer is full. The delimiter character is discarded (not included in the buffer).

Definition at line 197 of file serial.cpp.hpp.

197 {
198 if (!buffer || length == 0) {
199 return 0;
200 }
201
202 size_t count = 0;
203 u32 startTime = fl::millis();
204
205 while (count < length && (fl::millis() - startTime < mTimeoutMs)) {
206 if (available() > 0) {
207 int c = read();
208 if (c == -1) {
209 continue; // No data
210 }
211 if (c == delimiter) {
212 break; // Found delimiter, stop reading
213 }
214 buffer[count++] = static_cast<u8>(c);
215 startTime = fl::millis(); // Reset timeout on successful read
216 }
217 }
218
219 return count;
220}
int read() FL_NO_EXCEPT
Read next byte from serial input.
int available() FL_NO_EXCEPT
Check how many bytes are available to read.
fl::UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
unsigned char u8
Definition stdint.h:131
fl::u32 millis() FL_NO_EXCEPT
Universal millisecond timer - returns milliseconds since system startup.

References fl::available(), fl::FL_NO_EXCEPT, length(), fl::millis(), mTimeoutMs, and fl::read().

+ Here is the call graph for this function: