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

◆ getEstimatedPowerInMilliWatts()

fl::u32 CFastLED::getEstimatedPowerInMilliWatts ( bool apply_limiter = true) const

Get estimated power consumption in milliwatts.

Calculates the estimated power consumption based on current LED buffer contents, brightness setting, and configured power model. This provides visibility into power usage for monitoring and debugging.

Parameters
apply_limiterIf true (default), applies power limiting to calculate actual power. If false, returns requested power before limiting.
Returns
Estimated LED power consumption in milliwatts:
  • apply_limiter=true: Power AFTER applying max-power cap (actual power)
  • apply_limiter=false: Power BEFORE limiting (requested power)
Note
Usage examples:
fl::u32 actual = FastLED.getEstimatedPowerInMilliWatts(); // With limiting (default)
fl::u32 requested = FastLED.getEstimatedPowerInMilliWatts(false); // Without limiting
CFastLED FastLED
Global LED strip management instance.
When apply_limiter=true:
  • If power limiting is NOT enabled, returns unrestricted power
  • If power limiting IS enabled, returns power after brightness reduction
MCU power consumption is NOT included in this calculation. Add your platform-specific MCU power separately:
fl::u32 mcu_power_mW = 25 * 5; // 25mA @ 5V = 125mW (Arduino Uno example)
fl::u32 total_power = FastLED.getEstimatedPowerInMilliWatts() + mcu_power_mW;
Uses the configured power-scaling response. Default is linear scaling; use model.exponent via setPowerModel() or the setPowerScalingExponent() convenience wrapper to enable a non-linear model.
See also
setMaxPowerInMilliWatts()
setPowerModel()
setPowerScalingExponent()

Definition at line 578 of file FastLED.cpp.hpp.

578 {
579#if FL_COLOR_PIPELINE_SHARED
580 if (apply_limiter && mPPowerFunc && fl::activeFramePowerDispatch()) {
581 bool managed = false;
582 for (CLEDController* p = CLEDController::head(); p; p = p->next()) {
583 if (p->getEnabled() && fl::channelColorPipeline(*p)) {
584 managed = true;
585 break;
586 }
587 }
588 if (managed) {
589 const fl::FramePowerPlan plan =
590 fl::activeFramePowerDispatch()->calculate(mScale, mNPowerData);
591 if (plan.modeled_mW == 0xFFFFFFFFu) return plan.modeled_mW;
592 const fl::u32 mcu_mW = plan.mcu_mW;
593 return plan.modeled_mW > mcu_mW ? plan.modeled_mW - mcu_mW : 0;
594 }
595 }
596#endif
597 fl::u32 fixed_power_mW = 0;
598 fl::u32 controllable_power_mW = 0;
599 fl::u32 dither_reserve_power_mW = 0;
600
601 // Sum unscaled power from all LED controllers using visitor pattern.
602 // The dark-current baseline is kept apart from the part brightness scales,
603 // because it is drawn at every brightness including zero (#4156 R4).
604 const fl::u32 dark_mW_per_led = get_power_model().dark_mW;
605 CLEDController::visitControllers([&](const CLEDController* controller, fl::span<const CRGB> leds) {
606 if (!leds.empty()) {
607 // The controller's own estimate: its RGBW setting, so an RGBW strip
608 // is charged for the diode it actually lights, and for a bound
609 // colour profile the solved drives rather than the source (#4344).
610 const fl::u32 unscaled_mW = controller_unscaled_power_mW(*controller);
611 const fl::u32 dark_mW = dark_mW_per_led * static_cast<fl::u32>(leds.size());
612 fixed_power_mW += dark_mW;
613 controllable_power_mW += unscaled_mW > dark_mW ? unscaled_mW - dark_mW : 0;
614 // What dithering can add on top, at any non-zero brightness (#4342).
615 // Not on TINY, where the bound costs more flash than the tier has
616 // to spare (#4478); controller_dither_reserve_mW is 0 there.
617#if !FL_PLATFORM_HAS_TINY_MEMORY
618 dither_reserve_power_mW += controller_dither_reserve_mW(*controller);
619#endif
620 }
621 });
622
623 // Determine effective brightness
624 fl::u8 effective_brightness = mScale;
625
626 if (apply_limiter && mPPowerFunc) {
627 // Power limiting is enabled and user wants limited power - calculate brightness after limiting
628 // This calls calculate_max_brightness_for_power_mW(mScale, mNPowerData)
629 effective_brightness = (*mPPowerFunc)(mScale, mNPowerData);
630 }
631
632 // Scale only the emitter share by the configured power-brightness response
633 // and add the baseline back, so the estimate matches what the limiter now
634 // budgets against.
635 // Note: MCU power consumption is NOT included - caller should add platform-specific MCU power if needed
636 // The dither reserve only at a non-zero brightness: nothing dithers at 0,
637 // the same as the limiter, whose answer of 0 needs no reserve either.
638 if (effective_brightness != 0) {
639 fixed_power_mW += dither_reserve_power_mW;
640 }
641 return fixed_power_mW +
642 scale_power_for_brightness(controllable_power_mW, effective_brightness);
643}
CLEDController * controller
power_func mPPowerFunc
function for overriding brightness when using FastLED.show();
Definition FastLED.h:728
fl::u8 mScale
the current global brightness scale setting
Definition FastLED.h:724
CRGB * leds() FL_NO_EXCEPT
Get a pointer to led data for the first controller.
fl::u32 mNPowerData
max power use parameter
Definition FastLED.h:727
static void visitControllers(Visitor &&visitor) FL_NO_EXCEPT
Visit all controllers in the linked list with a visitor The visitor must be a callable that accepts (...
static CLEDController * head() FL_NO_EXCEPT
Get the first LED controller in the linked list of controllers.
fl::CLEDController CLEDController
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::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...
PowerModelRGB get_power_model() FL_NO_EXCEPT
Get current RGB power model.
unsigned char u8
Definition stdint.h:132
static fl::u32 fixed_power_mW(fl::u32 led_count) FL_NO_EXCEPT
fl::u8 dark_mW
Dark (all channels off) draw per LED IC, in milliwatts, charged as an undimmable baseline.
Definition power_mgt.h:41

References controller, controller_dither_reserve_mW(), controller_unscaled_power_mW(), PowerModelRGB::dark_mW, fixed_power_mW(), FL_NO_EXCEPT, get_power_model(), fl::CLEDController::head(), leds(), fl::FramePowerPlan::mcu_mW, mNPowerData, fl::FramePowerPlan::modeled_mW, mPPowerFunc, mScale, scale_power_for_brightness(), and fl::CLEDController::visitControllers().

+ Here is the call graph for this function: