10#if SKETCH_HAS_LARGE_MEMORY
46#if SKETCH_HAS_LARGE_MEMORY
47static constexpr fl::size kPowerScalingTableSize = 256;
52struct PowerScalingState {
53 fl::array<fl::u8, kPowerScalingTableSize>
forward;
54 fl::array<fl::u8, kPowerScalingTableSize>
reverse;
60 void reset_identity() {
61 for (fl::size i = 0; i < kPowerScalingTableSize; ++i) {
68static PowerScalingState& gPowerScaling() {
74static void rebuild_power_scaling_tables(
float exponent) {
75 PowerScalingState&
state = gPowerScaling();
76 if (!(exponent > 0.0f) ||
78 state.reset_identity();
84 for (fl::size i = 1; i < kPowerScalingTableSize; ++i) {
85 float normalized =
static_cast<float>(i) / 255.0f;
90 int mapped =
static_cast<int>(
94 state.forward[255] = 255;
101 for (
int scaled = 1; scaled < static_cast<int>(kPowerScalingTableSize); ++scaled) {
102 while (source < 255 &&
state.forward[source + 1] <= scaled) {
105 state.reverse[scaled] =
static_cast<fl::u8>(source);
111#if SKETCH_HAS_LARGE_MEMORY
119#if SKETCH_HAS_LARGE_MEMORY
120 return gPowerScaling().reverse[scaled_brightness];
122 return scaled_brightness;
148#define POWER_DEBUG_PRINT 0
159 fl::u32 red32 = 0, green32 = 0, blue32 = 0;
162 for(
size_t i = 0; i <
leds.size(); i++) {
198 fl::u8 recommended_brightness = target_brightness;
199 if(requested_power_mW > max_power_mW) {
200 fl::u8 recommended_scaled = (fl::u32)(target_brightness_scaled * (fl::u32)(max_power_mW)) / requested_power_mW;
204 return recommended_brightness;
220#if POWER_DEBUG_PRINT == 1
221 Serial.print(
"power demand at full brightness mW = ");
222 Serial.println( total_mW);
227#if POWER_DEBUG_PRINT == 1
228 if( target_brightness != 255 ) {
229 Serial.print(
"power demand at scaled brightness mW = ");
230 Serial.println( requested_power_mW);
232 Serial.print(
"power limit mW = ");
233 Serial.println( max_power_mW);
236 if( requested_power_mW < max_power_mW) {
242#if POWER_DEBUG_PRINT == 1
243 Serial.print(
"demand is under the limit");
245 return target_brightness;
248 fl::u8 recommended_scaled = (fl::u32)(target_brightness_scaled * (fl::u32)(max_power_mW)) / ((fl::u32)(requested_power_mW));
250#if POWER_DEBUG_PRINT == 1
251 Serial.print(
"recommended brightness # = ");
252 Serial.println( recommended_brightness);
255 Serial.print(
"resultant power demand mW = ");
256 Serial.println( resultant_power_mW);
267 return recommended_brightness;
277#if SKETCH_HAS_LARGE_MEMORY
278 rebuild_power_scaling_tables(model.
exponent);
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
CLEDController * next() FL_NOEXCEPT
Get the next controller in the linked list after this one.
CRGB * leds() FL_NOEXCEPT
Pointer to the CRGB array for this controller.
virtual int size() const FL_NOEXCEPT
How many LEDs does this controller manage?
static CLEDController * head() FL_NOEXCEPT
Get the first LED controller in the linked list of controllers.
static T & instance() FL_NOEXCEPT
fl::CLEDController CLEDController
Backward compatibility header - use fl/fastpin.h directly.
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::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...
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 calculate_unscaled_power_mW(fl::span< const CRGB > leds)
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.
Determines which platform system definitions to include.
constexpr T && forward(typename remove_reference< T >::type &t) FL_NOEXCEPT
float powf(float base, float exponent) FL_NOEXCEPT
constexpr bool almost_equal(T a, T b, U tolerance) FL_NOEXCEPT
long lroundf(float value) FL_NOEXCEPT
void reverse(Iterator first, Iterator last) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NOEXCEPT
Includes defintions for RGB and HSV pixels.
static constexpr float kLinearPowerScalingExponent
static fl::u8 unmap_power_value(fl::u8 scaled_brightness)
static constexpr float kPowerScalingExponentEpsilon
static fl::u8 gMaxPowerIndicatorLEDPinNumber
static fl::u8 map_power_value(fl::u8 brightness)
static const fl::u8 gMCU_mW
static PowerModelRGB & gPowerModel()
Global RGB power model (initialized to WS2812 @ 5V defaults, linear response)
Functions to limit the power used by FastLED.
fl::u8 blue_mW
Blue channel power at full brightness (255), in milliwatts.
fl::u8 dark_mW
Dark LED baseline power consumption, in milliwatts.
fl::u8 red_mW
Red channel power at full brightness (255), in milliwatts.
float exponent
Brightness-to-power response exponent (1.0 = linear)
fl::u8 green_mW
Green channel power at full brightness (255), in milliwatts.
RGB LED power consumption model Used for standard 3-channel LEDs (WS2812, WS2812B,...