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

◆ encodeSK9822()

template<typename InputIterator, typename OutputIterator>
void fl::encodeSK9822 ( InputIterator first,
InputIterator last,
OutputIterator out,
u8 global_brightness = 31 )

Encode pixel data in SK9822 format with global brightness.

Template Parameters
InputIteratorIterator yielding fl::array<u8, 3> (3 bytes in wire order)
OutputIteratorOutput iterator accepting uint8_t
Parameters
firstIterator to first pixel
lastIterator past last pixel
outOutput iterator for encoded bytes
global_brightnessGlobal 5-bit brightness (0-31), default 31
Note
SK9822 uses BGR wire order: pixel[0]=Blue, pixel[1]=Green, pixel[2]=Red

Definition at line 38 of file sk9822.h.

39 {
40 // Clamp brightness to 5-bit range
41 global_brightness = global_brightness & 0x1F;
42
43 // Start frame: 4 bytes of 0x00
44 *out++ = 0x00;
45 *out++ = 0x00;
46 *out++ = 0x00;
47 *out++ = 0x00;
48
49 // LED data: brightness header + BGR (count as we go)
50 size_t num_leds = 0;
51 while (first != last) {
52 const fl::array<u8, BYTES_PER_PIXEL_RGB>& pixel = *first;
53 *out++ = 0xE0 | global_brightness;
54 *out++ = pixel[0]; // Index 0 (BGR order: Blue)
55 *out++ = pixel[1]; // Index 1 (BGR order: Green)
56 *out++ = pixel[2]; // Index 2 (BGR order: Red)
57 ++first;
58 ++num_leds;
59 }
60
61 // SK9822 difference: end frame uses 0x00 instead of 0xFF
62 size_t end_dwords = (num_leds / 32) + 1;
63 for (size_t i = 0; i < end_dwords * 4; i++) {
64 *out++ = 0x00;
65 }
66}
A fixed-size array implementation similar to std::array.
Definition array.h:27

References FL_NOEXCEPT.

Referenced by fl::PixelIterator::writeSK9822().

+ Here is the caller graph for this function: