FastLED 3.9.15
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 78 of file sk9822.h.

79 {
80 // Start frame: 4 bytes of 0x00
81 *out++ = 0x00;
82 *out++ = 0x00;
83 *out++ = 0x00;
84 *out++ = 0x00;
85
86 // LED data: brightness header + BGR (per-LED brightness, count as we go)
87 size_t num_leds = 0;
88 while (first != last) {
89 const fl::array<u8, BYTES_PER_PIXEL_RGB>& pixel = *first;
90 u8 brightness_8bit = *brightness_first;
91 u8 brightness_5bit = mapBrightness8to5(brightness_8bit);
92
93 *out++ = 0xE0 | brightness_5bit;
94 *out++ = pixel[0]; // Index 0 (BGR order: Blue)
95 *out++ = pixel[1]; // Index 1 (BGR order: Green)
96 *out++ = pixel[2]; // Index 2 (BGR order: Red)
97
98 ++first;
99 ++brightness_first;
100 ++num_leds;
101 }
102
103 // SK9822 difference: end frame uses 0x00
104 size_t end_dwords = (num_leds / 32) + 1;
105 for (size_t i = 0; i < end_dwords * 4; i++) {
106 *out++ = 0x00;
107 }
108}
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_NOEXCEPT
Map 8-bit brightness to 5-bit (0-31)

References FL_NOEXCEPT, and mapBrightness8to5().

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

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