FastLED 3.10.8
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 548 of file power_mgt.cpp.hpp.

548 {
549 fl::u32 lit_r = 0, lit_g = 0, lit_b = 0;
550 for (fl::size i = 0; i < leds.size(); ++i) {
551 // A zero channel is never dithered: `dither()` returns 0 for it.
552 lit_r += leds[i].r != 0 ? 1u : 0u;
553 lit_g += leds[i].g != 0 ? 1u : 0u;
554 lit_b += leds[i].b != 0 ? 1u : 0u;
555 }
556 const PowerModelRGB& model = gPowerModel();
557 const dither_acc_t per_code =
558 static_cast<dither_acc_t>(lit_r) * model.red_mW +
559 static_cast<dither_acc_t>(lit_g) * model.green_mW +
560 static_cast<dither_acc_t>(lit_b) * model.blue_mW;
561 // Same >> 8 as the estimator, rounded up: this is a bound, and truncating
562 // it would hand back the under-charge it exists to remove.
563 const dither_acc_t scaled = per_code * kDitherReserveCodes * max_power_step();
564 const dither_acc_t reserve = (scaled + 255) >> 8;
565 // Saturate rather than wrap: an under-stated reserve is the failure this
566 // exists to prevent.
567 return reserve > 0xFFFFFFFFu ? 0xFFFFFFFFu : static_cast<fl::u32>(reserve);
568}
CRGB leds[1]
static constexpr fl::u32 kDitherReserveCodes
fl::conditional< sizeof(fl::size)<=2, fl::u32, fl::u64 >::type dither_acc_t
static PowerModelRGB & gPowerModel() FL_NO_EXCEPT
Global RGB power model (initialized to WS2812 @ 5V defaults, linear response)
static fl::u8 max_power_step() FL_NO_EXCEPT
What one output code can cost at the steepest point of the response, in the 0-255 scaled units calcul...
fl::u8 blue_mW
Blue channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:33
fl::u8 red_mW
Red channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:31
fl::u8 green_mW
Green channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:32
RGB LED power consumption model Used for standard 3-channel LEDs (WS2812, WS2812B,...
Definition power_mgt.h:30

References PowerModelRGB::blue_mW, FL_NO_EXCEPT, 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: