FastLED 3.9.15
Loading...
Searching...
No Matches
adapter.cpp.hpp
Go to the documentation of this file.
1// ok no header
3#include "FastLED.h" // ok include - WLED adapter needs global FastLED object
4#include "fl/stl/memory.h"
5
6namespace fl {
7
8// FastLEDAdapter implementation
9
11 : mControllerIndex(controllerIndex)
12 , mSegmentStart(0)
13 , mSegmentEnd(0)
14 , mHasSegment(false)
15{
16 // Initialize segment end to the number of LEDs in the controller
18 mSegmentEnd = controller.size();
19}
20
33
35 if (mHasSegment) {
37 }
38
40 return controller.size();
41}
42
44 FastLED.show();
45}
46
50
51void FastLEDAdapter::clear(bool writeToStrip) {
53 CRGB* leds = controller.leds();
54 if (!leds) {
55 return;
56 }
57
58 if (mHasSegment) {
59 // Clear only the segment
60 for (size_t i = mSegmentStart; i < mSegmentEnd; i++) {
61 leds[i] = CRGB::Black;
62 }
63 } else {
64 // Clear all LEDs
65 size_t numLeds = controller.size();
66 for (size_t i = 0; i < numLeds; i++) {
67 leds[i] = CRGB::Black;
68 }
69 }
70
71 if (writeToStrip) {
72 FastLED.show();
73 }
74}
75
79
81 return FastLED.getBrightness();
82}
83
85 FastLED.setCorrection(correction);
86}
87
89 FastLED.setTemperature(temperature);
90}
91
92void FastLEDAdapter::delay(unsigned long ms) {
93 FastLED.delay(ms);
94}
95
97 FastLED.setMaxRefreshRate(fps);
98}
99
101 // CFastLED doesn't expose the max refresh rate setting
102 // Return 0 to indicate no limit
103 return 0;
104}
105
106void FastLEDAdapter::setSegment(size_t start, size_t end) {
108 size_t numLeds = controller.size();
109
110 // Validate bounds
111 if (start >= numLeds) {
112 start = numLeds > 0 ? numLeds - 1 : 0;
113 }
114 if (end > numLeds) {
115 end = numLeds;
116 }
117 if (end <= start) {
118 end = start + 1;
119 if (end > numLeds) {
120 end = numLeds;
121 start = end > 0 ? end - 1 : 0;
122 }
123 }
124
125 mSegmentStart = start;
127 mHasSegment = true;
128}
129
136
137// Helper function implementation
139 return fl::make_shared<FastLEDAdapter>(controllerIndex);
140}
141
142} // namespace fl
fl::CRGB leds[NUM_LEDS]
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
CLEDController * controller
size_t mSegmentEnd
Definition adapter.h:72
void setBrightness(u8 brightness) override
Set the global brightness.
void setTemperature(CRGB temperature) override
Set color temperature.
void delay(unsigned long ms) override
Delay for a specified number of milliseconds.
void clear(bool writeToStrip=false) override
Clear all LEDs (set to black)
void setMaxRefreshRate(u16 fps) override
Set the maximum refresh rate.
u16 getMaxRefreshRate() const override
Get the maximum refresh rate.
size_t getNumLEDs() const override
Get the number of LEDs.
void clearSegment() override
Clear the segment range (operate on full LED array)
FastLEDAdapter(u8 controllerIndex=0)
Construct adapter wrapping the global FastLED object.
void show() override
Send the LED data to the strip Uses the current brightness setting.
u8 getBrightness() const override
Get the current global brightness.
size_t mSegmentStart
Definition adapter.h:71
void setSegment(size_t start, size_t end) override
Set a segment range for subsequent operations.
void setCorrection(CRGB correction) override
Set color correction.
fl::span< CRGB > getLEDs() override
Get the LED array as a span.
unsigned char u8
Definition stdint.h:131
constexpr T * end(T(&array)[N]) FL_NOEXCEPT
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
fl::shared_ptr< IFastLED > createFastLEDController(u8 controllerIndex)
Create a FastLED controller adapter.
Base definition for an LED controller.
Definition crgb.hpp:179
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:510
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38