FastLED 3.9.15
Loading...
Searching...
No Matches
cled_controller.h
Go to the documentation of this file.
1#pragma once
2
3
6
7#include "FastLED.h"
8#include "led_sysdefs.h"
9#include "pixeltypes.h"
10#include "color.h"
11
12#include "fl/force_inline.h"
13#include "fl/unused.h"
14#include "pixel_controller.h"
15#include "dither_mode.h"
16#include "pixel_iterator.h"
17#include "fl/engine_events.h"
18#include "fl/screenmap.h"
20#include "fl/int.h"
21#include "fl/bit_cast.h"
22
24
25
27//
28// LED Controller interface definition
29//
31
38protected:
39 friend class CFastLED;
45 bool m_enabled = true;
46 int m_nLeds;
49
50public:
51
56 virtual void showColor(const CRGB & data, int nLeds, fl::u8 brightness) = 0;
57
62 virtual void show(const struct CRGB *data, int nLeds, fl::u8 brightness) = 0;
63
64
67 // Note that at this time (Sept 13th, 2024) this is only implemented in the ESP32 driver
68 // directly. For an emulated version please see RGBWEmulatedController in chipsets.h
69 mRgbMode = arg;
70 return *this; // builder pattern.
71 }
72
73 void setEnabled(bool enabled) { m_enabled = enabled; }
74 bool getEnabled() { return m_enabled; }
75
77 // If we added virtual to the AVR boards then we are going to add 600 bytes of memory to the binary
78 // flash size. This is because the virtual destructor pulls in malloc and free, which are the largest
79 // Testing shows that this virtual destructor adds a 600 bytes to the binary on
80 // attiny85 and about 1k for the teensy 4.X series.
81 // Attiny85:
82 // With CLEDController destructor virtual: 11018 bytes to binary.
83 // Without CLEDController destructor virtual: 10666 bytes to binary.
85
86 Rgbw getRgbw() const { return mRgbMode; }
87
89 virtual void init() = 0;
90
93 VIRTUAL_IF_NOT_AVR void clearLeds(int nLeds = -1) {
95 showLeds(0);
96 }
97
98 // Compatibility with the 3.8.x codebase.
104
106
114 void showInternal(const struct CRGB *data, int nLeds, fl::u8 brightness) {
115 if (m_enabled) {
116 show(data, nLeds,brightness);
117 }
118 }
119
127 void showColorInternal(const struct CRGB &data, int nLeds, fl::u8 brightness) {
128 if (m_enabled) {
129 showColor(data, nLeds, brightness);
130 }
131 }
132
137 if (m_enabled) {
139 }
140 }
141
147 void showColorInternal(const struct CRGB & data, fl::u8 brightness) {
148 if (m_enabled) {
150 }
151 }
152
155 static CLEDController *head() { return m_pHead; }
156
160
164 CLEDController & setLeds(CRGB *data, int nLeds) {
165 m_Data = data;
166 m_nLeds = nLeds;
167 return *this;
168 }
169
171 void clearLedDataInternal(int nLeds = -1);
172
175 virtual int size() { return m_nLeds; }
176
179 virtual int lanes() { return 1; }
180
183 CRGB* leds() { return m_Data; }
184
188 CRGB &operator[](int x) { return m_Data[x]; }
189
193 inline CLEDController & setDither(fl::u8 ditherMode = BINARY_DITHER) { m_DitherMode = ditherMode; return *this; }
194
195 CLEDController& setScreenMap(const fl::XYMap& map, float diameter = -1.f) {
196 // EngineEvents::onCanvasUiSet(this, map);
197 fl::ScreenMap screenmap = map.toScreenMap();
198 if (diameter <= 0.0f) {
199 // screen map was not set.
200 if (map.getTotal() <= (64*64)) {
201 screenmap.setDiameter(.1f); // Assume small matrix is being used.
202 }
203 }
204 fl::EngineEvents::onCanvasUiSet(this, screenmap);
205 return *this;
206 }
207
210 return *this;
211 }
212
213 CLEDController& setScreenMap(fl::u16 width, fl::u16 height, float diameter = -1.f) {
215 return setScreenMap(xymap, diameter);
216 }
217
220 inline fl::u8 getDither() { return m_DitherMode; }
221
222 virtual void* beginShowLeds(int size) {
224 // By default, emit an integer. This integer will, by default, be passed back.
225 // If you override beginShowLeds() then
226 // you should also override endShowLeds() to match the return state.
227 //
228 // For async led controllers this should be used as a sync point to block
229 // the caller until the leds from the last draw frame have completed drawing.
230 // for each controller:
231 // beginShowLeds();
232 // for each controller:
233 // showLeds();
234 // for each controller:
235 // endShowLeds();
236 uintptr_t d = getDither();
237 void* out = fl::int_to_ptr<void>(d);
238 return out;
239 }
240
241 virtual void endShowLeds(void* data) {
242 // By default recieves the integer that beginShowLeds() emitted.
243 //For async controllers this should be used to signal the controller
244 // to begin transmitting the current frame to the leds.
245 uintptr_t d = fl::ptr_to_int(data);
246 setDither(static_cast<fl::u8>(d));
247 }
248
252 CLEDController & setCorrection(CRGB correction) { m_ColorCorrection = correction; return *this; }
253
255 CLEDController & setCorrection(LEDColorCorrection correction) { m_ColorCorrection = correction; return *this; }
256
260
264 CLEDController & setTemperature(CRGB temperature) { m_ColorTemperature = temperature; return *this; }
265
267 CLEDController & setTemperature(ColorTemperature temperature) { m_ColorTemperature = temperature; return *this; }
268
272
279
282 virtual fl::u16 getMaxRefreshRate() const { return 0; }
283};
284
int x
Definition simple.h:92
XYMap xymap(WIDTH, HEIGHT, SERPENTINE)
central include file for FastLED, defines the CFastLED class/object
uint16_t scale
Definition Noise.ino:74
UISlider brightness("Brightness", 128, 0, 255, 1)
CLEDController & setTemperature(ColorTemperature temperature)
Set the color temperature, aka white point, for this controller.
CRGB getCorrection()
Get the correction value used by this controller.
CLEDController * next()
Get the next controller in the linked list after this one.
virtual int lanes()
How many Lanes does this controller manage?
static CLEDController * m_pHead
pointer to the first LED controller in the linked list
CRGB getAdjustment(fl::u8 scale)
Get the combined brightness/color adjustment for this controller.
VIRTUAL_IF_NOT_AVR void showLeds(fl::u8 brightness)
CRGB * m_Data
pointer to the LED data used by this controller
CRGB & operator[](int x)
Reference to the n'th LED managed by the controller.
virtual void endShowLeds(void *data)
CRGB m_ColorCorrection
CRGB object representing the color correction to apply to the strip on show()
CLEDController & setScreenMap(fl::u16 width, fl::u16 height, float diameter=-1.f)
virtual int size()
How many LEDs does this controller manage?
void showColorInternal(const struct CRGB &data, int nLeds, fl::u8 brightness)
void showColorInternal(const struct CRGB &data, fl::u8 brightness)
CLEDController & setLeds(CRGB *data, int nLeds)
Set the default array of LEDs to be used by this controller.
VIRTUAL_IF_NOT_AVR void clearLeds(int nLeds=-1)
Clear out/zero out the given number of LEDs.
CLEDController & setCorrection(CRGB correction)
The color corrction to use for this controller, expressed as a CRGB object.
virtual void show(const struct CRGB *data, int nLeds, fl::u8 brightness)=0
Write the passed in RGB data out to the LEDs managed by this controller.
fl::u8 getDither()
Get the dithering option currently set for this controller.
static CLEDController * head()
Get the first LED controller in the linked list of controllers.
Rgbw getRgbw() const
CLEDController()
Create an led controller object, add it to the chain of controllers.
EDitherMode m_DitherMode
the current dither mode of the controller
ColorAdjustment getAdjustmentData(fl::u8 brightness)
CLEDController & setTemperature(CRGB temperature)
Set the color temperature, aka white point, for this controller.
virtual void showColor(const CRGB &data, int nLeds, fl::u8 brightness)=0
Set all the LEDs to a given color.
CRGB * leds()
Pointer to the CRGB array for this controller.
CLEDController * m_pNext
pointer to the next LED controller in the linked list
int m_nLeds
the number of LEDs in the LED data array
VIRTUAL_IF_NOT_AVR ~CLEDController()
static CLEDController * m_pTail
pointer to the last LED controller in the linked list
void setEnabled(bool enabled)
CLEDController & setRgbw(const Rgbw &arg=RgbwDefault::value())
void showInternal(const struct CRGB *data, int nLeds, fl::u8 brightness)
void clearLedDataInternal(int nLeds=-1)
Zero out the LED data managed by this controller.
virtual fl::u16 getMaxRefreshRate() const
Gets the maximum possible refresh rate of the strip.
friend class CFastLED
CLEDController & setCorrection(LEDColorCorrection correction)
The color corrction to use for this controller, expressed as a CRGB object.
CRGB m_ColorTemperature
CRGB object representing the color temperature to apply to the strip on show()
void showLedsInternal(fl::u8 brightness)
Write the data to the LEDs managed by this controller.
CLEDController & setScreenMap(const fl::XYMap &map, float diameter=-1.f)
CLEDController & setScreenMap(const fl::ScreenMap &map)
virtual void init()=0
Initialize the LED controller.
CLEDController & setDither(fl::u8 ditherMode=BINARY_DITHER)
Set the dithering mode for this controller to use.
virtual void * beginShowLeds(int size)
CRGB getTemperature()
Get the color temperature, aka white point, for this controller.
static void onCanvasUiSet(CLEDController *strip, const ScreenMap &xymap)
void setDiameter(float diameter)
fl::ScreenMap toScreenMap() const
Definition xymap.cpp:13
static XYMap constructRectangularGrid(u16 width, u16 height, u16 offset=0)
Definition xymap.cpp:34
u16 getTotal() const
Definition xymap.cpp:126
FASTLED_NAMESPACE_BEGIN typedef fl::u8 EDitherMode
The dither setting, either DISABLE_DITHER or BINARY_DITHER.
Definition dither_mode.h:17
#define BINARY_DITHER
Enable dithering using binary dithering (only option)
Definition dither_mode.h:14
Declares dithering options and types.
ColorTemperature
Color temperature values.
Definition color.h:46
LEDColorCorrection
Color correction starting points.
Definition color.h:15
Determines which platform system definitions to include.
#define FASTLED_NAMESPACE_END
Definition namespace.h:23
#define FASTLED_NAMESPACE_BEGIN
Definition namespace.h:22
unsigned char u8
Definition int.h:17
uptr ptr_to_int(T *ptr) noexcept
Definition bit_cast.h:65
T * int_to_ptr(uptr value) noexcept
Definition bit_cast.h:70
Low level pixel data writing class.
Non-templated low level pixel data writing class.
Includes defintions for RGB and HSV pixels.
Contains definitions for color correction and temperature.
static CRGB computeAdjustment(fl::u8 scale, const CRGB &colorCorrection, const CRGB &colorTemperature)
Calculates the combined color adjustment to the LEDs at a given scale, color correction,...
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86
static Rgbw value()
Definition rgbw.h:67
static Rgbw value()
Definition rgbw.h:56
#define FASTLED_UNUSED(x)
Definition unused.h:4
#define VIRTUAL_IF_NOT_AVR