FastLED 3.10.8
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 276 of file manager.cpp.hpp.

276 {
277 // Handle null or empty name: disable everything.
278 if (!name || !name[0]) {
279 FL_ERROR("ChannelManager::setExclusiveDriverByName() - Null or empty driver name provided");
280 mExclusiveDriver.clear();
281 for (auto& entry : mDrivers) {
282 entry.enabled = false;
283 }
284 return false;
285 }
286
287 // Store exclusive driver name for forward compatibility.
288 // When non-empty, addDriver() will auto-disable non-matching drivers.
289 mExclusiveDriver = name;
290
291 // Single-pass: enable only drivers matching the given name.
292 bool found = false;
293 for (auto& entry : mDrivers) {
294 entry.enabled = (entry.name == name);
295 found = found || entry.enabled;
296 }
297
298 if (!found) {
299 FL_ERROR("ChannelManager::setExclusiveDriverByName() - Driver '" << name << "' not found in registry");
300 }
301 return found;
302}
fl::vector< EngineEntry > mDrivers
Shared drivers sorted by priority descending (higher values first)
Definition manager.h:327
fl::string mExclusiveDriver
Exclusive driver name (empty if no exclusive mode)
Definition manager.h:336
#define FL_ERROR(...)
Definition log.h:373

References FL_ERROR, fl::FL_NO_EXCEPT, mDrivers, and mExclusiveDriver.

Referenced by setExclusiveDriver().

+ Here is the caller graph for this function: