Skip to content

refactor(channels): typed FastLED.setExclusiveDriver(fl::Bus) (#2471) - #2472

Merged
zackees merged 1 commit into
masterfrom
refactor/2471-typed-set-exclusive-driver
May 12, 2026
Merged

zackees merged 1 commit into
masterfrom
refactor/2471-typed-set-exclusive-driver

Conversation

@zackees

@zackees zackees commented May 12, 2026 •

Copy link
Copy Markdown
Member

Closes #2471.

Summary

  • FastLED.setExclusiveDriver(const char*) → FastLED.setExclusiveDriver(fl::Bus). The public facade is now typed and typo-safe — fl::Bus::RTM is a compile error.
  • ChannelManager::setExclusiveDriver(const char*) renamed to ChannelManager::setExclusiveDriverByName(const char*) — kept for mocks / custom / RPC-resolved drivers, but the name signals it's the escape hatch.
  • New ChannelManager::setExclusiveDriver(fl::Bus) overload delegates to the by-name form via busName(b).
  • AutoResearch's 4 runtime-string callers route through a new autoResearchSetExclusiveDriverByName() helper that calls FastLED.enableAllDrivers() first (RPC paths can't assume drivers are pre-enrolled).
  • 13 mock-test call sites in tests/fl/channels/spi_channel.cpp switch from manager.setExclusiveDriver(...) to manager.setExclusiveDriverByName(...).
  • DriverTest example switches to the same auto-enable + by-name pattern.
  • README.md / src/fl/channels/README.md / release_notes.md / options.h docs updated.

Why

The string form silently accepted typos that the typed fl::Bus enum catches at compile time. Removing it outright would have broken 17 legitimate callers (mocks + RPC-resolved names), so the fix is to split by intent: the public facade is typed-only; the by-name escape hatch lives one level down on ChannelManager.

Test plan

  • bash test --cpp — 304/304 passed (two transient flakes — fl_audio, fl_log — pass on rerun and in --debug; unrelated to this refactor).
  • bash lint — clean
  • SPI mock test suite still validates correctly via manager.setExclusiveDriverByName(...).
  • AutoResearch host build links (verified autoResearchSetExclusiveDriverByName() properly pulls in FastLED.enableAllDrivers() via fl/channels/all_drivers.h).

Backward compatibility

This is a source-breaking change for any user who called FastLED.setExclusiveDriver(\"RMT\") with a literal string. Migration:

Before After
FastLED.setExclusiveDriver(\"RMT\") FastLED.setExclusiveDriver(fl::Bus::RMT)
FastLED.setExclusiveDriver(some_runtime_str) fl::ChannelManager::instance().setExclusiveDriverByName(some_runtime_str) (after FastLED.enableAllDrivers())
manager.setExclusiveDriver(\"MOCK\") manager.setExclusiveDriverByName(\"MOCK\")

All in-tree callers in this PR have been migrated.

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Breaking Changes

    • Exclusive driver selection API updated from string-based to typed enum for improved compile-time safety.
    • Custom drivers and non-standard driver names now use a dedicated by-name helper method.
  • Documentation

    • Updated examples and API reference to reflect new typed driver selection API.

Review Change Stack

… string form (#2471)

`FastLED.setExclusiveDriver(const char*)` was the last string-based knob
on the public driver-selection surface after #2459 / #2460 introduced
the typed `fl::Bus` enum — silently accepting `"RTM"` typos that the
typed form catches at compile time.

The string form has two legitimate callers that can't go away though:

- **AutoResearch** (4 sites): driver name resolved at runtime from JSON/RPC.
- **Mock-test infrastructure** (13 sites in `spi_channel.cpp` + 1 in
  DriverTest example): custom drivers named with strings that will never
  be in `fl::Bus`.

So the fix is to split the public API by intent, not delete the string form:

**Public facade (`FastLED.setExclusiveDriver`):**
- Replace `(const char*)` with `(fl::Bus)`. Typed, typo-safe. The
  default entry point for user code.

**Lower-level (`ChannelManager`):**
- Rename `ChannelManager::setExclusiveDriver(const char*)` →
  `ChannelManager::setExclusiveDriverByName(const char*)`. Name signals
  "by-name escape hatch — you probably want the typed form."
- Add `ChannelManager::setExclusiveDriver(fl::Bus)` overload that
  delegates to `setExclusiveDriverByName(busName(b))`.

**AutoResearch helper (new):**
- `autoResearchSetExclusiveDriverByName(const char*)` in
  `examples/AutoResearch/AutoResearchHelpers.{h,cpp}` calls
  `FastLED.enableAllDrivers()` first (RPC paths can't assume drivers
  are pre-enrolled) and then `ChannelManager::instance()
  .setExclusiveDriverByName(name)`. The 4 AutoResearch call sites
  switch to this.

**Mock tests:**
- 13 calls in `tests/fl/channels/spi_channel.cpp`:
  `manager.setExclusiveDriver(...)` →
  `manager.setExclusiveDriverByName(...)`.

**DriverTest example:**
- `examples/SpecialDrivers/ESP/DriverTest/TestRunner.h` now calls
  `FastLED.enableAllDrivers()` + `ChannelManager::instance()
  .setExclusiveDriverByName(driverName)` directly (it doesn't pull
  AutoResearch's helper).

**Docs:**
- README.md, src/fl/channels/README.md, release_notes.md, options.h
  updated to show `FastLED.setExclusiveDriver(fl::Bus::X)` as the
  default and document the by-name escape hatch.

Closes #2471
@coderabbitai

coderabbitai Bot commented May 12, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

FastLED's exclusive driver selection API migrates from string-based setExclusiveDriver(const char*) to typed setExclusiveDriver(fl::Bus) on both CFastLED and ChannelManager, with a new setExclusiveDriverByName() escape hatch for runtime-resolved driver names. AutoResearch receives a helper for safe runtime name resolution. Tests and examples updated comprehensively.

Changes

Typed Driver Selection API Refactoring

Layer / File(s) Summary
ChannelManager API refactoring and core implementation
src/fl/channels/manager.h, src/fl/channels/manager.cpp.hpp, src/fl/channels/options.h
ChannelManager adds typed setExclusiveDriver(Bus) overload and renames the string-based form to setExclusiveDriverByName(const char*). Null/empty-name validation and error messaging updated. Bus header included for type availability.
CFastLED public API signature change
src/FastLED.h, src/FastLED.cpp.hpp
CFastLED::setExclusiveDriver() parameter changes from const char* to fl::Bus, forwarding to the ChannelManager typed overload. Documentation updated to describe compile-checked bus selection and guidance for custom drivers via setExclusiveDriverByName().
AutoResearch runtime name resolution helper
examples/AutoResearch/AutoResearchHelpers.h, examples/AutoResearch/AutoResearchHelpers.cpp, examples/AutoResearch/AutoResearchAsync.h, examples/AutoResearch/AutoResearchRemote.cpp
New autoResearchSetExclusiveDriverByName() helper enables all FastLED drivers before selecting by name via ChannelManager, ensuring runtime-resolved driver names from RPC/JSON don't silently fall back to default behavior. Integrated into stub-run loop and two RPC call paths.
ESP DriverTest integration
examples/SpecialDrivers/ESP/DriverTest/TestRunner.h
TestRunner adds ChannelManager include and updates testSingleDriver to enable all drivers then select by name, replacing direct FastLED call with ChannelManager::setExclusiveDriverByName().
Mock driver test migration across spi_channel.cpp
tests/fl/channels/spi_channel.cpp
13 SPI chipset integration and mock-driver predicate tests switch from manager.setExclusiveDriver(mock_name) to setExclusiveDriverByName(mock_name), enabling proper targeting of custom mock drivers (MOCK_SPI, MOCK_SPI_HD, CLOCKLESS_ONLY) across enabled and disabled test blocks.
Documentation and example migration to typed API
README.md, release_notes.md, src/fl/channels/README.md, examples/Sailboat/Sailboat.ino
README runtime control examples, release notes, and internal channel docs updated to show FastLED.setExclusiveDriver(fl::Bus::RMT/SPI) typed form with compile-time safety. Guidance added for non-enum drivers to use setExclusiveDriverByName() escape hatch. Example comments and Sailboat sketch updated.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2458: Both PRs refactor ChannelManager and CFastLED around fl::Bus typed driver model and add setExclusiveDriverByName escape hatch.
  • FastLED/FastLED#2448: Main PR directly uses the enableAllDrivers() enrollment helper and extends ChannelManager/CFastLED APIs with typed setExclusiveDriver(Bus) and setExclusiveDriverByName.
  • FastLED/FastLED#2461: Both PRs convert string-based driver selection to typed fl::Bus API and update examples/tests to use the new form.

Poem

🐰 A rabbit hops through driver selection,
Once strings did dance, now types protect!
The Bus enum shines, compile-checked bright,
Mock names find escape hatches in the night—
Refactored paths make testing right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing the string-based FastLED.setExclusiveDriver(const char*) with a typed FastLED.setExclusiveDriver(fl::Bus) API.
Linked Issues check ✅ Passed The PR fully implements all objectives from issue #2471: typed FastLED.setExclusiveDriver(fl::Bus) replaces string form, ChannelManager::setExclusiveDriverByName preserves by-name escape hatch, AutoResearch helper added, mock tests migrated, and documentation updated.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the typed API refactoring objective; documentation updates (README, release notes) support the API transition; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/2471-typed-set-exclusive-driver

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@release_notes.md`:
- Line 172: The release note at line mentioning the AutoResearch example
incorrectly claims the example uses FastLED.setExclusiveDriver(fl::Bus::RMT);
update the sentence to reflect the actual Runtime Channel API usage shown in
examples/AutoResearch/AutoResearch.ino by replacing the setExclusiveDriver
reference with a description that it demonstrates FastLED.add(),
FastLED.addRx(), and FastLED.getDriverInfos() for iterating drivers dynamically
(mention AutoResearch.ino and the Runtime Channel API and remove the
setExclusiveDriver symbol).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ff5abb42-0545-4dd3-9476-4ffc492a99ca

📥 Commits

Reviewing files that changed from the base of the PR and between 946b5fd and 897e774.

📒 Files selected for processing (15)
  • README.md
  • examples/AutoResearch/AutoResearchAsync.h
  • examples/AutoResearch/AutoResearchHelpers.cpp
  • examples/AutoResearch/AutoResearchHelpers.h
  • examples/AutoResearch/AutoResearchRemote.cpp
  • examples/Sailboat/Sailboat.ino
  • examples/SpecialDrivers/ESP/DriverTest/TestRunner.h
  • release_notes.md
  • src/FastLED.cpp.hpp
  • src/FastLED.h
  • src/fl/channels/README.md
  • src/fl/channels/manager.cpp.hpp
  • src/fl/channels/manager.h
  • src/fl/channels/options.h
  • tests/fl/channels/spi_channel.cpp

Comment thread release_notes.md
* **Automatic fallback**: If highest-priority driver fails, manager automatically tries next priority
* **ESP32 integration**: Drivers auto-register with names during platform initialization
* **Example Sketch**: See `examples/AutoResearch/AutoResearch.ino` for usage with `FastLED.setExclusiveDriver("RMT")`
* **Example Sketch**: See `examples/AutoResearch/AutoResearch.ino` for usage with `FastLED.setExclusiveDriver(fl::Bus::RMT)`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Verify what AutoResearch currently calls.
fd -i 'AutoResearch.ino' | while read -r f; do
  echo "=== $f ==="
  rg -n -C2 'setExclusiveDriver|setExclusiveDriverByName|enableAllDrivers|autoResearchSetExclusiveDriverByName' "$f"
done

Repository: FastLED/FastLED

Length of output: 106


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Check if AutoResearch.ino exists
echo "=== Checking for AutoResearch.ino ==="
find . -name "AutoResearch.ino" -type f 2>/dev/null

echo ""
echo "=== Reading AutoResearch.ino content ==="
cat examples/AutoResearch/AutoResearch.ino 2>/dev/null | head -150

echo ""
echo "=== Reading release_notes.md line 172 ==="
sed -n '170,175p' release_notes.md

Repository: FastLED/FastLED

Length of output: 7811


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Read the full AutoResearch.ino
wc -l examples/AutoResearch/AutoResearch.ino
echo ""
echo "=== Full AutoResearch.ino ==="
cat examples/AutoResearch/AutoResearch.ino

Repository: FastLED/FastLED

Length of output: 22866


Update release_notes.md line 172 — the AutoResearch example does not use setExclusiveDriver.

The example demonstrates the Runtime Channel API (FastLED.add() / FastLED.addRx() / FastLED.getDriverInfos()) for iterating through available drivers dynamically. The claim that it shows FastLED.setExclusiveDriver(fl::Bus::RMT) is incorrect and should be replaced with an accurate description of the actual API used.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@release_notes.md` at line 172, The release note at line mentioning the
AutoResearch example incorrectly claims the example uses
FastLED.setExclusiveDriver(fl::Bus::RMT); update the sentence to reflect the
actual Runtime Channel API usage shown in examples/AutoResearch/AutoResearch.ino
by replacing the setExclusiveDriver reference with a description that it
demonstrates FastLED.add(), FastLED.addRx(), and FastLED.getDriverInfos() for
iterating drivers dynamically (mention AutoResearch.ino and the Runtime Channel
API and remove the setExclusiveDriver symbol).

@zackees
zackees merged commit c6bbb1a into master May 12, 2026
6 of 9 checks passed
@zackees
zackees deleted the refactor/2471-typed-set-exclusive-driver branch August 21, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(channels): typed FastLED.setExclusiveDriver(fl::Bus) + lower string form

1 participant