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

◆ encodeUCS7604()

template<typename OutputIterator>
void fl::encodeUCS7604 ( PixelIterator & pixel_iter,
size_t num_leds,
OutputIterator out,
UCS7604Mode mode,
const UCS7604CurrentControl & current,
bool is_rgbw,
const Gamma8 * gamma = nullptr )

Encode complete UCS7604 frame (preamble + padding + pixel data)

Template Parameters
OutputIteratorOutput iterator accepting uint8_t
Parameters
pixel_iterPixelIterator with pixel data and scaling/gamma/dithering
num_ledsNumber of LEDs to encode
outOutput iterator for complete frame
modeUCS7604 protocol mode (8-bit/16-bit)
currentCurrent control settings (wire order RGBW)
is_rgbwTrue for RGBW mode, false for RGB mode
gammaGamma8 LUT for 16-bit modes (nullable, ignored for 8-bit mode)
Note
Outputs: preamble (15 bytes) + padding (0-2 bytes) + LED data
Total output size is always divisible by 3 (required by UCS7604 protocol)

Definition at line 209 of file ucs7604.h.

211 {
212 constexpr size_t PREAMBLE_LEN = 15;
213
214 // Calculate bytes per LED based on mode and RGB/RGBW
215 size_t bytes_per_led;
217 bytes_per_led = is_rgbw ? 4 : 3;
218 } else {
219 bytes_per_led = is_rgbw ? 8 : 6;
220 }
221
222 // Calculate total data size and padding
223 size_t led_data_size = num_leds * bytes_per_led;
224 size_t total_data_size = PREAMBLE_LEN + led_data_size;
225 size_t padding = (3 - (total_data_size % 3)) % 3;
226
227 // Build preamble (15 bytes) with current control
228 buildUCS7604Preamble(out, mode, current.r, current.g, current.b, current.w);
229
230 // Add padding (0-2 zero bytes)
231 for (size_t i = 0; i < padding; ++i) {
232 *out++ = 0;
233 }
234
235 // Encode LED data based on mode and RGB/RGBW
237 if (is_rgbw) {
238 auto range = makeScaledPixelRangeRGBW(&pixel_iter);
239 encodeUCS7604_8bit_RGBW(range.first, range.second, out);
240 } else {
241 auto range = makeScaledPixelRangeRGB(&pixel_iter);
242 encodeUCS7604_8bit_RGB(range.first, range.second, out);
243 }
244 } else {
245 // 16-bit modes — fall back to gamma 2.8 if no gamma provided
246 static fl::shared_ptr<const Gamma8> default_gamma;
247 const Gamma8& g = gamma ? *gamma : *(default_gamma ? default_gamma : (default_gamma = Gamma8::getOrCreate(2.8f)));
248 if (is_rgbw) {
249 auto range = makeScaledPixelRangeRGBW(&pixel_iter);
250 encodeUCS7604_16bit_RGBW(range.first, range.second, out, g);
251 } else {
252 auto range = makeScaledPixelRangeRGB(&pixel_iter);
253 encodeUCS7604_16bit_RGB(range.first, range.second, out, g);
254 }
255 }
256}
static fl::shared_ptr< const Gamma8 > getOrCreate(float gamma) FL_NOEXCEPT
Definition ease.cpp.hpp:459
pair< detail::ScaledPixelIteratorRGB, detail::ScaledPixelIteratorRGB > makeScaledPixelRangeRGB(PixelIterator *pixels) FL_NOEXCEPT
Create RGB input iterator range from PixelIterator.
void buildUCS7604Preamble(OutputIterator out, UCS7604Mode mode, u8 r_current, u8 g_current, u8 b_current, u8 w_current)
Build UCS7604 preamble (15 bytes)
Definition ucs7604.h:69
void encodeUCS7604_8bit_RGB(InputIterator first, InputIterator last, OutputIterator out)
Encode RGB pixels in UCS7604 8-bit format.
Definition ucs7604.h:106
void encodeUCS7604_16bit_RGBW(InputIterator first, InputIterator last, OutputIterator out, const Gamma8 &gamma)
Encode RGBW pixels in UCS7604 16-bit format with gamma correction.
Definition ucs7604.h:174
pair< detail::ScaledPixelIteratorRGBW, detail::ScaledPixelIteratorRGBW > makeScaledPixelRangeRGBW(PixelIterator *pixels) FL_NOEXCEPT
Create RGBW input iterator range from PixelIterator.
@ UCS7604_MODE_8BIT_800KHZ
Definition ucs7604.h:29
constexpr u32 gamma(float g) FL_NOEXCEPT
Definition gamma_lut.h:36
void encodeUCS7604_8bit_RGBW(InputIterator first, InputIterator last, OutputIterator out)
Encode RGBW pixels in UCS7604 8-bit format.
Definition ucs7604.h:124
void encodeUCS7604_16bit_RGB(InputIterator first, InputIterator last, OutputIterator out, const Gamma8 &gamma)
Encode RGB pixels in UCS7604 16-bit format with gamma correction.
Definition ucs7604.h:144
u8 g
Green channel current (0x0-0xF)
Definition ucs7604.h:37
u8 b
Blue channel current (0x0-0xF)
Definition ucs7604.h:38
u8 w
White channel current (0x0-0xF)
Definition ucs7604.h:39
u8 r
Red channel current (0x0-0xF)
Definition ucs7604.h:36

References fl::UCS7604CurrentControl::b, buildUCS7604Preamble(), encodeUCS7604_16bit_RGB(), encodeUCS7604_16bit_RGBW(), encodeUCS7604_8bit_RGB(), encodeUCS7604_8bit_RGBW(), fl::UCS7604CurrentControl::g, gamma(), fl::Gamma8::getOrCreate(), makeScaledPixelRangeRGB(), makeScaledPixelRangeRGBW(), fl::UCS7604CurrentControl::r, UCS7604_MODE_8BIT_800KHZ, and fl::UCS7604CurrentControl::w.

Referenced by buildExpectedUCS7604(), fl::UCS7604ControllerT< DATA_PIN, RGB_ORDER, fl::UCS7604Mode::UCS7604_MODE_8BIT_800KHZ, fl::TIMING_UCS7604_800KHZ, CLOCKLESS_CONTROLLER >::showPixels(), and fl::anonymous_namespace{channel.cpp.hpp}::writeUCS7604().

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