FastLED 3.10.10
Loading...
Searching...
No Matches

◆ calculate_max_brightness_for_power_mW() [1/2]

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 for a given set of LEDs.

What the budget bounds, stated rather than implied (#4156 R4):

  • The baseline is not scalable. PowerModel::dark_mW is drawn per LED at every brightness including zero, so it is subtracted from the budget first and only the remainder is divided among the emitters.
  • The budget is an upper bound. The answer is the largest brightness whose modeled draw fits, so it never exceeds the budget and never falls as the budget rises.
  • A budget at or below the baseline cannot be met. No brightness fits, so the answer is 0 and a warning is logged once a second. Lower the baseline with FastLED.setMcuPowerMilliWatts() and the power model's dark_mW, or raise the budget.
  • The bound is on the pre-dither frame. Demand is computed from the CRGB values, and BINARY_DITHER adds its offset afterwards, inside the encoder. That offset is shared across the frame, so a dithered frame can exceed the budgeted demand by up to one native code per channel per pixel – about 0.8 mW per LED on the default WS2812 model. The multi-frame mean is what the budget holds; a single latched frame can sit that much above it.
Parameters
ledbufferthe LED data to check
numLedsthe number of LEDs in the data array
target_brightnessthe brightness you'd ideally like to use
max_power_mWthe max power draw desired, in milliwatts
Returns
a limited brightness value. No higher than the target brightness, but may be lower depending on the power limit. Zero when the budget is at or below the unscalable baseline.

Definition at line 501 of file power_mgt.cpp.hpp.

501 {
502 const fl::u32 total_mW = calculate_unscaled_power_mW( ledbuffer, numLeds);
503 const fl::u32 fixed_mW = fixed_power_mW(numLeds);
504 const fl::u32 controllable_mW = total_mW > fixed_mW ? total_mW - fixed_mW : 0;
505
506 return brightness_within_budget(fixed_mW, controllable_mW, target_brightness,
507 max_power_mW);
508}
fl::u32 calculate_unscaled_power_mW(fl::span< const CRGB > leds) FL_NO_EXCEPT
static fl::u32 fixed_power_mW(fl::u32 led_count) FL_NO_EXCEPT
static fl::u8 brightness_within_budget(fl::u32 fixed_mW, fl::u32 controllable_mW, fl::u8 target_brightness, fl::u32 max_power_mW) FL_NO_EXCEPT

References brightness_within_budget(), calculate_unscaled_power_mW(), fixed_power_mW(), and FL_NO_EXCEPT.

Referenced by calculate_max_brightness_for_power_vmA(), and CFastLED::setMaxPowerInMilliWatts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: