FastLED 3.10.8
Loading...
Searching...
No Matches
cled_controller.cpp.hpp
Go to the documentation of this file.
1
3
4#define FASTLED_INTERNAL
5#include "fl/system/fastled.h"
6
7#include "cled_controller.h"
8
9#include "fl/stl/cstring.h"
11
12
14#if SKETCH_HAS_LARGE_MEMORY
15 // Remove from draw list on destruction to prevent dangling pointers
16 // Note: Not enabled on memory-constrained platforms (AVR, ESP8266, etc.)
17 // because the virtual destructor adds ~600 bytes on AVR and pulling in
18 // removeFromDrawList() adds additional overhead
20#endif
21}
22
28
35
37 // Don't add if already in list
38 #if SKETCH_HAS_LARGE_MEMORY // Mostly for AVR, the isInList() check adds memory overhead on these tight platforms.
39 if (isInList()) {
40 return;
41 }
42 #endif
43
44 // Append by walking from the head: registration is rare and lists are
45 // short, so no tail pointer is stored (#4788).
46 if (mPHead == nullptr) {
47 mPHead = this;
48 return;
49 }
50 // The walk also catches a repeat registration, which would otherwise
51 // create a cycle (AVR skips the isInList() check above).
52 CLEDController* last = mPHead;
53 while (true) {
54 if (last == this) {
55 return;
56 }
57 if (last->mPNext == nullptr) {
58 break;
59 }
60 last = last->mPNext;
61 }
62 last->mPNext = this;
63}
64
66 CLEDController* curr = mPHead;
67 while (curr != nullptr) {
68 if (curr == this) {
69 return true;
70 }
71 curr = curr->mPNext;
72 }
73 return false;
74}
75
77 // On common code that runs on avr, every byte counts.
78 //
79 // mLeds spans one lane, not the whole buffer. A parallel controller is
80 // registered with the PER-LANE count -- addLeds<NUM_LANES, ...>(data,
81 // nLeds) forwards nLeds -- while the caller's array is NUM_LANES * nLeds.
82 // Clearing mLeds.size() therefore blanked only the first strip and left
83 // the rest lit, which is FastLED#1017.
84 //
85 // lanes() is 1 for every ordinary controller, so this is a no-op there. It
86 // reports the template lane count on parallel controllers, which is what
87 // the caller allocated, so this cannot run past the end of their array
88 // even when fewer lanes were actually claimed.
89 fl::u16 n = nLeds >= 0 ? static_cast<fl::u16>(nLeds)
90 : static_cast<fl::u16>(mLeds.size() * lanes());
91 if (mLeds.data()) {
92 fl::memset((void*)mLeds.data(), 0, sizeof(CRGB) * n);
93 }
94
95}
96
98 if (controller == nullptr) {
99 return;
100 }
101
102 // Remove the specified controller from the linked list
103 CLEDController* prev = nullptr;
104 CLEDController* curr = mPHead;
105
106 // Find the controller in the linked list
107 while (curr != nullptr) {
108 if (curr == controller) {
109 // Found it - remove from list
110 if (prev == nullptr) {
111 // Removing head
112 mPHead = controller->mPNext;
113 } else {
114 // Removing from middle or end
115 prev->mPNext = controller->mPNext;
116 }
117
118 // Clear the controller's next pointer
119 controller->mPNext = nullptr;
120 break;
121 }
122 prev = curr;
123 curr = curr->mPNext;
124 }
125}
126
128 // *premixed = getAdjustment(brightness);
129 // if (color_correction) {
130 // *color_correction = getAdjustment(255);
131 // }
132 #if FASTLED_HD_COLOR_MIXING
134 #else
136 #endif
137 return out;
138}
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
CLEDController * controller
virtual int lanes() FL_NO_EXCEPT
How many Lanes does this controller manage?
bool isInList() const FL_NO_EXCEPT
Check if this controller is in the linked list.
RegistrationMode
Registration mode for constructor.
@ AutoRegister
Automatically add to linked list (default, backward compatible)
ColorAdjustment getAdjustmentData(fl::u8 brightness) FL_NO_EXCEPT
void clearLedDataInternal(int nLeds=-1) FL_NO_EXCEPT
Zero out the LED data managed by this controller.
LegacySettings mLegacySettings
bool mFixedWhiteChannel
chipset wire format owns the white policy
void removeFromDrawList() FL_NO_EXCEPT
Remove this controller from the draw list.
VIRTUAL_IF_NOT_AVR ~CLEDController() FL_NO_EXCEPT
static void removeFromList(CLEDController *controller) FL_NO_EXCEPT
Remove a controller from the linked list.
CLEDController * mPNext
pointer to the next LED controller in the linked list
static CLEDController * mPHead
pointer to the first LED controller in the linked list
CLEDController(RegistrationMode mode) FL_NO_EXCEPT
Protected constructor with registration mode.
CLEDController() FL_NO_EXCEPT
Create an led controller object, add it to the chain of controllers.
void addToList() FL_NO_EXCEPT
Add this controller to the linked list.
CRGB getAdjustment(fl::u8 scale) FL_NO_EXCEPT
Get the combined brightness/color adjustment for this controller.
fl::span< CRGB > mLeds
span of LED data used by this controller
base definitions used by led controllers for writing out led data
Internal FastLED header for implementation files.
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
FASTLED_FORCE_INLINE void * memset(void *s, int c, size_t n) FL_NO_EXCEPT
Definition cstring.h:148
Color adjustment structure for pixel output.
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38