FastLED 3.9.15
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:580
@ BRIGHTNESS
Reset global brightness to 255.
Definition FastLED.h:582
@ POWER_SETTINGS
Reset power management (setMaxPowerInMilliWatts)
Definition FastLED.h:581
CFastLED FastLED
Global LED strip management instance.

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

161 {
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)
207 fl::ChannelManager& manager = fl::channelManager();
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();
218 fl::ChannelManager& manager = fl::channelManager();
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}
ClearFlags
Flags for FastLED.clear() to control what state gets cleared/reset.
Definition FastLED.h:578
@ CHANNEL_ENGINES
Clear all channel drivers from ChannelManager.
Definition FastLED.h:585
@ 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
#define FL_ASSERT(x, MSG)
Definition assert.h:6
power_func mPPowerFunc
function for overriding brightness when using FastLED.show();
Definition FastLED.h:616
static fl::vector< fl::ChannelPtr > & channels()
stored ChannelPtrs to keep them alive
static void remove(fl::ChannelPtr channel)
Remove a channel from the LED controller list.
fl::u8 mScale
the current global brightness scale setting
Definition FastLED.h:612
fl::u32 mNPowerData
max power use parameter
Definition FastLED.h:615
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 wait()
Wait for all channel bus transmissions to complete.
void reset() FL_NOEXCEPT
Reset bus manager state, clearing all enqueued and transmitting channels.
void clearAllDrivers() FL_NOEXCEPT
Remove all drivers from the manager.
ChannelManager & channelManager()
Get the global ChannelManager singleton instance.

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

+ Here is the call graph for this function: