FastLED 3.9.15
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
27
33
35 // Don't add if already in list
36 #if SKETCH_HAS_LARGE_MEMORY // Mostly for AVR, the isInList() check adds memory overhead on these tight platforms.
37 if (isInList()) {
38 return;
39 }
40 #endif
41
42 // Add to linked list
43 if(mPHead==nullptr) { mPHead = this; }
44 if(mPTail != nullptr) { mPTail->mPNext = this; }
45 mPTail = this;
46}
47
49 CLEDController* curr = mPHead;
50 while (curr != nullptr) {
51 if (curr == this) {
52 return true;
53 }
54 curr = curr->mPNext;
55 }
56 return false;
57}
58
60 // On common code that runs on avr, every byte counts.
61 fl::u16 n = nLeds >= 0 ? static_cast<fl::u16>(nLeds) : static_cast<fl::u16>(mLeds.size());
62 if (mLeds.data()) {
63 fl::memset((void*)mLeds.data(), 0, sizeof(CRGB) * n);
64 }
65
66}
67
69 if (controller == nullptr) {
70 return;
71 }
72
73 // Remove the specified controller from the linked list
74 CLEDController* prev = nullptr;
75 CLEDController* curr = mPHead;
76
77 // Find the controller in the linked list
78 while (curr != nullptr) {
79 if (curr == controller) {
80 // Found it - remove from list
81 if (prev == nullptr) {
82 // Removing head
83 mPHead = controller->mPNext;
84 if (mPHead == nullptr) {
85 // List is now empty
86 mPTail = nullptr;
87 }
88 } else {
89 // Removing from middle or end
90 prev->mPNext = controller->mPNext;
91 if (controller->mPNext == nullptr) {
92 // Removing tail
93 mPTail = prev;
94 }
95 }
96
97 // Clear the controller's next pointer
98 controller->mPNext = nullptr;
99 break;
100 }
101 prev = curr;
102 curr = curr->mPNext;
103 }
104}
105
107 // *premixed = getAdjustment(brightness);
108 // if (color_correction) {
109 // *color_correction = getAdjustment(255);
110 // }
111 #if FASTLED_HD_COLOR_MIXING
112 ColorAdjustment out = {this->getAdjustment(brightness), this->getAdjustment(255), brightness};
113 #else
115 #endif
116 return out;
117}
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
CLEDController * controller
void clearLedDataInternal(int nLeds=-1) FL_NOEXCEPT
Zero out the LED data managed by this controller.
static CLEDController * mPTail
pointer to the last LED controller in the linked list
void removeFromDrawList() FL_NOEXCEPT
Remove this controller from the draw list.
RegistrationMode
Registration mode for constructor.
@ AutoRegister
Automatically add to linked list (default, backward compatible)
VIRTUAL_IF_NOT_AVR ~CLEDController() FL_NOEXCEPT
bool isInList() const FL_NOEXCEPT
Check if this controller is in the linked list.
CLEDController(RegistrationMode mode) FL_NOEXCEPT
Protected constructor with registration mode.
void addToList() FL_NOEXCEPT
Add this controller to the linked list.
CRGB getAdjustment(fl::u8 scale) FL_NOEXCEPT
Get the combined brightness/color adjustment for this controller.
CLEDController() FL_NOEXCEPT
Create an led controller object, add it to the chain of controllers.
ChannelOptions mSettings
Optional channel settings (correction, temperature, dither, rgbw, affinity)
static void removeFromList(CLEDController *controller) FL_NOEXCEPT
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
ColorAdjustment getAdjustmentData(fl::u8 brightness) FL_NOEXCEPT
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 s16x16x4.h:132
void * memset(void *s, int c, size_t n) FL_NOEXCEPT
Color adjustment structure for pixel output.
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38