FastLED 3.10.8
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:668
@ BRIGHTNESS
Reset global brightness to 255.
Definition FastLED.h:670
@ POWER_SETTINGS
Reset power management (setMaxPowerInMilliWatts)
Definition FastLED.h:669
CFastLED FastLED
Global LED strip management instance.

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

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