Repository navigation
refactor(channels): typed FastLED.setExclusiveDriver(fl::Bus) (#2471) - #2472
Conversation
… 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
📝 WalkthroughWalkthroughFastLED's exclusive driver selection API migrates from string-based ChangesTyped Driver Selection API Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (15)
README.mdexamples/AutoResearch/AutoResearchAsync.hexamples/AutoResearch/AutoResearchHelpers.cppexamples/AutoResearch/AutoResearchHelpers.hexamples/AutoResearch/AutoResearchRemote.cppexamples/Sailboat/Sailboat.inoexamples/SpecialDrivers/ESP/DriverTest/TestRunner.hrelease_notes.mdsrc/FastLED.cpp.hppsrc/FastLED.hsrc/fl/channels/README.mdsrc/fl/channels/manager.cpp.hppsrc/fl/channels/manager.hsrc/fl/channels/options.htests/fl/channels/spi_channel.cpp
| * **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)` |
There was a problem hiding this comment.
🧩 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"
doneRepository: 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.mdRepository: 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.inoRepository: 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).
Closes #2471.
Summary
FastLED.setExclusiveDriver(const char*)→FastLED.setExclusiveDriver(fl::Bus). The public facade is now typed and typo-safe —fl::Bus::RTMis a compile error.ChannelManager::setExclusiveDriver(const char*)renamed toChannelManager::setExclusiveDriverByName(const char*)— kept for mocks / custom / RPC-resolved drivers, but the name signals it's the escape hatch.ChannelManager::setExclusiveDriver(fl::Bus)overload delegates to the by-name form viabusName(b).autoResearchSetExclusiveDriverByName()helper that callsFastLED.enableAllDrivers()first (RPC paths can't assume drivers are pre-enrolled).tests/fl/channels/spi_channel.cppswitch frommanager.setExclusiveDriver(...)tomanager.setExclusiveDriverByName(...).Why
The string form silently accepted typos that the typed
fl::Busenum 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 onChannelManager.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— cleanmanager.setExclusiveDriverByName(...).autoResearchSetExclusiveDriverByName()properly pulls inFastLED.enableAllDrivers()viafl/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:FastLED.setExclusiveDriver(\"RMT\")FastLED.setExclusiveDriver(fl::Bus::RMT)FastLED.setExclusiveDriver(some_runtime_str)fl::ChannelManager::instance().setExclusiveDriverByName(some_runtime_str)(afterFastLED.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
Documentation