FastLED 3.9.15
Loading...
Searching...
No Matches
FastLED.cpp.hpp
Go to the documentation of this file.
1#define FASTLED_INTERNAL
2// IWYU pragma: begin_keep
3#include <stdint.h>
4// IWYU pragma: end_keep // for u8, u32, u16
5#include "FastLED.h"
11#include "fl/channels/manager.h"
12#include "fl/system/trace.h"
13#include "fl/channels/driver.h" // for IChannelDriver
14#include "fl/channels/detail/wait_spin_budget.h" // for tiered-wait spin-budget setters (#2818)
15#include "fl/system/delay.h" // for delayMicroseconds
16#include "fl/system/yield.h" // for fl::yield
18#if SKETCH_HAS_LARGE_MEMORY
19#include "fl/task/executor.h" // for task::run (WiFi yield in show() spin loop)
20#endif
21#include "fl/log/log.h" // for FL_WARN
22#include "fl/stl/assert.h" // for FL_ASSERT
23#include "fl/audio/audio_manager.h" // for AudioManager
24#include "hsv2rgb.h" // for CRGB
25#include "fl/stl/int.h" // for u32, u16
26#include "platforms/init.h" // IWYU pragma: keep
27#include "fl/channels/config.h" // for ChannelConfig
28#include "fl/stl/singleton.h" // for fl::Singleton
29#include "platforms/is_platform.h"
30
33
34#ifndef MAX_CLED_CONTROLLERS
35#ifdef FL_IS_AVR
36// if mega or leonardo, allow more controllers
37#if defined(FL_IS_AVR_ATMEGA_2560) || defined(FL_IS_AVR_ATMEGA)
38#define MAX_CLED_CONTROLLERS 16
39#else
40#define MAX_CLED_CONTROLLERS 8
41#endif
42#else
43#define MAX_CLED_CONTROLLERS 64
44#endif // FL_IS_AVR
45#endif // MAX_CLED_CONTROLLERS
46
47#if defined(FL_IS_SAM)
48volatile fl::u32 fuckit;
49#endif
50
51
52#ifndef FASTLED_NO_ATEXIT
53#define FASTLED_NO_ATEXIT 0
54#endif
55
56#if !FASTLED_NO_ATEXIT
57extern "C" FL_LINK_WEAK int atexit(void (* /*func*/ )()) { return 0; }
58#endif
59
60#ifdef FASTLED_NEEDS_YIELD
61extern "C" void yield(void) { }
62#endif
63
64// Implementation of cled_contoller_size() moved to src/fl/fastled_internal.cpp
65
67
70void *pSmartMatrix = nullptr;
71
74
75CFastLED FastLED; // global constructor allowed in this case.
76
78
81static fl::u32 lastshow = 0;
82
85fl::u32 _frame_cnt=0;
86
89fl::u32 _retry_cnt=0;
90
91// uint32_t CRGB::Squant = ((uint32_t)((__TIME__[4]-'0') * 28))<<16 | ((__TIME__[6]-'0')*50)<<8 | ((__TIME__[7]-'0')*28);
92
94 // clear out the array of led controllers
95 // m_nControllers = 0;
96 mScale = 255;
97 mNFPS = 0;
98 mPPowerFunc = nullptr;
99 mNPowerData = 0xFFFFFFFF;
100 mNMinMicros = 0;
101}
102
104 // Call platform-specific initialization once
105 // Uses the trampoline pattern: platforms/init.h dispatches to platform-specific headers
106 // FL_RUN_ONCE ensures this is only called once, even if init() is called multiple times
107 FL_RUN_ONCE(fl::platforms::init());
108}
109
111 return (*this)[0].size();
112}
113
115 return (*this)[0].leds();
116}
117
119 CRGB *data,
120 int nLedsOrOffset, int nLedsIfOffset) {
121 int nOffset = (nLedsIfOffset > 0) ? nLedsOrOffset : 0;
122 int nLeds = (nLedsIfOffset > 0) ? nLedsIfOffset : nLedsOrOffset;
123
124 pLed->init();
125 pLed->setLeds(data + nOffset, nLeds);
126 FastLED.setMaxRefreshRate(pLed->getMaxRefreshRate(),true);
127 fl::EngineEvents::onStripAdded(pLed, nLedsOrOffset - nOffset);
128 return *pLed;
129}
130
134
135void CFastLED::add(fl::ChannelPtr channel) {
136 if (!channel) {
137 return;
138 }
139 auto& chnls = channels();
140 // Protect against double-add
141 if (chnls.has(channel)) {
142 return;
143 }
144 chnls.push_back(channel);
145 // Add channel to the CLEDController linked list
146 // Channel uses DeferRegister mode, so explicit addToDrawList() call is required
147 // Note: addToDrawList() now fires onChannelAdded event
148 channel->addToDrawList();
149}
150
151void CFastLED::remove(fl::ChannelPtr channel) {
152 if (!channel) {
153 return;
154 }
155 // Note: removeFromDrawList() now fires onChannelRemoved event
156 channel->removeFromDrawList();
157 // Remove from internal storage (safe if not found - erase is a no-op)
158 channels().erase(channel);
159}
160
162 // Lambda to check if flag is set, clear it, and return true if it was set
163 auto clearFlag = [&flags](ClearFlags flag) -> bool {
164 if ((flags & flag) != ClearFlags::NONE) {
165 flags = static_cast<ClearFlags>(static_cast<fl::u32>(flags) & ~static_cast<fl::u32>(flag));
166 return true;
167 }
168 return false;
169 };
170
171
172 // Reset POWER_SETTINGS - reset power management to defaults
173 if (clearFlag(ClearFlags::POWER_SETTINGS)) {
174 FastLED.mPPowerFunc = nullptr; // No power limiting function
175 FastLED.mNPowerData = 0xFFFFFFFF; // No power limit (max value)
176 }
177
178 // Reset BRIGHTNESS - reset global brightness to 255 (full brightness)
179 if (clearFlag(ClearFlags::BRIGHTNESS)) {
180 FastLED.mScale = 255;
181 }
182
183 // Reset REFRESH_RATE - reset refresh rate limiting to unlimited
184 if (clearFlag(ClearFlags::REFRESH_RATE)) {
185 FastLED.mNMinMicros = 0; // No minimum delay between frames
186 }
187
188 // Reset FPS_COUNTER - reset FPS tracking counter to 0
189 if (clearFlag(ClearFlags::FPS_COUNTER)) {
190 FastLED.mNFPS = 0;
191 }
192
193 // Reset CHANNELS - remove all channels from controller list
194 if (clearFlag(ClearFlags::CHANNELS)) {
195 // Wait for engines to complete, with 2s timeout to prevent infinite hang
196 // if an engine is permanently stalled (e.g. PARLIO on ESP32-C6 hw bug)
197 FastLED.wait(2000);
198
199 // Remove all channels by iterating through a copy of the vector
200 // (we make a copy because remove() modifies channels())
201 fl::vector<fl::ChannelPtr> channelsCopy = channels();
202 for (auto& channel : channelsCopy) {
203 remove(channel);
204 }
205
206 // Reset bus manager state (clear enqueued and transmitting channels)
208 manager.reset();
209
210 // Clear the internal storage (should already be empty, but ensure it)
211 channels().clear();
212 }
213
214 // Reset CHANNEL_ENGINES - clear all registered channel drivers
215 if (clearFlag(ClearFlags::CHANNEL_ENGINES)) {
216 // Always wait for all channel bus transmissions to complete first
217 FastLED.wait();
219 manager.clearAllDrivers();
220 }
221
222 // Ensure all flags were handled - catches typos or missing implementations
223 FL_ASSERT(flags == ClearFlags::NONE, "Unhandled flags in FastLED.clear()");
224}
225
226// This is bad code. But it produces the smallest binaries for reasons
227// beyond mortal comprehensions.
228// Instead of iterating through the link list for onBeginFrame(), beginShowLeds()
229// and endShowLeds(): store the pointers in an array and iterate through that.
230//
231// static uninitialized gControllersData produces the smallest binary on attiny85.
233
236 onBeginFrame();
237 while(mNMinMicros && ((fl::micros()-lastshow) < mNMinMicros)) {
238#if SKETCH_HAS_LARGE_MEMORY
240#endif
241 }
243
244 // If we have a function for computing power, use it!
245 if(mPPowerFunc) {
246 scale = (*mPPowerFunc)(scale, mNPowerData);
247 }
248
249
250 int length = 0;
252
253 while(pCur && length < MAX_CLED_CONTROLLERS) {
254 if (pCur->getEnabled()) {
255 gControllersData[length] = pCur->beginShowLeds(pCur->size());
256 } else {
257 gControllersData[length] = nullptr;
258 }
259 length++;
260 if (mNFPS < 100) { pCur->setDither(0); }
261 pCur = pCur->next();
262 }
263
264 pCur = CLEDController::head();
265 for (length = 0; length < MAX_CLED_CONTROLLERS && pCur; length++) {
266 if (pCur->getEnabled()) {
267 pCur->showLedsInternal(scale);
268 }
269 pCur = pCur->next();
270
271 }
272
273 length = 0; // Reset length to 0 and iterate again.
274 pCur = CLEDController::head();
275 while(pCur && length < MAX_CLED_CONTROLLERS) {
276 if (pCur->getEnabled()) {
278 }
279 length++;
280 pCur = pCur->next();
281 }
282 countFPS();
283 onEndFrame();
285}
286
288 #if FASTLED_HAS_ENGINE_EVENTS
290 #endif
291}
292
294 int x = 0;
296 while( pCur) {
297 ++x;
298 pCur = pCur->next();
299 }
300 return x;
301}
302
305 while(x-- && pCur) {
306 pCur = pCur->next();
307 }
308 if(pCur == nullptr) {
309 return *(CLEDController::head());
310 } else {
311 return *pCur;
312 }
313}
314
315void CFastLED::showColor(const CRGB & color, fl::u8 scale) {
316 while(mNMinMicros && ((fl::micros()-lastshow) < mNMinMicros)) {
317#if SKETCH_HAS_LARGE_MEMORY
319#endif
320 }
322
323 // If we have a function for computing power, use it!
324 if(mPPowerFunc) {
325 scale = (*mPPowerFunc)(scale, mNPowerData);
326 }
327
328 int length = 0;
330 while(pCur && length < MAX_CLED_CONTROLLERS) {
331 if (pCur->getEnabled()) {
332 gControllersData[length] = pCur->beginShowLeds(pCur->size());
333 } else {
334 gControllersData[length] = nullptr;
335 }
336 length++;
337 pCur = pCur->next();
338 }
339
340 pCur = CLEDController::head();
341 while(pCur && length < MAX_CLED_CONTROLLERS) {
342 if(mNFPS < 100) { pCur->setDither(0); }
343 if (pCur->getEnabled()) {
344 pCur->showColorInternal(color, scale);
345 }
346 pCur = pCur->next();
347 }
348
349 pCur = CLEDController::head();
350 length = 0; // Reset length to 0 and iterate again.
351 while(pCur && length < MAX_CLED_CONTROLLERS) {
352 if (pCur->getEnabled()) {
354 }
355 length++;
356 pCur = pCur->next();
357 }
358 countFPS();
359 onEndFrame();
360}
361
362void CFastLED::clear(bool writeData) {
363 if(writeData) {
364 showColor(CRGB(0,0,0), 0);
365 }
366 clearData();
367}
368
371 while(pCur) {
372 pCur->clearLedDataInternal();
373 pCur = pCur->next();
374 }
375}
376
377void CFastLED::delay(unsigned long ms) {
378 unsigned long start = fl::millis();
379 do {
380#ifndef FASTLED_ACCURATE_CLOCK
381 // make sure to allow at least one ms to pass to ensure the clock moves
382 // forward
383 fl::delay(1);
384#endif
385 show();
386 fl::yield();
387 }
388 while((fl::millis()-start) < ms);
389}
390
391void CFastLED::setTemperature(const CRGB & temp) {
393 while(pCur) {
394 pCur->setTemperature(temp);
395 pCur = pCur->next();
396 }
397}
398
399void CFastLED::setCorrection(const CRGB & correction) {
401 while(pCur) {
402 pCur->setCorrection(correction);
403 pCur = pCur->next();
404 }
405}
406
407void CFastLED::setDither(fl::u8 ditherMode) {
409 while(pCur) {
410 pCur->setDither(ditherMode);
411 pCur = pCur->next();
412 }
413}
414
415fl::u32 CFastLED::getEstimatedPowerInMilliWatts(bool apply_limiter) const {
416 fl::u32 total_power_mW = 0;
417
418 // Sum unscaled power from all LED controllers using visitor pattern
419 CLEDController::visitControllers([&total_power_mW](const CLEDController* /*controller*/, fl::span<const CRGB> leds) {
420 if (!leds.empty()) {
421 total_power_mW += calculate_unscaled_power_mW(leds);
422 }
423 });
424
425 // Determine effective brightness
426 fl::u8 effective_brightness = mScale;
427
428 if (apply_limiter && mPPowerFunc) {
429 // Power limiting is enabled and user wants limited power - calculate brightness after limiting
430 // This calls calculate_max_brightness_for_power_mW(mScale, mNPowerData)
431 effective_brightness = (*mPPowerFunc)(mScale, mNPowerData);
432 }
433
434 // Scale by the configured power-brightness response.
435 // Note: MCU power consumption is NOT included - caller should add platform-specific MCU power if needed
436 return scale_power_for_brightness(total_power_mW, effective_brightness);
437}
438
439//
440// template<int m, int n> void transpose8(unsigned char A[8], unsigned char B[8]) {
441// uint32_t x, y, t;
442//
443// // Load the array and pack it into x and y.
444// y = *(unsigned int*)(A);
445// x = *(unsigned int*)(A+4);
446//
447// // x = (A[0]<<24) | (A[m]<<16) | (A[2*m]<<8) | A[3*m];
448// // y = (A[4*m]<<24) | (A[5*m]<<16) | (A[6*m]<<8) | A[7*m];
449//
450 // // pre-transform x
451 // t = (x ^ (x >> 7)) & 0x00AA00AA; x = x ^ t ^ (t << 7);
452 // t = (x ^ (x >>14)) & 0x0000CCCC; x = x ^ t ^ (t <<14);
453 //
454 // // pre-transform y
455 // t = (y ^ (y >> 7)) & 0x00AA00AA; y = y ^ t ^ (t << 7);
456 // t = (y ^ (y >>14)) & 0x0000CCCC; y = y ^ t ^ (t <<14);
457 //
458 // // final transform
459 // t = (x & 0xF0F0F0F0) | ((y >> 4) & 0x0F0F0F0F);
460 // y = ((x << 4) & 0xF0F0F0F0) | (y & 0x0F0F0F0F);
461 // x = t;
462//
463// B[7*n] = y; y >>= 8;
464// B[6*n] = y; y >>= 8;
465// B[5*n] = y; y >>= 8;
466// B[4*n] = y;
467//
468// B[3*n] = x; x >>= 8;
469// B[2*n] = x; x >>= 8;
470// B[n] = x; x >>= 8;
471// B[0] = x;
472// // B[0]=x>>24; B[n]=x>>16; B[2*n]=x>>8; B[3*n]=x>>0;
473// // B[4*n]=y>>24; B[5*n]=y>>16; B[6*n]=y>>8; B[7*n]=y>>0;
474// }
475//
476// void transposeLines(Lines & out, Lines & in) {
477// transpose8<1,2>(in.bytes, out.bytes);
478// transpose8<1,2>(in.bytes + 8, out.bytes + 1);
479// }
480
481
484extern int noise_min;
485
488extern int noise_max;
489
490void CFastLED::countFPS(int nFrames) {
491 static int br = 0;
492 static fl::u32 lastframe = 0; // fl::millis();
493
494 if(br++ >= nFrames) {
495 fl::u32 now = fl::millis();
496 now -= lastframe;
497 if(now == 0) {
498 now = 1; // prevent division by zero below
499 }
500 mNFPS = (br * 1000) / now;
501 br = 0;
502 lastframe = fl::millis();
503 }
504}
505
506void CFastLED::setMaxRefreshRate(fl::u16 refresh, bool constrain) {
507 if(constrain) {
508 // if we're constraining, the new value of mNMinMicros _must_ be higher than previously (because we're only
509 // allowed to slow things down if constraining)
510 if(refresh > 0) {
511 mNMinMicros = ((1000000 / refresh) > mNMinMicros) ? (1000000 / refresh) : mNMinMicros;
512 }
513 } else if(refresh > 0) {
514 mNMinMicros = 1000000 / refresh;
515 } else {
516 mNMinMicros = 0;
517 }
518}
519
520
522 return FastLED.getBrightness();
523}
524
525// ============================================================================
526// Deprecated Power Management Wrapper Functions
527// ============================================================================
528// These functions wrap the CFastLED singleton methods for backward compatibility.
529// They were originally in power_mgt.cpp but have been moved here to avoid
530// circular dependencies (power_mgt.cpp should not include FastLED.h).
531
532void set_max_power_in_volts_and_milliamps(fl::u8 volts, fl::u32 milliamps)
533{
534 FastLED.setMaxPowerInVoltsAndMilliamps(volts, milliamps);
535}
536
537void set_max_power_in_milliwatts(fl::u32 powerInmW)
538{
539 FastLED.setMaxPowerInMilliWatts(powerInmW);
540}
541
543{
544 // power management usage is now in FastLED.show, no need for this function
545 FastLED.show();
546}
547
549{
550 FastLED.delay(ms);
551}
552
553// ============================================================================
554// Channel Bus Manager Controls
555// ============================================================================
556
560
561void CFastLED::setDriverEnabled(const char* name, bool enabled) {
563 manager.setDriverEnabled(name, enabled);
564}
565
568 return manager.setExclusiveDriver(bus);
569}
570
571bool CFastLED::isDriverEnabled(const char* name) const {
573 return manager.isDriverEnabled(name);
574}
575
576fl::size CFastLED::getDriverCount() const {
578 return manager.getDriverCount();
579}
580
585
586// ============================================================================
587// Wait for channel bus transmissions
588// ============================================================================
589
592 // Wait for all drivers to become READY
593 // Calls async_run() and uses time-based delays to avoid busy-waiting
594 manager.waitForReady();
595}
596
597bool CFastLED::wait(fl::u32 timeout_ms) {
599 return manager.waitForReady(timeout_ms);
600}
601
602// Tiered-wait spin-budget shims (#2818). Storage in
603// src/fl/channels/detail/wait_spin_budget.cpp.hpp.
607
611
612// ============================================================================
613// Runtime Channel API Implementation
614// ============================================================================
615
616fl::ChannelPtr CFastLED::add(const fl::ChannelConfig& config) {
617 // Issue #2459: the non-template `FastLED.add(cfg)` path is the runtime-
618 // selection mode. To make sure `cfg.options.mBus` (or priority dispatch
619 // when `mBus == Bus::AUTO`) can actually find the requested driver at
620 // runtime, we eagerly enroll every driver available on this platform.
621 // That trades binary size for ergonomics — the user wanted runtime
622 // selection, so they get runtime selection.
623 //
624 // For minimum binary size, callers should use the compile-time path:
625 // FastLED.addLeds<CHIPSET, PIN, ORDER, fl::Bus::X>(leds, n);
626 // which ODR-uses only `BusTraits<X>::instancePtr()` and lets
627 // `--gc-sections` drop every other driver TU.
628 //
629 // The warning fires at most once per process (FL_WARN_ONCE) and can be
630 // disabled with `-DFASTLED_SUPPRESS_RUNTIME_DRIVER_WARNING`.
631 #ifndef FASTLED_SUPPRESS_RUNTIME_DRIVER_WARNING
632 FL_WARN_ONCE("FastLED.add(cfg): runtime-selection mode — enrolling every "
633 "available driver via fl::enableAllDrivers(). For minimum "
634 "binary size, prefer FastLED.addLeds<CHIPSET, PIN, ORDER, "
635 "fl::Bus::X>(leds, n) which links only the named driver. "
636 "Suppress this warning with -DFASTLED_SUPPRESS_RUNTIME_DRIVER_WARNING.");
637 #endif
639
641 FL_ASSERT(manager.getDriverCount() > 0,
642 "No channel drivers available - channel API requires at least one registered driver");
643 auto channel = fl::Channel::create(config);
644 add(channel);
645 return channel;
646}
647
650 channels.reserve(configs.size());
651
652 for (const auto& config : configs) {
653 channels.push_back(add(config));
654 }
655
656 return channels;
657}
658
659fl::vector<fl::ChannelPtr> CFastLED::add(fl::initializer_list<fl::ChannelConfig> configs) {
661 channels.reserve(configs.size());
662
663 for (const auto& config : configs) {
664 channels.push_back(add(config));
665 }
666
667 return channels;
668}
669
672 channels.reserve(multiConfig.mChannels.size());
673
674 for (const auto& configPtr : multiConfig.mChannels) {
675 if (configPtr) {
676 channels.push_back(add(*configPtr));
677 }
678 }
679
680 return channels;
681}
682
683fl::RxChannelPtr CFastLED::addRx(const fl::RxChannelConfig& config) {
684 return fl::RxChannel::create(config);
685}
686
687// ============================================================================
688
689#ifdef NEED_CXX_BITS
690namespace __cxxabiv1
691{
692 #if !defined(FL_IS_ESP8266) && !defined(FL_IS_ESP32) && !defined(ARDUINO)
693 extern "C" void __cxa_pure_virtual (void) {}
694 #endif
695
696 /* guard variables */
697
698 /* The ABI requires a 64-bit type. */
699 __extension__ typedef int __guard __attribute__((mode(__DI__)));
700
701 extern "C" int __cxa_guard_acquire (__guard *) FL_LINK_WEAK;
702 extern "C" void __cxa_guard_release (__guard *) FL_LINK_WEAK;
703 extern "C" void __cxa_guard_abort (__guard *) FL_LINK_WEAK;
704
705 extern "C" int __cxa_guard_acquire (__guard *g)
706 {
707 return !*(char *)(g);
708 }
709
710 extern "C" void __cxa_guard_release (__guard *g)
711 {
712 *(char *)g = 1;
713 }
714
715 extern "C" void __cxa_guard_abort (__guard *)
716 {
717
718 }
719}
720#endif
721
722
724 #if FASTLED_HAS_ENGINE_EVENTS
726 #endif
727}
728
729
731 #if FASTLED_HAS_ENGINE_EVENTS
733 #endif
734}
735
739
743
744// ============================================================================
745// CFastLED audio method implementations - thin trampolines to AudioManager
746// ============================================================================
747
752
757
762
int x
Definition simple.h:92
#define MAX_CLED_CONTROLLERS
FL_LINK_WEAK int atexit(void(*)())
void * pSmartMatrix
Pointer to the matrix object when using the Smart Matrix Library.
static fl::u32 lastshow
fl::u32 _retry_cnt
Global frame retry counter, used for debugging ESP implementations.
static void * gControllersData[MAX_CLED_CONTROLLERS]
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
int noise_max
Unused value.
fl::u32 _frame_cnt
Global frame counter, used for debugging ESP implementations.
fl::u8 get_brightness()
int noise_min
Unused value.
ClearFlags
Flags for FastLED.clear() to control what state gets cleared/reset.
Definition FastLED.h:578
@ CHANNELS
Remove all channels from controller list.
Definition FastLED.h:580
@ BRIGHTNESS
Reset global brightness to 255.
Definition FastLED.h:582
@ CHANNEL_ENGINES
Clear all channel drivers from ChannelManager.
Definition FastLED.h:585
@ POWER_SETTINGS
Reset power management (setMaxPowerInMilliWatts)
Definition FastLED.h:581
@ FPS_COUNTER
Reset FPS tracking counter to 0.
Definition FastLED.h:584
@ NONE
Clear nothing (no-op)
Definition FastLED.h:579
@ REFRESH_RATE
Reset refresh rate limiting to unlimited.
Definition FastLED.h:583
CFastLED FastLED
Global LED strip management instance.
central include file for FastLED, defines the CFastLED class/object
fl::UISlider scale("Scale", 4,.1, 4,.1)
Declaration of fl::enableAllDrivers() — enrolls every channel driver available on the current platfor...
#define FL_ASSERT(x, MSG)
Definition assert.h:6
ESP32-P4 Parallel IO (PARLIO) LED channel.
static void enableAllDrivers()
Enroll every channel driver available on this platform with ChannelManager.
power_func mPPowerFunc
function for overriding brightness when using FastLED.show();
Definition FastLED.h:616
fl::u32 getEstimatedPowerInMilliWatts(bool apply_limiter=true) const
Get estimated power consumption in milliwatts.
void onEndFrame()
static fl::vector< fl::ChannelPtr > & channels()
stored ChannelPtrs to keep them alive
int size()
Get the number of leds in the first controller.
CRGB * leds()
Get a pointer to led data for the first controller.
bool isDriverEnabled(const char *name) const
Check if a driver is enabled by name.
void onEndShowLeds()
Manually trigger the end show LEDs event.
void setMaxRefreshRate(fl::u16 refresh, bool constrain=false)
Set the maximum refresh rate.
static fl::RxChannelPtr addRx(const fl::RxChannelConfig &config)
Add an RX channel with runtime configuration.
void setTemperature(const CRGB &temp)
Set a global color temperature.
void show()
Update all our controllers with the current led colors.
Definition FastLED.h:1649
void onBeginFrame()
Manually trigger the begin frame event.
static void remove(fl::ChannelPtr channel)
Remove a channel from the LED controller list.
void showColor(const CRGB &color, fl::u8 scale)
Set all leds on all controllers to the given color/scale.
void countFPS(int nFrames=25)
For debugging, this will keep track of time between calls to countFPS().
CLEDController & operator[](int x)
Get a reference to a registered controller.
void delay(unsigned long ms)
Delay for the given number of milliseconds.
void setExclusiveDriver() FL_NOEXCEPT
Register a single driver at a priority above the platform default (compile-time TU-linking variant).
Definition FastLED.h:1408
static void _setWaitSpinBudgetUs(fl::u32 budget_us) FL_NOEXCEPT
fl::u8 mScale
the current global brightness scale setting
Definition FastLED.h:612
void setDither(fl::u8 ditherMode=BINARY_DITHER)
Set the dithering mode.
fl::size getDriverCount() const
Get count of registered channel drivers.
static fl::Watchdog & watchdog()
Access the unified cross-platform watchdog timer.
fl::u32 mNPowerData
max power use parameter
Definition FastLED.h:615
static fl::u32 _getWaitSpinBudgetUs() FL_NOEXCEPT
fl::u16 mNFPS
tracking for current frames per second (FPS) value
Definition FastLED.h:613
fl::u32 mNMinMicros
minimum µs between frames, used for capping frame rates
Definition FastLED.h:614
void init()
Initialize platform-specific subsystems.
static void add(fl::ChannelPtr channel)
Add a Channel-based LED controller (from ChannelPtr)
void clearData()
Clear out the local data array.
int count()
Get how many controllers have been registered.
void wait()
Wait for all channel bus transmissions to complete.
void clear(bool writeData=false)
Clear the leds, wiping the local array of data.
void setCorrection(const CRGB &correction)
Set a global color correction.
::CLEDController & addLeds(::CLEDController *pLed, CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
fl::span< const fl::DriverInfo > getDriverInfos() const
Get full state of all registered channel drivers.
static fl::ChannelEvents & channelEvents()
Access the channel event system.
High level controller interface for FastLED.
Definition FastLED.h:610
CLEDController & setCorrection(CRGB correction) FL_NOEXCEPT
The color corrction to use for this controller, expressed as a CRGB object.
virtual void * beginShowLeds(int size) FL_NOEXCEPT
void clearLedDataInternal(int nLeds=-1) FL_NOEXCEPT
Zero out the LED data managed by this controller.
virtual void endShowLeds(void *data) FL_NOEXCEPT
static CLEDController * mPTail
pointer to the last LED controller in the linked list
CLEDController & setLeds(CRGB *data, int nLeds) FL_NOEXCEPT
Set the default array of LEDs to be used by this controller.
void showLedsInternal(fl::u8 brightness) FL_NOEXCEPT
Write the data to the LEDs managed by this controller.
CLEDController & setDither(fl::u8 ditherMode=BINARY_DITHER) FL_NOEXCEPT
Set the dithering mode for this controller to use.
CLEDController * next() FL_NOEXCEPT
Get the next controller in the linked list after this one.
virtual void init() FL_NOEXCEPT=0
Initialize the LED controller.
virtual fl::u16 getMaxRefreshRate() const FL_NOEXCEPT
Gets the maximum possible refresh rate of the strip.
static void visitControllers(Visitor &&visitor) FL_NOEXCEPT
Visit all controllers in the linked list with a visitor The visitor must be a callable that accepts (...
virtual int size() const FL_NOEXCEPT
How many LEDs does this controller manage?
static CLEDController * mPHead
pointer to the first LED controller in the linked list
CLEDController & setTemperature(CRGB temperature) FL_NOEXCEPT
Set the color temperature, aka white point, for this controller.
static CLEDController * head() FL_NOEXCEPT
Get the first LED controller in the linked list of controllers.
bool getEnabled() FL_NOEXCEPT
void showColorInternal(const CRGB &data, int nLeds, fl::u8 brightness) FL_NOEXCEPT
bool isDriverEnabled(const char *name) const FL_NOEXCEPT
Check if a driver is enabled by name.
void setDriverEnabled(const char *name, bool enabled) FL_NOEXCEPT
Enable or disable a driver by name at runtime.
void setExclusiveDriver() FL_NOEXCEPT
Register a single driver at a priority above the platform default and disable all others (compile-tim...
Definition manager.h:322
void reset() FL_NOEXCEPT
Reset bus manager state, clearing all enqueued and transmitting channels.
fl::span< const DriverInfo > getDriverInfos() const FL_NOEXCEPT
Get full state of all registered drivers.
fl::size getDriverCount() const FL_NOEXCEPT
Get count of registered drivers (including unnamed ones)
bool waitForReady(u32 timeoutMs=1000) FL_NOEXCEPT
Wait for all drivers to become READY.
void clearAllDrivers() FL_NOEXCEPT
Remove all drivers from the manager.
Unified channel manager with priority-based driver selection.
Definition manager.h:50
static void onStripAdded(CLEDController *strip, fl::u32 num_leds) FL_NOEXCEPT
static void onEndShowLeds() FL_NOEXCEPT
static void onEndFrame() FL_NOEXCEPT
static void onBeginFrame() FL_NOEXCEPT
static RxChannelPtr create(const RxChannelConfig &config) FL_NOEXCEPT
static Watchdog & instance() FL_NOEXCEPT
Unified cross-platform watchdog interface.
Definition watchdog.h:123
shared_ptr< Processor > add(const Config &config) FL_NOEXCEPT
static AudioManager & instance() FL_NOEXCEPT
void remove(shared_ptr< Processor > processor) FL_NOEXCEPT
constexpr fl::size size() const FL_NOEXCEPT
Definition span.h:458
fl::size size() const FL_NOEXCEPT
fl::CLEDController CLEDController
Delay utilities for FastLED Includes nanosecond-precision delays, cycle counting, and microsecond del...
fl::UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
Task executor — runs registered task runners and manages the run loop.
fl::CRGB CRGB
Definition crgb.h:25
void show_at_max_brightness_for_power()
Similar to CFastLED::show(), but pre-adjusts brightness to keep below the power threshold.
fl::u32 scale_power_for_brightness(fl::u32 total_mW, fl::u8 brightness)
Applies the configured power-scaling response to a total power value.
void delay_at_max_brightness_for_power(fl::u16 ms)
Similar to CFastLED::delay(), but pre-adjusts brightness to keep below the power threshold.
void set_max_power_in_volts_and_milliamps(fl::u8 volts, fl::u32 milliamps)
Set the maximum power used in milliamps for a given voltage.
void set_max_power_in_milliwatts(fl::u32 powerInmW)
Set the maximum power used in watts.
fl::u32 calculate_unscaled_power_mW(fl::span< const CRGB > leds)
Functions to convert from the HSV colorspace to the RGB colorspace.
#define FL_WARN_ONCE(X)
Definition log.h:278
Centralized logging categories for FastLED hardware interfaces and subsystems.
Unified manager for channel drivers with priority-based fallback.
fl::u32 getWaitSpinBudgetUs() FL_NOEXCEPT
Get the current tiered-wait spin budget (microseconds).
void setWaitSpinBudgetUs(fl::u32 budget_us) FL_NOEXCEPT
Set the tiered-wait spin budget (microseconds).
void run(fl::u32 microseconds, ExecFlags flags)
Run selected task subsystems.
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
Definition move.h:28
unsigned char u8
Definition stdint.h:131
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
void delay(u32 ms, bool run_async=true) FL_NOEXCEPT
Public delay wrapper that keeps bare Arduino delay() preferred after using fl::delay; while still all...
Definition delay.h:98
Bus
Driver identifier for compile-time bus selection.
Definition bus.h:60
ChannelManager & channelManager()
Get the global ChannelManager singleton instance.
fl::u32 micros()
Universal microsecond timer - returns microseconds since system startup.
void yield()
Yield to the platform scheduler.
Definition yield.cpp.hpp:31
void enableAllDrivers() FL_NOEXCEPT
Register every channel driver available on this platform with ChannelManager, restoring 3....
#define FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS
#define FL_DISABLE_WARNING_PUSH
#define FL_KEEP_ALIVE
#define FL_RUN_ONCE(code)
#define FL_DISABLE_WARNING_POP
#define FL_MAYBE_UNUSED
#define FL_NOEXCEPT
#define FL_LINK_WEAK
Configuration for a single LED channel.
Definition config.h:163
static ChannelEvents & instance()
Singleton event router for Channel lifecycle events.
fl::vector< ChannelConfigPtr > mChannels
Vector of shared pointers to channel configurations.
Definition config.h:392
#define FL_SCOPED_TRACE
Definition trace.h:128
Runtime-tunable microsecond spin budget for the channel-manager and driver wait loops (Phase 1 of #28...
Platform-aware cooperative yield for FastLED.