FastLED 3.10.10
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#include "fl/stl/noexcept.h"
9
12
13
14
18
19
23
42 float exponent;
43
45 constexpr PowerModelRGB()
46 FL_NO_EXCEPT : red_mW(5 * 16), green_mW(5 * 11), blue_mW(5 * 15), dark_mW(5 * 1),
47 exponent(1.0f) {}
48
59 constexpr PowerModelRGB(fl::u8 r, fl::u8 g, fl::u8 b, fl::u8 d, float e = 1.0f)
60 FL_NO_EXCEPT : red_mW(r), green_mW(g), blue_mW(b), dark_mW(d), exponent(e) {}
61};
62
71 float exponent;
72
74 constexpr PowerModelRGBW()
75 FL_NO_EXCEPT : red_mW(90), green_mW(70), blue_mW(90), white_mW(100), dark_mW(5),
76 exponent(1.0f) {}
77
86 float e = 1.0f)
88 exponent(e) {}
89
101};
102
113 float exponent;
114
116 constexpr PowerModelRGBWW()
117 FL_NO_EXCEPT : red_mW(85), green_mW(65), blue_mW(85),
118 white_mW(95), warm_white_mW(95), dark_mW(5),
119 exponent(1.0f) {}
120
130 fl::u8 w, fl::u8 ww, fl::u8 d,
131 float e = 1.0f)
132 FL_NO_EXCEPT : red_mW(r), green_mW(g), blue_mW(b),
133 white_mW(w), warm_white_mW(ww), dark_mW(d),
134 exponent(e) {}
135
149 constexpr PowerModelRGB toRGB() const FL_NO_EXCEPT {
150 // Distribute white-channel mW evenly across R/G/B. Clamp to 255 (u8
151 // max) on overflow — a wrapping static_cast<u8> here would make the
152 // brightness limiter *less* conservative on the highest-draw configs
153 // (where it most needs to be conservative). The worst-case
154 // under-budget per channel from the floor division is 2 mW.
155 return PowerModelRGB(
156 static_cast<fl::u8>(
157 (red_mW + (white_mW + warm_white_mW) / 3) > 255
158 ? 255 : (red_mW + (white_mW + warm_white_mW) / 3)),
159 static_cast<fl::u8>(
160 (green_mW + (white_mW + warm_white_mW) / 3) > 255
161 ? 255 : (green_mW + (white_mW + warm_white_mW) / 3)),
162 static_cast<fl::u8>(
163 (blue_mW + (white_mW + warm_white_mW) / 3) > 255
164 ? 255 : (blue_mW + (white_mW + warm_white_mW) / 3)),
165 dark_mW,
166 exponent);
167 }
168};
169
178
183void set_mcu_power_mW(fl::u16 mcu_mW) FL_NO_EXCEPT;
186
198void set_power_scaling_exponent(float exponent) FL_NO_EXCEPT;
199
204
219
226
230
237
241fl::u32 calculate_unscaled_emitter_power_mW(fl::span<const fl::u8> codes,
242 fl::u8 emitter_count) FL_NO_EXCEPT;
243
245
246
250
253void set_max_power_in_volts_and_milliamps( fl::u8 volts, fl::u32 milliamps) FL_NO_EXCEPT;
254
257void set_max_power_in_milliwatts( fl::u32 powerInmW) FL_NO_EXCEPT;
258
262void set_max_power_indicator_LED( fl::u8 pinNumber) FL_NO_EXCEPT; // zero = no indicator LED
263
265
266
276
285
287
288
292
298fl::u32 calculate_unscaled_power_mW( const CRGB* ledbuffer, fl::u16 numLeds) FL_NO_EXCEPT;
299
303
323fl::u32 calculate_unscaled_power_mW(fl::span<const CRGB> leds, const fl::Rgbw& rgbw) FL_NO_EXCEPT;
324
333
344fl::u32 dither_reserve_mW(fl::span<const CRGB> leds) FL_NO_EXCEPT;
345
358
369
400fl::u8 calculate_max_brightness_for_power_mW(const CRGB* ledbuffer, fl::u16 numLeds, fl::u8 target_brightness, fl::u32 max_power_mW) FL_NO_EXCEPT;
401
410fl::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) FL_NO_EXCEPT;
411
421fl::u8 calculate_max_brightness_for_power_mW( fl::u8 target_brightness, fl::u32 max_power_mW) FL_NO_EXCEPT;
422
425fl::u32 power_ratio_of_255(fl::u32 num, fl::u32 den) FL_NO_EXCEPT;
426
428
429
CRGB leds[1]
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
CLEDController * controller
Rgbw rgbw
fl::CLEDController CLEDController
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
void set_max_power_indicator_LED(fl::u8 pinNumber) FL_NO_EXCEPT
Select a pin with an LED that will be flashed to indicate that power management is pulling down the b...
fl::u32 scale_power_for_brightness(fl::u32 total_mW, fl::u8 brightness) FL_NO_EXCEPT
Applies the configured power-scaling response to a total power value.
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) FL_NO_EXCEPT
Determines the highest brightness level you can use and still stay under the specified power budget f...
fl::u32 calculate_unscaled_power_mW(fl::span< const CRGB > leds) FL_NO_EXCEPT
fl::u8 calculate_max_brightness_for_power_mW(const CRGB *ledbuffer, fl::u16 numLeds, fl::u8 target_brightness, fl::u32 max_power_mW) FL_NO_EXCEPT
Determines the highest brightness level you can use and still stay under the specified power budget f...
fl::u32 power_ratio_of_255(fl::u32 num, fl::u32 den) FL_NO_EXCEPT
min(255, floor(255 * num / den)) for den > 0, computed in 32-bit arithmetic.
fl::u32 dither_reserve_mW(fl::span< const CRGB > leds) FL_NO_EXCEPT
The most BINARY_DITHER can add to one latched frame of leds, in mW (#4342, contract R4: "quantization...
void delay_at_max_brightness_for_power(fl::u16 ms) FL_NO_EXCEPT
Similar to CFastLED::delay(), but pre-adjusts brightness to keep below the power threshold.
void set_max_power_in_milliwatts(fl::u32 powerInmW) FL_NO_EXCEPT
Set the maximum power used in watts.
fl::u32 controller_dither_reserve_mW(const fl::CLEDController &controller) FL_NO_EXCEPT
dither_reserve_mW() for a controller that dithers, and zero for one that does not: a mode other than ...
fl::u32 controller_unscaled_power_mW(const fl::CLEDController &controller) FL_NO_EXCEPT
One controller's demand at full brightness, in mW, including idle draw – the quantity the limiter sum...
void set_max_power_in_volts_and_milliamps(fl::u8 volts, fl::u32 milliamps) FL_NO_EXCEPT
Set the maximum power used in milliamps for a given voltage.
void show_at_max_brightness_for_power() FL_NO_EXCEPT
Similar to CFastLED::show(), but pre-adjusts brightness to keep below the power threshold.
void set_power_scaling_exponent(float exponent) FL_NO_EXCEPT
Set a non-linear brightness-to-power response exponent.
PowerModelRGB get_power_model() FL_NO_EXCEPT
Get current RGB power model.
void set_power_model(const PowerModelRGB &model) FL_NO_EXCEPT
Set custom RGB LED power consumption model.
fl::u32 calculate_unscaled_emitter_power_mW(fl::span< const fl::u8 > codes, fl::u8 emitter_count) FL_NO_EXCEPT
Charge already-solved physical output bytes in source emitter order: RGB, RGBW, or RGB + warm white +...
fl::u16 get_mcu_power_mW() FL_NO_EXCEPT
The MCU baseline currently charged, in milliwatts.
float get_power_scaling_exponent() FL_NO_EXCEPT
Get the current brightness-to-power response exponent.
void set_mcu_power_mW(fl::u16 mcu_mW) FL_NO_EXCEPT
Override the MCU board's undimmable baseline draw, in milliwatts.
fl::u8 get_white_emitter_mW() FL_NO_EXCEPT
The white-emitter draw the caller declared, or zero if they declared only an RGB model.
unsigned char u8
Definition stdint.h:132
Base definition for an LED controller.
Includes defintions for RGB and HSV pixels.
#define FL_NO_EXCEPT
fl::u8 blue_mW
Blue channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:33
constexpr PowerModelRGB() FL_NO_EXCEPT
Default constructor - WS2812 @ 5V (16mA/11mA/15mA @ 5V), linear response.
Definition power_mgt.h:45
fl::u8 dark_mW
Dark (all channels off) draw per LED IC, in milliwatts, charged as an undimmable baseline.
Definition power_mgt.h:41
fl::u8 red_mW
Red channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:31
float exponent
Brightness-to-power response exponent (1.0 = linear)
Definition power_mgt.h:42
fl::u8 green_mW
Green channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:32
constexpr PowerModelRGB(fl::u8 r, fl::u8 g, fl::u8 b, fl::u8 d, float e=1.0f) FL_NO_EXCEPT
Custom RGB power model.
Definition power_mgt.h:59
RGB LED power consumption model Used for standard 3-channel LEDs (WS2812, WS2812B,...
Definition power_mgt.h:30
constexpr PowerModelRGBW() FL_NO_EXCEPT
Default constructor - SK6812 RGBW @ 5V estimate, linear response.
Definition power_mgt.h:74
constexpr PowerModelRGBW(fl::u8 r, fl::u8 g, fl::u8 b, fl::u8 w, fl::u8 d, float e=1.0f) FL_NO_EXCEPT
Custom RGBW power model.
Definition power_mgt.h:85
float exponent
Brightness-to-power response exponent (1.0 = linear)
Definition power_mgt.h:71
fl::u8 green_mW
Green channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:67
constexpr PowerModelRGB toRGB() const FL_NO_EXCEPT
The RGB emitters alone, without the white one.
Definition power_mgt.h:98
fl::u8 dark_mW
Dark LED baseline power consumption, in milliwatts.
Definition power_mgt.h:70
fl::u8 blue_mW
Blue channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:68
fl::u8 white_mW
White channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:69
fl::u8 red_mW
Red channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:66
RGBW LED power consumption model Used for 4-channel LEDs (SK6812 RGBW and similar).
Definition power_mgt.h:65
fl::u8 white_mW
Cool white channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:110
float exponent
Brightness-to-power response exponent (1.0 = linear)
Definition power_mgt.h:113
constexpr PowerModelRGBWW() FL_NO_EXCEPT
Default constructor - Hypothetical RGBWW @ 5V estimate, linear response.
Definition power_mgt.h:116
fl::u8 green_mW
Green channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:108
fl::u8 warm_white_mW
Warm white channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:111
constexpr PowerModelRGB toRGB() const FL_NO_EXCEPT
Convert to RGB model (folds W/WW power back into RGB so the brightness limiter doesn't under-budget).
Definition power_mgt.h:149
fl::u8 red_mW
Red channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:107
fl::u8 blue_mW
Blue channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:109
constexpr PowerModelRGBWW(fl::u8 r, fl::u8 g, fl::u8 b, fl::u8 w, fl::u8 ww, fl::u8 d, float e=1.0f) FL_NO_EXCEPT
Custom RGBWW power model.
Definition power_mgt.h:129
fl::u8 dark_mW
Dark LED baseline power consumption, in milliwatts.
Definition power_mgt.h:112
RGBWW LED power consumption model (RGB + warm white + cool white).
Definition power_mgt.h:106