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

◆ dither_reserve_mW()

fl::u32 dither_reserve_mW ( fl::span< const CRGB > leds)

The most BINARY_DITHER can add to one latched frame of leds, in mW (#4342, contract R4: "quantization reserve").

Dither is applied before scaling and only ever raises a lit channel – dither() is b ? qadd8(b, d) : 0 – by up to two output codes at any non-zero brightness (the offset d <= 256/s is scaled back by s, and the FASTLED_SCALE8_FIXED rounding can carry once more). So the reserve is two codes on every lit channel, at the power model's steepest single-code step, rounded up. It does not scale with brightness, which is why the limiter adds it to the fixed part of the demand rather than the scaled part.

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

485 {
486 fl::u32 lit_r = 0, lit_g = 0, lit_b = 0;
487 for (fl::size i = 0; i < leds.size(); ++i) {
488 // A zero channel is never dithered: `dither()` returns 0 for it.
489 lit_r += leds[i].r != 0 ? 1u : 0u;
490 lit_g += leds[i].g != 0 ? 1u : 0u;
491 lit_b += leds[i].b != 0 ? 1u : 0u;
492 }
493 const PowerModelRGB& model = gPowerModel();
494 const fl::u64 per_code =
495 static_cast<fl::u64>(lit_r) * model.red_mW +
496 static_cast<fl::u64>(lit_g) * model.green_mW +
497 static_cast<fl::u64>(lit_b) * model.blue_mW;
498 // Same >> 8 as the estimator, rounded up: this is a bound, and truncating
499 // it would hand back the under-charge it exists to remove.
500 const fl::u64 scaled = per_code * kDitherReserveCodes * max_power_step();
501 const fl::u64 reserve = (scaled + 255) >> 8;
502 // Saturate rather than wrap: an under-stated reserve is the failure this
503 // exists to prevent.
504 return reserve > 0xFFFFFFFFu ? 0xFFFFFFFFu : static_cast<fl::u32>(reserve);
505}
CRGB leds[1]
static constexpr fl::u32 kDitherReserveCodes
static fl::u8 max_power_step()
What one output code can cost at the steepest point of the response, in the 0-255 scaled units calcul...
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 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
RGB LED power consumption model Used for standard 3-channel LEDs (WS2812, WS2812B,...
Definition power_mgt.h:29

References PowerModelRGB::blue_mW, gPowerModel(), PowerModelRGB::green_mW, kDitherReserveCodes, leds, max_power_step(), and PowerModelRGB::red_mW.

Referenced by controller_dither_reserve_mW().

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