FastLED 3.9.15
Loading...
Searching...
No Matches
channel.h
Go to the documentation of this file.
1
12
13#pragma once
14
15#include "fl/stl/noexcept.h"
16
18#include "fl/channels/bus.h"
20#include "fl/channels/options.h"
21#include "fl/stl/shared_ptr.h"
22#include "fl/stl/string.h"
23#include "fl/stl/weak_ptr.h"
24#include "fl/stl/stdint.h"
25#include "fl/channels/config.h"
27
28namespace fl {
29
30// Forward declarations
31class IChannelDriver;
32class ChannelData;
33struct ChannelOptions; // IWYU pragma: keep
34class Channel;
35class XMap;
38
48class Channel: public CPixelLEDController<RGB>, public IChannel {
49public:
58 static ChannelPtr create(const ChannelConfig& config);
59
61 virtual ~Channel() FL_NOEXCEPT;
62
65 i32 id() const override { return mId; }
66
69 const fl::string& name() const override { return mName; }
70
73 int getPin() const;
74
77 int getClockPin() const;
78
82 Channel& setGamma(float gamma);
83
87
91 const ChipsetTimingConfig& getTiming() const;
92
95 const ChipsetVariant& getChipset() const { return mChipset; }
96
99 EOrder getRgbOrder() const { return mRgbOrder; }
100
102 bool isClockless() const { return mChipset.is<ClocklessChipset>(); }
103
105 bool isSpi() const { return mChipset.is<SpiChipsetConfig>(); }
106
110 void applyConfig(const ChannelConfig& config);
111
112 // Re-expose protected base class methods for external access
114 void addToDrawList();
115
117 void removeFromDrawList();
118
120 int size() const override;
121
124
126 bool isInDrawList() const;
127
129 CLEDController* asController() { return static_cast<CLEDController*>(this); }
130 const CLEDController* asController() const { return static_cast<const CLEDController*>(this); }
131
134
137
140
143
145 u8 getDither();
146
148 Rgbw getRgbw() const;
149
153
158 Channel& setScreenMap(const fl::XYMap& map, float diameter = -1.f);
159
164
170 Channel& setScreenMap(fl::u16 width, fl::u16 height, float diameter = -1.f);
171
176
179 const fl::ScreenMap& getScreenMap() const;
180
183 bool hasScreenMap() const;
184
185private:
187 template<typename T, typename... Args>
189
190protected:
191 // CPixelLEDController interface implementation - protected so subclass delegates
192 // (e.g., UCS7604's DelegateController) can call through the base class chain.
193 void showPixels(PixelController<RGB, 1, 0xFFFFFFFF>& pixels) override;
194 void init() override;
200 Channel(const ChipsetVariant& chipset, EOrder rgbOrder, RegistrationMode mode);
201
202private:
212protected:
213
227 mDriver = driver;
228 mDriverPreBound = true;
229 }
230
231private:
238 EOrder rgbOrder, const ChannelOptions& options);
239
242 Channel(int pin, const ChipsetTimingConfig& timing, fl::span<CRGB> leds,
243 EOrder rgbOrder, const ChannelOptions& options);
244
245 // Non-copyable, non-movable
246 Channel(const Channel&) FL_NOEXCEPT = delete;
249 Channel& operator=(Channel&&) FL_NOEXCEPT = delete;
250
251 static i32 nextId();
252 static fl::string makeName(i32 id, const fl::optional<fl::string>& configName = fl::optional<fl::string>());
253
254 ChipsetVariant mChipset; // Chipset configuration (clockless or SPI)
256 fl::weak_ptr<IChannelDriver> mDriver; // Weak reference to driver (prevents dangling pointers)
257 bool mDriverPreBound = false; // True if setDriver() was called (legacy addLeds<> path).
258 // When true, showPixels() uses mDriver directly and skips
259 // ChannelManager::selectDriverForChannel(). When false (the
260 // default), every showPixels() re-evaluates the manager's
261 // priority list so users can swap drivers at runtime.
262 Bus mBus = Bus::AUTO; // Typed driver selection (#2459). `Bus::AUTO` falls through
263 // to `ChannelManager` priority dispatch; any other value
264 // pins this channel to `busName(mBus)`.
265 bool mBusWarned = false; // One-shot guard for the #2455 FL_ERROR. Flipped on the
266 // first showPixels() that observes a `mBus` miss (the
267 // named driver wasn't registered with ChannelManager).
268 // Subsequent shows on the same channel skip the warn even
269 // though the priority-dispatch fallback re-runs every frame.
270 bool mDisabledDriverWarned = false; // One-shot guard for the #2517 FL_ERROR. Flipped on the
271 // first showPixels() that would have enqueued data to a
272 // driver disabled by `setExclusiveDriver(...)` (or
273 // `setDriverEnabled(name, false)`). Cleared whenever the
274 // resolved driver returns to ENABLED so a subsequent
275 // disable re-emits the diagnostic.
276 const i32 mId;
277 fl::string mName; // User-specified or auto-generated name
278 ChannelOptions mSettings; // Per-channel settings (gamma, rgbw, etc.)
279 ChannelDataPtr mChannelData;
280 fl::ScreenMap mScreenMap; // Screen map for JS canvas visualization
281};
282
287
288} // namespace fl
fl::CRGB leds[NUM_LEDS]
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
Compile-time identifier for an LED channel transmission bus.
CPixelLEDController(RegistrationMode mode)
RegistrationMode
Registration mode for constructor.
Rgbw getRgbw() const
Get the RGBW conversion mode.
void removeFromDrawList()
Remove this channel from the global controller draw list.
CRGB getTemperature()
Get the color temperature.
Channel(const Channel &) FL_NOEXCEPT=delete
const fl::ScreenMap & getScreenMap() const
Get the current screen map.
CRGB getCorrection()
Get the color correction.
fl::string getEngineName() const
Get the name of the currently bound driver (if any)
FL_NO_INLINE fl::shared_ptr< IChannelDriver > resolveDynamicDriver()
Cold slow-path helper for showPixels() when the driver was NOT pre-bound via setDriver().
EOrder mRgbOrder
Definition channel.h:255
void init() override
Initialize the LED controller.
static fl::string makeName(i32 id, const fl::optional< fl::string > &configName=fl::optional< fl::string >())
fl::span< CRGB > leds()
Get the LED array as a span (non-const)
int size() const override
Get the number of LEDs in this channel.
ChipsetVariant mChipset
Definition channel.h:254
void setDriver(fl::shared_ptr< IChannelDriver > driver) FL_NOEXCEPT
Pre-bind a driver, bypassing ChannelManager::selectDriverForChannel() on every subsequent showPixels(...
Definition channel.h:226
EOrder getRgbOrder() const
Get the RGB channel ordering.
Definition channel.h:99
bool hasScreenMap() const
Check if screen map is configured.
void showPixels(PixelController< RGB, 1, 0xFFFFFFFF > &pixels) override
CLEDController * asController()
Get pointer to base CLEDController for linked list traversal.
Definition channel.h:129
bool mDriverPreBound
Definition channel.h:257
void addToDrawList()
Add this channel to the global controller draw list.
void applyConfig(const ChannelConfig &config)
Apply reconfigurable settings from a ChannelConfig.
Channel & operator=(const Channel &) FL_NOEXCEPT=delete
int getClockPin() const
Get the clock pin for this channel (SPI only, -1 for clockless)
void showLeds(u8 brightness=255) OVERRIDE_IF_NOT_AVR
Show the LEDs with optional brightness scaling.
const ChipsetTimingConfig & getTiming() const
Get the timing configuration for this channel (clockless only)
i32 id() const override
Get the channel ID.
Definition channel.h:65
bool mBusWarned
Definition channel.h:265
const ChipsetVariant & getChipset() const
Get the chipset configuration variant.
Definition channel.h:95
int getPin() const
Get the pin number for this channel (data pin)
fl::ScreenMap mScreenMap
Definition channel.h:280
ChannelDataPtr mChannelData
Definition channel.h:279
static i32 nextId()
bool isClockless() const
Check if this is a clockless chipset.
Definition channel.h:102
const fl::string & name() const override
Get the channel name.
Definition channel.h:69
bool isSpi() const
Check if this is an SPI chipset.
Definition channel.h:105
Channel(const ChipsetVariant &chipset, EOrder rgbOrder, RegistrationMode mode)
Protected constructor for template subclasses (e.g., ClocklessIdf5)
bool mDisabledDriverWarned
Definition channel.h:270
fl::weak_ptr< IChannelDriver > mDriver
Definition channel.h:256
Channel & setScreenMap(const fl::XYMap &map, float diameter=-1.f)
Set screen map for JS canvas visualization from XYMap.
Channel(Channel &&) FL_NOEXCEPT=delete
virtual ~Channel() FL_NOEXCEPT
Destructor.
const CLEDController * asController() const
Definition channel.h:130
static ChannelPtr create(const ChannelConfig &config)
Create a new channel with optional mBus driver pinning.
const i32 mId
Definition channel.h:276
fl::optional< float > getGamma() const
Get gamma correction value.
Channel & setGamma(float gamma)
Set gamma correction value.
bool isInDrawList() const
Check if this channel is in the controller draw list.
fl::string mName
Definition channel.h:277
u8 getDither()
Get the dither mode.
ChannelOptions mSettings
Definition channel.h:278
Transmission data for a single LED channel.
Definition data.h:39
LED channel for parallel output, pretty much a CPixelLEDController but with timing and pin informatio...
Definition channel.h:48
IChannel() FL_NOEXCEPT=default
Minimal interface for LED channel transmission drivers.
Definition driver.h:49
defines the templated version of the CLEDController class
Type-erased base for the templated Channel<Bus, Chipset> family.
byte Channel
Definition midi_Defs.h:58
unsigned char u8
Definition stdint.h:131
IChannelDriver * getStubChannelEngine()
Get stub channel driver for testing or unsupported platforms.
MapRedBlackTree< Key, T, Compare, fl::allocator_slab< char > > map
Definition map.h:283
u8 u8 height
Definition blur.h:186
Optional< T > optional
Definition optional.h:16
fl::variant< ClocklessChipset, SpiChipsetConfig > ChipsetVariant
Definition config.h:153
Bus
Driver identifier for compile-time bus selection.
Definition bus.h:60
@ AUTO
Sentinel: defer to DefaultBus<Chipset>::value.
Definition bus.h:61
u8 width
Definition blur.h:186
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
EOrder
RGB color channel orderings, used when instantiating controllers to determine what order the controll...
Definition eorder.h:13
constexpr u32 gamma(float g) FL_NOEXCEPT
Definition gamma_lut.h:36
Base definition for an LED controller.
Definition crgb.hpp:179
corkscrew_args args
Definition old.h:149
#define FL_NO_INLINE
#define OVERRIDE_IF_NOT_AVR
#define FL_NOEXCEPT
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:535
Pixel controller class.
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
Configuration for a single LED channel.
Definition config.h:163
Optional channel configuration parameters All fields have sensible defaults and can be overridden as ...
Definition options.h:43
Runtime bit-period timing for a clockless chipset.
Clockless chipset configuration (single data pin)
Definition config.h:32
SPI chipset configuration (data + clock pins)
Definition config.h:102