FastLED 3.9.3
Loading...
Searching...
No Matches
cled_controller.h
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 "force_inline.h"
14#include "pixel_controller.h"
15#include "dither_mode.h"
16#include "pixel_iterator.h"
17#include "engine_events.h"
18#include "screenmap.h"
19
20FASTLED_NAMESPACE_BEGIN
21
22
24//
25// LED Controller interface definition
26//
28
35protected:
36 friend class CFastLED;
41 EDitherMode m_DitherMode;
42 int m_nLeds;
45
46
51 virtual void showColor(const CRGB & data, int nLeds, uint8_t brightness) = 0;
52
57 virtual void show(const struct CRGB *data, int nLeds, uint8_t brightness) = 0;
58
59public:
60
61 Rgbw mRgbMode = RgbwInvalid::value();
62 CLEDController& setRgbw(const Rgbw& arg = RgbwDefault::value()) {
63 // Note that at this time (Sept 13th, 2024) this is only implemented in the ESP32 driver
64 // directly. For an emulated version please see RGBWEmulatedController in chipsets.h
65 mRgbMode = arg;
66 return *this; // builder pattern.
67 }
68 Rgbw getRgbw() const { return mRgbMode; }
69
72 m_pNext = NULL;
73 if(m_pHead==NULL) { m_pHead = this; }
74 if(m_pTail != NULL) { m_pTail->m_pNext = this; }
75 m_pTail = this;
76 }
77
79 virtual void init() = 0;
80
83 virtual void clearLeds(int nLeds = -1) {
85 }
86
87 inline ColorAdjustment getAdjustmentData(uint8_t brightness) {
88 // *premixed = getAdjustment(brightness);
89 // if (color_correction) {
90 // *color_correction = getAdjustment(255);
91 // }
92 #if FASTLED_HD_COLOR_MIXING
93 ColorAdjustment out = {getAdjustment(brightness), getAdjustment(255), brightness};
94 #else
95 ColorAdjustment out = {getAdjustment(brightness)};
96 #endif
97 return out;
98 }
99
107 void showInternal(const struct CRGB *data, int nLeds, uint8_t brightness) {
108 show(data, nLeds,brightness);
109 }
110
118 void showColorInternal(const struct CRGB &data, int nLeds, uint8_t brightness) {
119 showColor(data, nLeds, brightness);
120 }
121
125 void showLedsInternal(uint8_t brightness) {
126 show(m_Data, m_nLeds, brightness);
127 }
128
134 void showColorInternal(const struct CRGB & data, uint8_t brightness) {
135 showColor(data, m_nLeds, brightness);
136 }
137
140 static CLEDController *head() { return m_pHead; }
141
145
149 CLEDController & setLeds(CRGB *data, int nLeds) {
150 m_Data = data;
151 m_nLeds = nLeds;
152 return *this;
153 }
154
156 void clearLedDataInternal(int nLeds = -1) {
157 if(m_Data) {
158 nLeds = (nLeds < 0) ? m_nLeds : nLeds;
159 nLeds = (nLeds > m_nLeds) ? m_nLeds : nLeds;
160 memset((void*)m_Data, 0, sizeof(struct CRGB) * nLeds);
161 }
162 }
163
166 virtual int size() { return m_nLeds; }
167
170 virtual int lanes() { return 1; }
171
174 CRGB* leds() { return m_Data; }
175
179 CRGB &operator[](int x) { return m_Data[x]; }
180
184 inline CLEDController & setDither(uint8_t ditherMode = BINARY_DITHER) { m_DitherMode = ditherMode; return *this; }
185
186 CLEDController& setScreenMap(const XYMap& map) {
187 // EngineEvents::onCanvasUiSet(this, map);
188 ScreenMap screenmap = map.toScreenMap();
189 EngineEvents::onCanvasUiSet(this, screenmap);
190 return *this;
191 }
192
193 CLEDController& setScreenMap(const ScreenMap& map) {
194 EngineEvents::onCanvasUiSet(this, map);
195 return *this;
196 }
197
198 CLEDController& setScreenMap(uint16_t width, uint16_t height) {
199 return setScreenMap(XYMap::constructRectangularGrid(width, height));
200 }
201
204 inline uint8_t getDither() { return m_DitherMode; }
205
206 virtual void* beginShowLeds() {
207 // By default, emit an integer. This integer will, by default, be passed back.
208 // If you override beginShowLeds() then
209 // you should also override endShowLeds() to match the return state.
210 //
211 // For async led controllers this should be used as a sync point to block
212 // the caller until the leds from the last draw frame have completed drawing.
213 // for each controller:
214 // beginShowLeds();
215 // for each controller:
216 // showLeds();
217 // for each controller:
218 // endShowLeds();
219 uintptr_t d = getDither();
220 void* out = reinterpret_cast<void*>(d);
221 return out;
222 }
223 virtual void endShowLeds(void* data) {
224 // By default recieves the integer that beginShowLeds() emitted.
225 //For async controllers this should be used to signal the controller
226 // to begin transmitting the current frame to the leds.
227 uintptr_t d = reinterpret_cast<uintptr_t>(data);
228 setDither(static_cast<uint8_t>(d));
229 }
230
234 CLEDController & setCorrection(CRGB correction) { m_ColorCorrection = correction; return *this; }
235
237 CLEDController & setCorrection(LEDColorCorrection correction) { m_ColorCorrection = correction; return *this; }
238
242
246 CLEDController & setTemperature(CRGB temperature) { m_ColorTemperature = temperature; return *this; }
247
249 CLEDController & setTemperature(ColorTemperature temperature) { m_ColorTemperature = temperature; return *this; }
250
254
261
264 virtual uint16_t getMaxRefreshRate() const { return 0; }
265};
266
267FASTLED_NAMESPACE_END
268
269
central include file for FastLED, defines the CFastLED class/object
High level controller interface for FastLED.
Definition FastLED.h:353
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 void clearLeds(int nLeds=-1)
Clear out/zero out the given number of LEDs.
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.
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.
Definition xymap.h:39
Contains definitions for color correction and temperature.
ColorTemperature
Color temperature values.
Definition color.h:46
LEDColorCorrection
Color correction starting points.
Definition color.h:15
@ UncorrectedTemperature
Uncorrected temperature (0xFFFFFF)
Definition color.h:94
@ UncorrectedColor
Uncorrected color (0xFFFFFF)
Definition color.h:28
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:10
Determines which platform system definitions to include.
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:39
Definition rgbw.h:25