FastLED 3.10.8
Loading...
Searching...
No Matches
manager.h
Go to the documentation of this file.
1
22
23#pragma once
24
25#include "fl/channels/driver.h"
26#include "fl/channels/data.h"
27#include "fl/channels/bus.h"
30#include "fl/stl/vector.h"
31#include "fl/stl/shared_ptr.h"
32#include "fl/stl/noexcept.h"
34#include "platforms/channel_poll_signal.h"
35
36namespace fl {
37
44
52public:
61
69
72
75
88 void addDriver(int priority, fl::shared_ptr<IChannelDriver> driver) FL_NO_EXCEPT;
89
96
106
113 void setDriverEnabled(const char* name, bool enabled) FL_NO_EXCEPT;
114
138 template<fl::Bus B, fl::u8 Which = 0>
140
148 bool setExclusiveDriver(Bus bus, fl::u8 which = 0) FL_NO_EXCEPT;
149
169 bool setExclusiveDriverByName(const char* name) FL_NO_EXCEPT;
170
178 bool setDriverPriority(const fl::string& name, int priority) FL_NO_EXCEPT;
179
183 bool isDriverEnabled(const char* name) const FL_NO_EXCEPT;
184
189 bool isDriverEnabled(const IChannelDriver& driver) const FL_NO_EXCEPT;
190
201
209
216
219 fl::size getDriverCount() const FL_NO_EXCEPT;
220
227
233 fl::shared_ptr<IChannelDriver> getDriverByName(const fl::string& name) const FL_NO_EXCEPT;
234
241 fl::shared_ptr<IChannelDriver> findDriverByName(const fl::string& name) const FL_NO_EXCEPT;
242
249 fl::shared_ptr<IChannelDriver> selectDriverForChannel(const ChannelDataPtr& data, const fl::string& affinity) FL_NO_EXCEPT;
250
255 IChannelDriver::DriverState poll() FL_NO_EXCEPT;
256
260 bool waitForReady(u32 timeoutMs = 1000) FL_NO_EXCEPT;
261 bool waitForReadyOrDraining(u32 timeoutMs = 1000) FL_NO_EXCEPT;
262
265 void onBeginFrame() FL_NO_EXCEPT override;
266
269 void onEndFrame() FL_NO_EXCEPT override;
270
273 void reset() FL_NO_EXCEPT;
274
275private:
281
285 int priority,
286 const fl::shared_ptr<IChannelDriver>& driver,
287 const fl::string* engineName,
289
295 template<typename Condition>
296 bool waitForCondition(Condition condition, u32 timeoutMs = 1000) FL_NO_EXCEPT;
297
299 bool waitForPollNeededSignal(u32 timeoutMs) FL_NO_EXCEPT;
300 u32 pollNeededWaitSliceMs(u32 startTime, u32 timeoutMs) const FL_NO_EXCEPT;
301 static void notifyPollNeededThunk(void* context) FL_NO_EXCEPT;
302
303private:
305 struct EngineEntry {
309 bool enabled;
310
313 bool operator<(const EngineEntry& other) const FL_NO_EXCEPT {
314 return priority > other.priority; // Sort descending: higher values first
315 }
316 };
317
323 IChannelDriver* selectDriver(const ChannelDataPtr& data = nullptr) FL_NO_EXCEPT;
324
328
332
337
340
342 platforms::ChannelPollSignal mPollNeededSignal;
343
344 // Non-copyable, non-movable
346 ChannelManager& operator=(const ChannelManager&) FL_NO_EXCEPT = delete;
349};
350
355
356// Inline template definition for ChannelManager::setExclusiveDriver<B>().
357// Defined here so the ODR-use of `BusTraits<B>::instancePtr()` happens in the
358// caller's TU, which links the driver translation unit. The caller must have
359// the per-driver `bus_traits.h` (which provides `BusTraits<B>::instancePtr`)
360// visible at the call site.
361template<fl::Bus B, fl::u8 Which>
363 // Priority above any platform default — see `bus_priorities.h` for the
364 // default-priority constants (highest there is ~10 for native LCD/I2S SPI).
365 constexpr int kExclusivePriority = 10000;
367 addDriver(kExclusivePriority, fl::BusTraits<B, Which>::instancePtr());
368}
369
370} // namespace fl
Portable compile-time identifiers for LED channel buses.
Per-driver traits keyed on fl::Bus.
void onEndFrame() FL_NO_EXCEPT override
Trigger transmission of batched channel data.
void setDriverEnabled(const char *name, bool enabled) FL_NO_EXCEPT
Enable or disable a driver by name at runtime.
bool waitForReadyOrDraining(u32 timeoutMs=1000) FL_NO_EXCEPT
bool setExclusiveDriverByName(const char *name) FL_NO_EXCEPT
Enable only one driver exclusively (disables all others) — by-name escape hatch.
u32 pollNeededWaitSliceMs(u32 startTime, u32 timeoutMs) const FL_NO_EXCEPT
IChannelDriver * selectDriver(const ChannelDataPtr &data=nullptr) FL_NO_EXCEPT
Select driver for current operation.
void reset() FL_NO_EXCEPT
Reset bus manager state, clearing all enqueued and transmitting channels.
ChannelManager() FL_NO_EXCEPT
Constructor.
~ChannelManager() FL_NO_EXCEPT override
Destructor - cleanup shared drivers (automatic via shared_ptr)
const fl::string & exclusiveDriverName() const FL_NO_EXCEPT
Get the currently-active exclusive-driver selection (if any).
Definition manager.h:215
void onBeginFrame() FL_NO_EXCEPT override
Poll drivers before frame starts to clear previous frame state.
static ChannelManager & registry() FL_NO_EXCEPT
Get the singleton WITHOUT registering platform default drivers.
fl::shared_ptr< IChannelDriver > findDriverByName(const fl::string &name) const FL_NO_EXCEPT
Silent counterpart to getDriverByName().
fl::size getDriverCount() const FL_NO_EXCEPT
Get count of registered drivers (including unnamed ones)
IChannelDriver::DriverState poll() FL_NO_EXCEPT
Poll all registered drivers and return aggregate state.
void clearAllDrivers() FL_NO_EXCEPT
Remove all drivers from the manager.
static ChannelManager & instance() FL_NO_EXCEPT
Get the global singleton instance.
IChannelDriver::PollNeededCallback mPollNeededCallback
Shared callback installed on drivers that can signal poll-needed events.
Definition manager.h:339
DriverStatus driverStatus(const fl::string &name) const FL_NO_EXCEPT
Look up a driver's registration status without logging on miss.
FL_NO_INLINE FL_COLD bool addDriverSlow(int priority, const fl::shared_ptr< IChannelDriver > &driver, const fl::string *engineName, AddDriverSlowReason reason) FL_NO_EXCEPT
Handle validation failures and the uncommon replacement flow outside the normal driver-registration p...
platforms::ChannelPollSignal mPollNeededSignal
Platform wait primitive owned by the manager.
Definition manager.h:342
fl::vector< DriverInfo > mCachedDriverInfo
Cached driver info for getDriverInfos() to avoid allocations.
Definition manager.h:331
DriverStatus
Registration status of a driver by name (silent lookup)
Definition manager.h:196
@ NOT_REGISTERED
No driver with that name is registered.
Definition manager.h:197
@ STATUS_ENABLED
Driver is registered and enabled.
Definition manager.h:199
@ STATUS_DISABLED
Driver is registered but disabled.
Definition manager.h:198
void setExclusiveDriver() FL_NO_EXCEPT
Register a single driver at a priority above the platform default and disable all others (compile-tim...
Definition manager.h:362
fl::shared_ptr< IChannelDriver > getDriverByName(const fl::string &name) const FL_NO_EXCEPT
Get driver by name for affinity binding.
bool waitForCondition(Condition condition, u32 timeoutMs=1000) FL_NO_EXCEPT
Wait until a condition is met, with check-pump-delay logic.
fl::shared_ptr< IChannelDriver > selectDriverForChannel(const ChannelDataPtr &data, const fl::string &affinity) FL_NO_EXCEPT
Select best driver for channel data (used by Channel::showPixels)
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
static void notifyPollNeededThunk(void *context) FL_NO_EXCEPT
bool setDriverPriority(const fl::string &name, int priority) FL_NO_EXCEPT
Change the priority of a registered driver.
bool waitForPollNeededSignal(u32 timeoutMs) FL_NO_EXCEPT
void addDriver(int priority, fl::shared_ptr< IChannelDriver > driver) FL_NO_EXCEPT
Add a driver with priority (higher priority = preferred)
bool isDriverEnabled(const char *name) const FL_NO_EXCEPT
Check if a driver is enabled by name.
void notifyPollNeeded() FL_NO_EXCEPT
bool removeDriver(fl::shared_ptr< IChannelDriver > driver) FL_NO_EXCEPT
Remove a driver from the manager.
bool waitForReady(u32 timeoutMs=1000) FL_NO_EXCEPT
Wait for all drivers to become READY.
fl::span< const DriverInfo > getDriverInfos() const FL_NO_EXCEPT
Get full state of all registered drivers.
Minimal interface for LED channel transmission drivers.
Definition driver.h:52
#define FL_NO_INLINE
#define FL_COLD
Channel transmission data - lightweight DTO for driver transmission.
void enable_clockless() FL_NO_EXCEPT
Definition bus_traits.h:64
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
ChannelManager & channelManager() FL_NO_EXCEPT
Get the global ChannelManager singleton instance.
Bus
Portable public bus selector.
Definition bus.h:27
Base definition for an LED controller.
Definition crgb.hpp:179
fl::string name
Driver name (empty for unnamed drivers)
Definition manager.h:40
bool enabled
Whether driver is currently enabled.
Definition manager.h:42
int priority
Driver priority (higher = preferred)
Definition manager.h:41
Driver state information for channel manager.
Definition manager.h:39
Primary template — intentionally undefined.
Definition bus_traits.h:31
fl::string name
Engine name for runtime identification (e.g., "RMT", "SPI")
Definition manager.h:308
bool enabled
Runtime enable/disable flag.
Definition manager.h:309
int priority
Definition manager.h:306
fl::shared_ptr< IChannelDriver > driver
Definition manager.h:307
bool operator<(const EngineEntry &other) const FL_NO_EXCEPT
Sort by priority descending (higher numbers first)
Definition manager.h:313
Engine registry entry (priority + shared pointer + runtime control)
Definition manager.h:305