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

◆ setExclusiveDriverByName()

bool fl::ChannelManager::setExclusiveDriverByName ( const char * name)

Enable only one driver exclusively (disables all others) — by-name escape hatch.

Parameters
nameDriver name to enable exclusively (case-sensitive, e.g., "MOCK_SPI")
Returns
true if driver was found and set as exclusive, false if name not found

Test / mock helper: works with drivers that have ALREADY been registered via addDriver() (typically ChannelEngineMock instances under unit tests), or for drivers whose names are NOT in the fl::Bus enum (custom third-party drivers, RPC-resolved names). Does NOT link or register new drivers.

For built-in drivers, prefer either:

  • setExclusiveDriver(fl::Bus) (typed runtime form), or
  • setExclusiveDriver<fl::Bus B>() (compile-time form that links the driver TU via ODR-use).
    Note
    Atomically disables all drivers, then enables the specified one
    Changes take effect immediately on next enqueue()
    If name is not found, all drivers remain disabled (defensive behavior)
    Use nullptr or empty string to disable all drivers (returns false)
    Warning
    This will disable ALL other registered drivers, including future additions

Definition at line 248 of file manager.cpp.hpp.

248 {
249 // Handle null or empty name: disable everything.
250 if (!name || !name[0]) {
251 FL_ERROR("ChannelManager::setExclusiveDriverByName() - Null or empty driver name provided");
252 mExclusiveDriver.clear();
253 for (auto& entry : mDrivers) {
254 entry.enabled = false;
255 }
256 return false;
257 }
258
259 // Store exclusive driver name for forward compatibility.
260 // When non-empty, addDriver() will auto-disable non-matching drivers.
261 mExclusiveDriver = name;
262
263 // Single-pass: enable only drivers matching the given name.
264 bool found = false;
265 for (auto& entry : mDrivers) {
266 entry.enabled = (entry.name == name);
267 found = found || entry.enabled;
268 }
269
270 if (!found) {
271 FL_ERROR("ChannelManager::setExclusiveDriverByName() - Driver '" << name << "' not found in registry");
272 }
273 return found;
274}
fl::vector< EngineEntry > mDrivers
Shared drivers sorted by priority descending (higher values first)
Definition manager.h:287
fl::string mExclusiveDriver
Exclusive driver name (empty if no exclusive mode)
Definition manager.h:296
#define FL_ERROR(X)
Definition log.h:219

References FL_ERROR, mDrivers, and mExclusiveDriver.

Referenced by autoResearchSetExclusiveDriverByName(), and setExclusiveDriver().

+ Here is the caller graph for this function: