FastLED 3.10.6
Loading...
Searching...
No Matches

◆ calculate_unscaled_power_mW() [3/3]

fl::u32 calculate_unscaled_power_mW ( fl::span< const CRGB > leds,
const fl::Rgbw & rgbw )

Same, for a strip driven through the RGBW conversion.

The overloads above read the source CRGB triple, which is what the sketch wrote – not what the strip is driven with. A controller in RGBW mode converts every pixel with rgb_2_rgbw before latching, and the resulting four drives are neither bounded by nor proportional to the source triple. Measured on the shipped default PowerModelRGBW at full white, in units of the sum below: source-triple 249 against a true 348 under kRGBWMaxBrightness, 266 under kRGBWBoostedWhite, 99 under kRGBWExactColors. The first two are the budget being under-spent against; the third is a strip dimmed for no reason.

This runs the same conversion the encoder will and charges all four emitters. It needs white_mW, so it falls back to the three-emitter figure – and says so once – when the caller declared only an RGB model.

Parameters
ledsspan of LED data to check
rgbwthe controller's RGBW setting; an inactive one delegates to the three-emitter overload

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

310 {
311 const fl::u8 white_mW = gWhiteEmitterPower().mW;
312 // `!rgbw.active()` is a fast path, not a different answer: the only
313 // inactive mode is `kRGBWInvalid`, which `rgb_2_rgbw` dispatches to
314 // null-white -- RGB passed through with w = 0 -- so the loop below would
315 // return the same total. Removing the test changes nothing observable
316 // and costs one conversion per pixel on every plain RGB controller in
317 // the sketch, which the estimator walks once per frame.
318 //
319 // The `white_mW == 0` half *is* behavioural: with no declared white
320 // there is nothing to charge the fourth diode at.
321 if (!rgbw.active() || white_mW == 0) {
322 if (rgbw.active()) {
323 FL_WARN_ONCE("power: controller is in RGBW mode but the power model "
324 "declares no white emitter, so the budget covers three "
325 "of its four diodes. Call "
326 "FastLED.setPowerModel(PowerModelRGBW(...)) to fix it.");
327 }
329 }
330
331 fl::u32 red32 = 0, green32 = 0, blue32 = 0, white32 = 0;
332 for (fl::size i = 0; i < leds.size(); i++) {
333 fl::u8 r = 0, g = 0, b = 0, w = 0;
334 fl::rgb_2_rgbw(rgbw, leds[i].r, leds[i].g, leds[i].b, 255, 255, 255,
335 &r, &g, &b, &w);
336 red32 += map_power_value(r);
337 green32 += map_power_value(g);
338 blue32 += map_power_value(b);
339 white32 += map_power_value(w);
340 }
341
342 red32 *= gPowerModel().red_mW;
343 green32 *= gPowerModel().green_mW;
344 blue32 *= gPowerModel().blue_mW;
345 white32 *= white_mW;
346
347 red32 >>= 8;
348 green32 >>= 8;
349 blue32 >>= 8;
350 white32 >>= 8;
351
352 return red32 + green32 + blue32 + white32 +
353 (gPowerModel().dark_mW * leds.size());
354}
CRGB leds[1]
Rgbw rgbw
fl::u32 calculate_unscaled_power_mW(fl::span< const CRGB > leds)
Determines how many milliwatts the current LED data would draw at max brightness (255)
#define FL_WARN_ONCE(...)
Definition log.h:442
unsigned char u8
Definition stdint.h:131
FASTLED_FORCE_INLINE void rgb_2_rgbw(const Rgbw &cfg, u8 r, u8 g, u8 b, u8 r_scale, u8 g_scale, u8 b_scale, u8 *out_r, u8 *out_g, u8 *out_b, u8 *out_w) FL_NO_EXCEPT
Converts RGB to RGBW using one of the functions.
Definition rgbw.h:380
InputGamut g
Definition rgbw.h:124
static WhiteEmitterPower & gWhiteEmitterPower()
static fl::u8 map_power_value(fl::u8 brightness)
static PowerModelRGB & gPowerModel()
Global RGB power model (initialized to WS2812 @ 5V defaults, linear response)
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
fl::u8 green_mW
Green channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:31

References PowerModelRGB::blue_mW, calculate_unscaled_power_mW(), PowerModelRGB::dark_mW, FL_WARN_ONCE, gPowerModel(), PowerModelRGB::green_mW, gWhiteEmitterPower(), leds, map_power_value(), WhiteEmitterPower::mW, PowerModelRGB::red_mW, fl::rgb_2_rgbw(), and rgbw.

+ Here is the call graph for this function: