FastLED 3.10.6
Loading...
Searching...
No Matches

◆ encodeSK9822_HD()

template<typename InputIterator, typename BrightnessIterator, typename OutputIterator>
void fl::encodeSK9822_HD ( InputIterator first,
InputIterator last,
BrightnessIterator brightness_first,
OutputIterator out )

Encode pixel data in SK9822 format with per-LED brightness.

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

Definition at line 79 of file sk9822.h.

80 {
81 // Start frame: 4 bytes of 0x00
82 *out++ = 0x00;
83 *out++ = 0x00;
84 *out++ = 0x00;
85 *out++ = 0x00;
86
87 // LED data: brightness header + BGR (per-LED brightness, count as we go)
88 size_t num_leds = 0;
89 while (first != last) {
90 const fl::array<u8, BYTES_PER_PIXEL_RGB>& pixel = *first;
91 u8 brightness_8bit = *brightness_first;
92 u8 brightness_5bit = mapBrightness8to5(brightness_8bit);
93
94 *out++ = 0xE0 | brightness_5bit;
95 *out++ = pixel[0]; // Index 0 (BGR order: Blue)
96 *out++ = pixel[1]; // Index 1 (BGR order: Green)
97 *out++ = pixel[2]; // Index 2 (BGR order: Red)
98
99 ++first;
100 ++brightness_first;
101 ++num_leds;
102 }
103
104 // See encodeSK9822(): the end clocks are all ones.
105 size_t end_dwords = (num_leds / 32) + 1;
106 for (size_t i = 0; i < end_dwords * 4; i++) {
107 *out++ = 0xFF;
108 }
109}
A fixed-size array implementation similar to std::array.
Definition array.h:27
unsigned char u8
Definition stdint.h:131
u8 mapBrightness8to5(u8 brightness_8bit) FL_NO_EXCEPT
Map 8-bit brightness to 5-bit (0-31)

References FL_NO_EXCEPT, and mapBrightness8to5().

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

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