FastLED 3.10.8
Loading...
Searching...
No Matches
adapter.cpp.hpp
Go to the documentation of this file.
1// ok no header
2
3// This is FastLED's own translation unit, not user code. `FastLED.h` emits
4// user-facing `#warning`s (EOL boards, removed build flags) that are all
5// guarded on `!defined(FASTLED_INTERNAL)`, so without this the library warns
6// at itself and the user sees the same notice twice per build. Matches the
7// convention already used by bitswap/crgb/cled_controller/FastLED.cpp.hpp.
8#define FASTLED_INTERNAL
9
10#include "fl/fx/wled/adapter.h"
11#include "FastLED.h" // ok include - WLED adapter needs global FastLED object
12#include "fl/stl/memory.h"
13#include "fl/stl/noexcept.h"
14
15namespace fl {
16
17// FastLEDAdapter implementation
18
20 FL_NO_EXCEPT : mControllerIndex(controllerIndex)
21 , mSegmentStart(0)
22 , mSegmentEnd(0)
23 , mHasSegment(false)
24{
25 // Initialize segment end to the number of LEDs in the controller
27 mSegmentEnd = controller.size();
28}
29
42
51
55
59
60void FastLEDAdapter::clear(bool writeToStrip) FL_NO_EXCEPT {
62 CRGB* leds = controller.leds();
63 if (!leds) {
64 return;
65 }
66
67 if (mHasSegment) {
68 // Clear only the segment
69 for (size_t i = mSegmentStart; i < mSegmentEnd; i++) {
70 leds[i] = CRGB::Black;
71 }
72 } else {
73 // Clear all LEDs
74 size_t numLeds = controller.size();
75 for (size_t i = 0; i < numLeds; i++) {
76 leds[i] = CRGB::Black;
77 }
78 }
79
80 if (writeToStrip) {
81 FastLED.show();
82 }
83}
84
88
90 return FastLED.getBrightness();
91}
92
94 FastLED.setCorrection(correction);
95}
96
98 FastLED.setTemperature(temperature);
99}
100
101void FastLEDAdapter::delay(unsigned long ms) FL_NO_EXCEPT {
102 FastLED.delay(ms);
103}
104
106 FastLED.setMaxRefreshRate(fps);
107}
108
110 // CFastLED doesn't expose the max refresh rate setting
111 // Return 0 to indicate no limit
112 return 0;
113}
114
115void FastLEDAdapter::setSegment(size_t start, size_t end) FL_NO_EXCEPT {
117 size_t numLeds = controller.size();
118
119 // Validate bounds
120 if (start >= numLeds) {
121 start = numLeds > 0 ? numLeds - 1 : 0;
122 }
123 if (end > numLeds) {
124 end = numLeds;
125 }
126 if (end <= start) {
127 end = start + 1;
128 if (end > numLeds) {
129 end = numLeds;
130 start = end > 0 ? end - 1 : 0;
131 }
132 }
133
134 mSegmentStart = start;
136 mHasSegment = true;
137}
138
145
146// Helper function implementation
150
151} // namespace fl
CRGB leds[1]
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
fl::span< CRGB > getLEDs() FL_NO_EXCEPT override
Get the LED array as a span.
size_t mSegmentEnd
Definition adapter.h:72
void setCorrection(CRGB correction) FL_NO_EXCEPT override
Set color correction.
size_t getNumLEDs() const FL_NO_EXCEPT override
Get the number of LEDs.
void setMaxRefreshRate(u16 fps) FL_NO_EXCEPT override
Set the maximum refresh rate.
void clearSegment() FL_NO_EXCEPT override
Clear the segment range (operate on full LED array)
void show() FL_NO_EXCEPT override
Send the LED data to the strip Uses the current brightness setting.
void clear(bool writeToStrip=false) FL_NO_EXCEPT override
Clear all LEDs (set to black)
void setTemperature(CRGB temperature) FL_NO_EXCEPT override
Set color temperature.
void delay(unsigned long ms) FL_NO_EXCEPT override
Delay for a specified number of milliseconds.
FastLEDAdapter(u8 controllerIndex=0) FL_NO_EXCEPT
Construct adapter wrapping the global FastLED object.
void setBrightness(u8 brightness) FL_NO_EXCEPT override
Set the global brightness.
size_t mSegmentStart
Definition adapter.h:71
u16 getMaxRefreshRate() const FL_NO_EXCEPT override
Get the maximum refresh rate.
u8 getBrightness() const FL_NO_EXCEPT override
Get the current global brightness.
void setSegment(size_t start, size_t end) FL_NO_EXCEPT override
Set a segment range for subsequent operations.
constexpr T * end(T(&array)[N]) FL_NO_EXCEPT
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:423
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
fl::shared_ptr< IFastLED > createFastLEDController(u8 controllerIndex) FL_NO_EXCEPT
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:517
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38