FastLED 3.10.9
Loading...
Searching...
No Matches

◆ clear() [2/2]

void CFastLED::clear ( ClearFlags flags)
static

Clear/reset FastLED state based on the provided flags.

Waits for all pending channel bus transmissions to complete, then clears the specified settings. Multiple flags can be combined using bitwise OR (|).

Parameters
flagsSettings to clear (REQUIRED). Can be OR'd together:
// Clear only channels
// Clear power settings and brightness
@ CHANNELS
Remove all channels from controller list.
Definition FastLED.h:663
@ BRIGHTNESS
Reset global brightness to 255.
Definition FastLED.h:665
@ POWER_SETTINGS
Reset power management (setMaxPowerInMilliWatts)
Definition FastLED.h:664
CFastLED FastLED
Global LED strip management instance.

Definition at line 242 of file FastLED.cpp.hpp.

242 {
243 // Lambda to check if flag is set, clear it, and return true if it was set
244 auto clearFlag = [&flags](ClearFlags flag) -> bool {
245 if ((flags & flag) != ClearFlags::NONE) {
246 flags = static_cast<ClearFlags>(static_cast<fl::u32>(flags) & ~static_cast<fl::u32>(flag));
247 return true;
248 }
249 return false;
250 };
251
252
253 // Reset POWER_SETTINGS - reset power management to defaults
254 if (clearFlag(ClearFlags::POWER_SETTINGS)) {
255 FastLED.mPPowerFunc = nullptr; // No power limiting function
256 FastLED.mNPowerData = 0xFFFFFFFF; // No power limit (max value)
259 }
260
261 // Reset BRIGHTNESS - reset global brightness to 255 (full brightness)
262 if (clearFlag(ClearFlags::BRIGHTNESS)) {
263 FastLED.mScale = 255;
264 }
265
266 // Reset REFRESH_RATE - reset refresh rate limiting to unlimited
267 if (clearFlag(ClearFlags::REFRESH_RATE)) {
268 FastLED.mMaxRefreshHz = 0; // No minimum delay between frames
269 }
270
271 // Reset FPS_COUNTER - reset FPS tracking counter to 0
272 if (clearFlag(ClearFlags::FPS_COUNTER)) {
273 FastLED.mNFPS = 0;
274 }
275
276 // Reset CHANNELS - remove all channels from controller list
277 if (clearFlag(ClearFlags::CHANNELS)) {
278 // Wait for engines to complete, with 2s timeout to prevent infinite hang
279 // if an engine is permanently stalled (e.g. PARLIO on ESP32-C6 hw bug)
280 FastLED.wait(2000);
281
282 // Remove all channels by iterating through a copy of the vector
283 // (we make a copy because remove() modifies channels())
284 fl::vector<fl::ChannelPtr> channelsCopy = channels();
285 for (auto& channel : channelsCopy) {
286 remove(channel);
287 }
288
289 // Reset bus manager state (clear enqueued and transmitting channels)
290 fl::ChannelManager& manager = fl::channelManager();
291 manager.reset();
292
293 // Clear the internal storage (should already be empty, but ensure it)
294 channels().clear();
295 }
296
297 // Reset CHANNEL_ENGINES - clear all registered channel drivers
298 if (clearFlag(ClearFlags::CHANNEL_ENGINES)) {
299 // Always wait for all channel bus transmissions to complete first
300 FastLED.wait();
301 fl::ChannelManager& manager = fl::channelManager();
302 manager.clearAllDrivers();
303 }
304
305 // Ensure all flags were handled - catches typos or missing implementations
306 FL_ASSERT(flags == ClearFlags::NONE, "Unhandled flags in FastLED.clear()");
307}
ClearFlags
Flags for FastLED.clear() to control what state gets cleared/reset.
Definition FastLED.h:661
@ CHANNEL_ENGINES
Clear all channel drivers from ChannelManager.
Definition FastLED.h:668
@ FPS_COUNTER
Reset FPS tracking counter to 0.
Definition FastLED.h:667
@ NONE
Clear nothing (no-op)
Definition FastLED.h:662
@ REFRESH_RATE
Reset refresh rate limiting to unlimited.
Definition FastLED.h:666
#define FL_ASSERT(x, MSG)
Definition assert.h:6
power_func mPPowerFunc
function for overriding brightness when using FastLED.show();
Definition FastLED.h:726
static void remove(fl::ChannelPtr channel) FL_NO_EXCEPT
Remove a channel from the LED controller list.
static fl::vector< fl::ChannelPtr > & channels() FL_NO_EXCEPT
stored ChannelPtrs to keep them alive
void wait() FL_NO_EXCEPT
Wait for all channel bus transmissions to complete.
fl::u8 mScale
the current global brightness scale setting
Definition FastLED.h:722
fl::u32 mNPowerData
max power use parameter
Definition FastLED.h:725
fl::u16 mNFPS
tracking for current frames per second (FPS) value
Definition FastLED.h:723
fl::u8 mLastShownScale
brightness the last show()/showColor() applied, after the power limiter
Definition FastLED.h:728
fl::u8 mLastRequestedScale
brightness the last show()/showColor() was asked for
Definition FastLED.h:727
fl::u16 mMaxRefreshHz
frame-rate cap in Hz, 0 = unlimited (u16 saves 2 B over micros, #4788)
Definition FastLED.h:724
void reset() FL_NO_EXCEPT
Reset bus manager state, clearing all enqueued and transmitting channels.
void clearAllDrivers() FL_NO_EXCEPT
Remove all drivers from the manager.
ChannelManager & channelManager() FL_NO_EXCEPT
Get the global ChannelManager singleton instance.

References BRIGHTNESS, CHANNEL_ENGINES, fl::channelManager(), CHANNELS, channels(), fl::ChannelManager::clearAllDrivers(), FastLED, FL_ASSERT, FL_NO_EXCEPT, FPS_COUNTER, NONE, POWER_SETTINGS, REFRESH_RATE, remove(), and fl::ChannelManager::reset().

+ Here is the call graph for this function: