FastLED 3.9.7
Loading...
Searching...
No Matches
cled_controller.h
Go to the documentation of this file.
1#pragma once
2
3#include <stddef.h>
4
7
8#include "FastLED.h"
9#include "led_sysdefs.h"
10#include "pixeltypes.h"
11#include "color.h"
12
13#include "fl/force_inline.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"
19#include "fl/virtual_if_not_avr.h"
20
22
23
25//
26// LED Controller interface definition
27//
29
36protected:
37 friend class CFastLED;
43 bool m_enabled = true;
44 int m_nLeds;
47
48
53 virtual void showColor(const CRGB & data, int nLeds, uint8_t brightness) = 0;
54
59 virtual void show(const struct CRGB *data, int nLeds, uint8_t brightness) = 0;
60
61public:
62
63 Rgbw mRgbMode = RgbwInvalid::value();
64 CLEDController& setRgbw(const Rgbw& arg = RgbwDefault::value()) {
65 // Note that at this time (Sept 13th, 2024) this is only implemented in the ESP32 driver
66 // directly. For an emulated version please see RGBWEmulatedController in chipsets.h
67 mRgbMode = arg;
68 return *this; // builder pattern.
69 }
70
71 void setEnabled(bool enabled) { m_enabled = enabled; }
72
74 #if defined(FASTLED_TESTING)
75 // Silences the warning about the destructor not being virtual during testing.
76 // Testing shows that this virtual destructor adds a 600 bytes to the binary on
77 // attiny85 and about 1k for the teensy 4.X series.
78 // Attiny85:
79 // With CLEDController destructor virtual: 11018 bytes to binary.
80 // Without CLEDController destructor virtual: 10666 bytes to binary.
81 // Looking at the ELF/Map file, it appears that adding a virtual destructor to this
82 // base class not only adds vtables to the subclasses, but also pulls in malloc & free,
83 // which are by far the largest functions in binary size.
84 // Since we don't control how this library is compiled, the only thing we can do is
85 // carefully enable this virtual destructor for testing only and in the future, for boards
86 // that have enough space to handle the extra binary size.
87 virtual ~CLEDController();
88 #else
90 #endif
91 Rgbw getRgbw() const { return mRgbMode; }
92
93
94
96 virtual void init() = 0;
97
100 VIRTUAL_IF_NOT_AVR void clearLeds(int nLeds = -1) {
102 showLeds(0);
103 }
104
105 // Compatibility with the 3.8.x codebase.
106 VIRTUAL_IF_NOT_AVR void showLeds(uint8_t brightness) {
107 void* data = beginShowLeds();
108 showLedsInternal(brightness);
109 endShowLeds(data);
110 }
111
112 ColorAdjustment getAdjustmentData(uint8_t brightness);
113
121 void showInternal(const struct CRGB *data, int nLeds, uint8_t brightness) {
122 if (m_enabled) {
123 show(data, nLeds,brightness);
124 }
125 }
126
134 void showColorInternal(const struct CRGB &data, int nLeds, uint8_t brightness) {
135 if (m_enabled) {
136 showColor(data, nLeds, brightness);
137 }
138 }
139
143 void showLedsInternal(uint8_t brightness) {
144 if (m_enabled) {
145 show(m_Data, m_nLeds, brightness);
146 }
147 }
148
154 void showColorInternal(const struct CRGB & data, uint8_t brightness) {
155 if (m_enabled) {
156 showColor(data, m_nLeds, brightness);
157 }
158 }
159
162 static CLEDController *head() { return m_pHead; }
163
167
171 CLEDController & setLeds(CRGB *data, int nLeds) {
172 m_Data = data;
173 m_nLeds = nLeds;
174 return *this;
175 }
176
178 void clearLedDataInternal(int nLeds = -1);
179
182 virtual int size() { return m_nLeds; }
183
186 virtual int lanes() { return 1; }
187
190 CRGB* leds() { return m_Data; }
191
195 CRGB &operator[](int x) { return m_Data[x]; }
196
200 inline CLEDController & setDither(uint8_t ditherMode = BINARY_DITHER) { m_DitherMode = ditherMode; return *this; }
201
202 CLEDController& setScreenMap(const fl::XYMap& map) {
203 // EngineEvents::onCanvasUiSet(this, map);
204 fl::ScreenMap screenmap = map.toScreenMap();
205 fl::EngineEvents::onCanvasUiSet(this, screenmap);
206 return *this;
207 }
208
209 CLEDController& setScreenMap(const fl::ScreenMap& map) {
210 fl::EngineEvents::onCanvasUiSet(this, map);
211 return *this;
212 }
213
214 CLEDController& setScreenMap(uint16_t width, uint16_t height) {
215 return setScreenMap(fl::XYMap::constructRectangularGrid(width, height));
216 }
217
220 inline uint8_t getDither() { return m_DitherMode; }
221
222 virtual void* beginShowLeds() {
223 // By default, emit an integer. This integer will, by default, be passed back.
224 // If you override beginShowLeds() then
225 // you should also override endShowLeds() to match the return state.
226 //
227 // For async led controllers this should be used as a sync point to block
228 // the caller until the leds from the last draw frame have completed drawing.
229 // for each controller:
230 // beginShowLeds();
231 // for each controller:
232 // showLeds();
233 // for each controller:
234 // endShowLeds();
235 uintptr_t d = getDither();
236 void* out = reinterpret_cast<void*>(d);
237 return out;
238 }
239 virtual void endShowLeds(void* data) {
240 // By default recieves the integer that beginShowLeds() emitted.
241 //For async controllers this should be used to signal the controller
242 // to begin transmitting the current frame to the leds.
243 uintptr_t d = reinterpret_cast<uintptr_t>(data);
244 setDither(static_cast<uint8_t>(d));
245 }
246
250 CLEDController & setCorrection(CRGB correction) { m_ColorCorrection = correction; return *this; }
251
253 CLEDController & setCorrection(LEDColorCorrection correction) { m_ColorCorrection = correction; return *this; }
254
258
262 CLEDController & setTemperature(CRGB temperature) { m_ColorTemperature = temperature; return *this; }
263
265 CLEDController & setTemperature(ColorTemperature temperature) { m_ColorTemperature = temperature; return *this; }
266
270
277
280 virtual uint16_t getMaxRefreshRate() const { return 0; }
281};
282
284
285
central include file for FastLED, defines the CFastLED class/object
High level controller interface for FastLED.
Definition FastLED.h:354
Base definition for an LED controller.
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.
CLEDController & setDither(uint8_t ditherMode=BINARY_DITHER)
Set the dithering mode for this controller to use.
virtual int lanes()
How many Lanes does this controller manage?
virtual uint16_t getMaxRefreshRate() const
Gets the maximum possible refresh rate of the strip.
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.
CRGB m_ColorCorrection
CRGB object representing the color correction to apply to the strip on show()
virtual int size()
How many LEDs does this controller manage?
uint8_t getDither()
Get the dithering option currently set for this controller.
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.
static CLEDController * head()
Get the first LED controller in the linked list of controllers.
CLEDController()
Create an led controller object, add it to the chain of controllers.
EDitherMode m_DitherMode
the current dither mode of the controller
CLEDController & setTemperature(CRGB temperature)
Set the color temperature, aka white point, for this controller.
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
static CLEDController * m_pTail
pointer to the last LED controller in the linked list
void showInternal(const struct CRGB *data, int nLeds, uint8_t brightness)
void showColorInternal(const struct CRGB &data, int nLeds, uint8_t brightness)
void showLedsInternal(uint8_t brightness)
Write the data to the LEDs managed by this controller.
void clearLedDataInternal(int nLeds=-1)
Zero out the LED data managed by this controller.
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 showColorInternal(const struct CRGB &data, uint8_t brightness)
virtual void showColor(const CRGB &data, int nLeds, uint8_t brightness)=0
Set all the LEDs to a given color.
CRGB getAdjustment(uint8_t scale)
Get the combined brightness/color adjustment for this controller.
virtual void init()=0
Initialize the LED controller.
static CLEDController * m_pHead
pointer to the first LED controller in the linked list
virtual void show(const struct CRGB *data, int nLeds, uint8_t brightness)=0
Write the passed in RGB data out to the LEDs managed by this controller.
CRGB getTemperature()
Get the color temperature, aka whipe point, for this controller.
Declares dithering options and types.
uint8_t EDitherMode
The dither setting, either DISABLE_DITHER or BINARY_DITHER.
Definition dither_mode.h:16
#define BINARY_DITHER
Enable dithering using binary dithering (only option)
Definition dither_mode.h:13
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
End of the FastLED namespace.
Definition namespace.h:16
#define FASTLED_NAMESPACE_BEGIN
Start of the FastLED namespace.
Definition namespace.h:14
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.
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54
static CRGB computeAdjustment(uint8_t scale, const CRGB &colorCorrection, const CRGB &colorTemperature)
Calculates the combined color adjustment to the LEDs at a given scale, color correction,...
Definition crgb.cpp:24
Definition rgbw.h:28