FastLED 3.10.6
Loading...
Searching...
No Matches
power_mgt.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/system/fastled.h"
4
5#include "pixeltypes.h"
6#include "fl/gfx/rgbw.h"
7#include "fl/channels/cled_controller.h" // IWYU pragma: keep (controller_unscaled_power_mW)
8
11
12
13
17
18
22
34 float exponent;
35
37 constexpr PowerModelRGB()
38 : red_mW(5 * 16), green_mW(5 * 11), blue_mW(5 * 15), dark_mW(5 * 1),
39 exponent(1.0f) {}
40
51 constexpr PowerModelRGB(fl::u8 r, fl::u8 g, fl::u8 b, fl::u8 d, float e = 1.0f)
52 : red_mW(r), green_mW(g), blue_mW(b), dark_mW(d), exponent(e) {}
53};
54
63 float exponent;
64
66 constexpr PowerModelRGBW()
67 : red_mW(90), green_mW(70), blue_mW(90), white_mW(100), dark_mW(5),
68 exponent(1.0f) {}
69
78 float e = 1.0f)
79 : red_mW(r), green_mW(g), blue_mW(b), white_mW(w), dark_mW(d),
80 exponent(e) {}
81
90 constexpr PowerModelRGB toRGB() const {
92 }
93};
94
105 float exponent;
106
108 constexpr PowerModelRGBWW()
109 : red_mW(85), green_mW(65), blue_mW(85),
110 white_mW(95), warm_white_mW(95), dark_mW(5),
111 exponent(1.0f) {}
112
122 fl::u8 w, fl::u8 ww, fl::u8 d,
123 float e = 1.0f)
124 : red_mW(r), green_mW(g), blue_mW(b),
125 white_mW(w), warm_white_mW(ww), dark_mW(d),
126 exponent(e) {}
127
141 constexpr PowerModelRGB toRGB() const {
142 // Distribute white-channel mW evenly across R/G/B. Clamp to 255 (u8
143 // max) on overflow — a wrapping static_cast<u8> here would make the
144 // brightness limiter *less* conservative on the highest-draw configs
145 // (where it most needs to be conservative). The worst-case
146 // under-budget per channel from the floor division is 2 mW.
147 return PowerModelRGB(
148 static_cast<fl::u8>(
149 (red_mW + (white_mW + warm_white_mW) / 3) > 255
150 ? 255 : (red_mW + (white_mW + warm_white_mW) / 3)),
151 static_cast<fl::u8>(
152 (green_mW + (white_mW + warm_white_mW) / 3) > 255
153 ? 255 : (green_mW + (white_mW + warm_white_mW) / 3)),
154 static_cast<fl::u8>(
155 (blue_mW + (white_mW + warm_white_mW) / 3) > 255
156 ? 255 : (blue_mW + (white_mW + warm_white_mW) / 3)),
157 dark_mW,
158 exponent);
159 }
160};
161
169void set_power_model(const PowerModelRGB& model);
170
182void set_power_scaling_exponent(float exponent);
183
188
202void set_power_model(const PowerModelRGBW& model);
203
209void set_power_model(const PowerModelRGBWW& model);
210
214
221
226 fl::u8 emitter_count);
227
229
230
234
237void set_max_power_in_volts_and_milliamps( fl::u8 volts, fl::u32 milliamps);
238
241void set_max_power_in_milliwatts( fl::u32 powerInmW);
242
246void set_max_power_indicator_LED( fl::u8 pinNumber); // zero = no indicator LED
247
249
250
260
268void delay_at_max_brightness_for_power( fl::u16 ms);
269
271
272
276
282fl::u32 calculate_unscaled_power_mW( const CRGB* ledbuffer, fl::u16 numLeds);
283
287
308
317
329
342
352fl::u32 scale_power_for_brightness(fl::u32 total_mW, fl::u8 brightness);
353
379fl::u8 calculate_max_brightness_for_power_mW(const CRGB* ledbuffer, fl::u16 numLeds, fl::u8 target_brightness, fl::u32 max_power_mW);
380
389fl::u8 calculate_max_brightness_for_power_vmA(const CRGB* ledbuffer, fl::u16 numLeds, fl::u8 target_brightness, fl::u32 max_power_V, fl::u32 max_power_mA);
390
400fl::u8 calculate_max_brightness_for_power_mW( fl::u8 target_brightness, fl::u32 max_power_mW);
401
403
404
CRGB leds[1]
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
CLEDController * controller
Rgbw rgbw
base definitions used by led controllers for writing out led data
Functions for red, green, blue, white (RGBW) output.
Internal FastLED header for implementation files.
fl::CRGB CRGB
Definition crgb.h:25
fl::u32 calculate_unscaled_power_mW(const CRGB *ledbuffer, fl::u16 numLeds)
Determines how many milliwatts the current LED data would draw at max brightness (255)
void show_at_max_brightness_for_power()
Similar to CFastLED::show(), but pre-adjusts brightness to keep below the power threshold.
fl::u32 scale_power_for_brightness(fl::u32 total_mW, fl::u8 brightness)
Applies the configured power-scaling response to a total power value.
void set_max_power_indicator_LED(fl::u8 pinNumber)
Select a pin with an LED that will be flashed to indicate that power management is pulling down the b...
fl::u32 controller_unscaled_power_mW(const fl::CLEDController &controller)
One controller's demand at full brightness, in mW, including idle draw – the quantity the limiter sum...
fl::u8 calculate_max_brightness_for_power_mW(const CRGB *ledbuffer, fl::u16 numLeds, fl::u8 target_brightness, fl::u32 max_power_mW)
Determines the highest brightness level you can use and still stay under the specified power budget f...
void delay_at_max_brightness_for_power(fl::u16 ms)
Similar to CFastLED::delay(), but pre-adjusts brightness to keep below the power threshold.
void set_max_power_in_volts_and_milliamps(fl::u8 volts, fl::u32 milliamps)
Set the maximum power used in milliamps for a given voltage.
void set_max_power_in_milliwatts(fl::u32 powerInmW)
Set the maximum power used in watts.
fl::u32 controller_dither_reserve_mW(const fl::CLEDController &controller)
dither_reserve_mW() for a controller that dithers, and zero for one that does not: a mode other than ...
fl::u8 calculate_max_brightness_for_power_vmA(const CRGB *ledbuffer, fl::u16 numLeds, fl::u8 target_brightness, fl::u32 max_power_V, fl::u32 max_power_mA)
Determines the highest brightness level you can use and still stay under the specified power budget f...
fl::u32 dither_reserve_mW(fl::span< const CRGB > leds)
The most BINARY_DITHER can add to one latched frame of leds, in mW (#4342, contract R4: "quantization...
fl::u32 calculate_unscaled_emitter_power_mW(fl::span< const fl::u8 > codes, fl::u8 emitter_count)
Charge already-solved physical output bytes in source emitter order: RGB, RGBW, or RGB + warm white +...
fl::u8 get_white_emitter_mW()
The white-emitter draw the caller declared, or zero if they declared only an RGB model.
void set_power_model(const PowerModelRGB &model)
Set custom RGB LED power consumption model.
float get_power_scaling_exponent()
Get the current brightness-to-power response exponent.
void set_power_scaling_exponent(float exponent)
Set a non-linear brightness-to-power response exponent.
PowerModelRGB get_power_model()
Get current RGB power model.
unsigned char u8
Definition stdint.h:131
Includes defintions for RGB and HSV pixels.
fl::u8 blue_mW
Blue channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:32
fl::u8 dark_mW
Dark LED baseline power consumption, in milliwatts.
Definition power_mgt.h:33
fl::u8 red_mW
Red channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:30
float exponent
Brightness-to-power response exponent (1.0 = linear)
Definition power_mgt.h:34
fl::u8 green_mW
Green channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:31
constexpr PowerModelRGB(fl::u8 r, fl::u8 g, fl::u8 b, fl::u8 d, float e=1.0f)
Custom RGB power model.
Definition power_mgt.h:51
constexpr PowerModelRGB()
Default constructor - WS2812 @ 5V (16mA/11mA/15mA @ 5V), linear response.
Definition power_mgt.h:37
RGB LED power consumption model Used for standard 3-channel LEDs (WS2812, WS2812B,...
Definition power_mgt.h:29
constexpr PowerModelRGBW()
Default constructor - SK6812 RGBW @ 5V estimate, linear response.
Definition power_mgt.h:66
float exponent
Brightness-to-power response exponent (1.0 = linear)
Definition power_mgt.h:63
fl::u8 green_mW
Green channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:59
fl::u8 dark_mW
Dark LED baseline power consumption, in milliwatts.
Definition power_mgt.h:62
fl::u8 blue_mW
Blue channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:60
constexpr PowerModelRGB toRGB() const
The RGB emitters alone, without the white one.
Definition power_mgt.h:90
constexpr PowerModelRGBW(fl::u8 r, fl::u8 g, fl::u8 b, fl::u8 w, fl::u8 d, float e=1.0f)
Custom RGBW power model.
Definition power_mgt.h:77
fl::u8 white_mW
White channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:61
fl::u8 red_mW
Red channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:58
RGBW LED power consumption model Used for 4-channel LEDs (SK6812 RGBW and similar).
Definition power_mgt.h:57
fl::u8 white_mW
Cool white channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:102
float exponent
Brightness-to-power response exponent (1.0 = linear)
Definition power_mgt.h:105
fl::u8 green_mW
Green channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:100
fl::u8 warm_white_mW
Warm white channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:103
fl::u8 red_mW
Red channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:99
constexpr PowerModelRGBWW()
Default constructor - Hypothetical RGBWW @ 5V estimate, linear response.
Definition power_mgt.h:108
fl::u8 blue_mW
Blue channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:101
fl::u8 dark_mW
Dark LED baseline power consumption, in milliwatts.
Definition power_mgt.h:104
constexpr PowerModelRGB toRGB() const
Convert to RGB model (folds W/WW power back into RGB so the brightness limiter doesn't under-budget).
Definition power_mgt.h:141
constexpr PowerModelRGBWW(fl::u8 r, fl::u8 g, fl::u8 b, fl::u8 w, fl::u8 ww, fl::u8 d, float e=1.0f)
Custom RGBWW power model.
Definition power_mgt.h:121
RGBWW LED power consumption model (RGB + warm white + cool white).
Definition power_mgt.h:98