FastLED 3.10.8
Loading...
Searching...
No Matches

◆ addToList()

void CLEDController::addToList ( )

Add this controller to the linked list.

Note
Used with DeferRegister mode to explicitly add controller to list (for example, fl::Channel via FastLED.add(ChannelPtr))
Safe to call multiple times - won't add if already in list

Definition at line 36 of file cled_controller.cpp.hpp.

36 {
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}
bool isInList() const FL_NO_EXCEPT
Check if this controller is in 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.

References CLEDController(), fl::FL_NO_EXCEPT, isInList(), mPHead, and mPNext.

Referenced by CLEDController(), CLEDController(), and fl::Channel::addToDrawList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: