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

◆ encodeAPA102()

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

Encode pixel data in APA102 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
All LEDs use the same brightness value
APA102 uses BGR wire order: pixel[0]=Blue, pixel[1]=Green, pixel[2]=Red

Definition at line 45 of file apa102.h.

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

References FL_NOEXCEPT.

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

+ Here is the caller graph for this function: