FastLED 3.9.15
Loading...
Searching...
No Matches
ws2812.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"
21#include "fl/gfx/rgbw.h"
22#include "fl/gfx/rgbww.h"
23#include "fl/stl/noexcept.h"
24
25namespace fl {
26
34template <typename InputIterator, typename OutputIterator>
35void encodeWS2812_RGB(InputIterator first, InputIterator last, OutputIterator out) FL_NOEXCEPT {
36 while (first != last) {
37 const fl::array<u8, BYTES_PER_PIXEL_RGB>& pixel = *first;
38 *out++ = pixel[0]; // First byte
39 *out++ = pixel[1]; // Second byte
40 *out++ = pixel[2]; // Third byte
41 ++first;
42 }
43}
44
52template <typename InputIterator, typename OutputIterator>
53void encodeWS2812_RGBW(InputIterator first, InputIterator last, OutputIterator out) FL_NOEXCEPT {
54 while (first != last) {
55 const fl::array<u8, BYTES_PER_PIXEL_RGBW>& pixel = *first;
56 *out++ = pixel[0]; // First byte
57 *out++ = pixel[1]; // Second byte
58 *out++ = pixel[2]; // Third byte
59 *out++ = pixel[3]; // Fourth byte
60 ++first;
61 }
62}
63
72template <typename InputIterator, typename OutputIterator>
73void encodeWS2812(InputIterator first, InputIterator last, OutputIterator out, const Rgbw& rgbw) FL_NOEXCEPT {
74 if (rgbw.active()) {
75 encodeWS2812_RGBW(first, last, out);
76 } else {
77 encodeWS2812_RGB(first, last, out);
78 }
79}
80
85template <typename InputIterator, typename OutputIterator>
86void encodeWS2812_RGBWW(InputIterator first, InputIterator last, OutputIterator out) FL_NOEXCEPT {
87 while (first != last) {
88 const fl::array<u8, BYTES_PER_PIXEL_RGBWW>& pixel = *first;
89 *out++ = pixel[0];
90 *out++ = pixel[1];
91 *out++ = pixel[2];
92 *out++ = pixel[3];
93 *out++ = pixel[4];
94 ++first;
95 }
96}
97
98} // namespace fl
Rgbw rgbw
A fixed-size array implementation similar to std::array.
Definition array.h:27
Constants for SPI chipset encoders.
Functions for red, green, blue, white (RGBW) output.
void encodeWS2812_RGBWW(InputIterator first, InputIterator last, OutputIterator out) FL_NOEXCEPT
Encode 5-byte pixel data in WS2812 format (issue #2558, RGBWW).
Definition ws2812.h:86
void encodeWS2812(InputIterator first, InputIterator last, OutputIterator out, const Rgbw &rgbw) FL_NOEXCEPT
Encode pixel data in WS2812 format (automatic RGB/RGBW selection)
Definition ws2812.h:73
void encodeWS2812_RGB(InputIterator first, InputIterator last, OutputIterator out) FL_NOEXCEPT
Encode 3-byte pixel data in WS2812 format.
Definition ws2812.h:35
void encodeWS2812_RGBW(InputIterator first, InputIterator last, OutputIterator out) FL_NOEXCEPT
Encode 4-byte pixel data in WS2812 format.
Definition ws2812.h:53
Base definition for an LED controller.
Definition crgb.hpp:179
5-channel RGB + warm-W + cool-W (RGBWW / RGBCCT) configuration types (issue #2558,...
#define FL_NOEXCEPT