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

◆ encodeAPA102_HD()

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

Encode pixel data in APA102 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
Each LED has individual brightness (HD gamma mode)
APA102 uses BGR wire order: pixel[0]=Blue, pixel[1]=Green, pixel[2]=Red

Definition at line 86 of file apa102.h.

87 {
88 // Start frame: 4 bytes of 0x00
89 *out++ = 0x00;
90 *out++ = 0x00;
91 *out++ = 0x00;
92 *out++ = 0x00;
93
94 // LED data: brightness header + BGR (per-LED brightness, count as we go)
95 size_t num_leds = 0;
96 while (first != last) {
97 const fl::array<u8, BYTES_PER_PIXEL_RGB>& pixel = *first;
98 u8 brightness_8bit = *brightness_first;
99 u8 brightness_5bit = mapBrightness8to5(brightness_8bit);
100
101 *out++ = 0xE0 | brightness_5bit;
102 *out++ = pixel[0]; // Index 0 (BGR order: Blue)
103 *out++ = pixel[1]; // Index 1 (BGR order: Green)
104 *out++ = pixel[2]; // Index 2 (BGR order: Red)
105
106 ++first;
107 ++brightness_first;
108 ++num_leds;
109 }
110
111 // End frame: ⌈num_leds/32⌉ DWords of 0xFF
112 size_t end_dwords = (num_leds / 32) + 1;
113 for (size_t i = 0; i < end_dwords * 4; i++) {
114 *out++ = 0xFF;
115 }
116}
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::writeAPA102().

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