FastLED 3.9.15
Loading...
Searching...
No Matches
ws2816.h
Go to the documentation of this file.
1#pragma once
2
17
18#include "fl/stl/stdint.h"
19#include "fl/stl/array.h"
20#include "fl/stl/pair.h"
21
22namespace fl {
23
24// NOTE: The old loadAndScale_WS2816_HD<RGB_ORDER>() function has been removed.
25// RGB reordering now happens upstream via ScaledPixelIteratorRGB16 adapter.
26// The encoder receives wire-ordered 16-bit RGB data (fl::array<u16, 3>).
27// For backward compatibility, WS2816Controller in chipsets.h still uses the
28// old pattern temporarily - it will be updated to use the new iterator pattern.
29
36inline pair<CRGB, CRGB> packWS2816Pixel(u16 s0, u16 s1, u16 s2) {
37 // Split each 16-bit channel into high/low bytes
38 u8 b0_hi = s0 >> 8;
39 u8 b0_lo = s0 & 0xFF;
40 u8 b1_hi = s1 >> 8;
41 u8 b1_lo = s1 & 0xFF;
42 u8 b2_hi = s2 >> 8;
43 u8 b2_lo = s2 & 0xFF;
44
45 // Pack into two CRGB pixels: [R_hi, R_lo, G_hi] and [G_lo, B_hi, B_lo]
46 return make_pair(
47 CRGB(b0_hi, b0_lo, b1_hi),
48 CRGB(b1_lo, b2_hi, b2_lo)
49 );
50}
51
60template <typename InputIterator, typename OutputIterator>
61void encodeWS2816(InputIterator first, InputIterator last, OutputIterator out) {
62 while (first != last) {
63 // Get 16-bit RGB in wire order (already scaled, color-corrected, brightness-adjusted)
64 const array<u16, 3>& rgb16 = *first;
65 u16 s0 = rgb16[0];
66 u16 s1 = rgb16[1];
67 u16 s2 = rgb16[2];
68
69 // Use the packing helper function
70 pair<CRGB, CRGB> packed = packWS2816Pixel(s0, s1, s2);
71 *out++ = packed.first;
72 *out++ = packed.second;
73
74 ++first;
75 }
76}
77
78} // namespace fl
A fixed-size array implementation similar to std::array.
Definition array.h:27
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:15
void encodeWS2816(InputIterator first, InputIterator last, OutputIterator out)
Encode 16-bit RGB pixel data into dual 8-bit RGB format for WS2816.
Definition ws2816.h:61
pair< typename fl::decay< T1 >::type, typename fl::decay< T2 >::type > make_pair(T1 &&t, T2 &&u) FL_NOEXCEPT
Definition pair.h:95
pair< CRGB, CRGB > packWS2816Pixel(u16 s0, u16 s1, u16 s2)
Pack a single 16-bit RGB pixel into two 8-bit CRGB pixels for WS2816.
Definition ws2816.h:36
Base definition for an LED controller.
Definition crgb.hpp:179
T1 first
Definition pair.h:16
T2 second
Definition pair.h:17