Skip to content

Commit

Permalink
fix power calculation for NeoPixelBusLg
Browse files Browse the repository at this point in the history
power estimation results from estimateCurrentAndLimitBri() were too low (example: estimated 1.3Amp, measured 1.6Amp). This change corrects the power calculation. Due to the changed behavior of getPixelColor, powerSum must be used as-is, not scaled down again by brightness.
  • Loading branch information
softhack007 committed Jul 8, 2023
1 parent 2c823d9 commit 2562f30
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,8 @@ void WS2812FX::estimateCurrentAndLimitBri() {
}

uint32_t powerSum0 = powerSum;
powerSum *= _brightness;
//powerSum *= _brightness; // for NPBrightnessBus
powerSum *= 255; // no need to scale down powerSum - NPB-LG getPixelColor returns colors scaled down by brightness

if (powerSum > powerBudget) //scale brightness down to stay in current limit
{
Expand All @@ -1704,9 +1705,10 @@ void WS2812FX::estimateCurrentAndLimitBri() {
uint8_t scaleB = (scaleI > 255) ? 255 : scaleI;
uint8_t newBri = scale8(_brightness, scaleB);
// to keep brightness uniform, sets virtual busses too - softhack007: apply reductions immediately
if (scaleB < 255) busses.setBrightness(scaleB, true); // NPB-LG has already applied brightness, so its suffifient to post-apply scaling
if (scaleB < 255) busses.setBrightness(scaleB, true); // NPB-LG has already applied brightness, so its suffifient to post-apply scaling ==> use scaleB instead of newBri
busses.setBrightness(newBri, false); // set new brightness for next frame
currentMilliamps = (powerSum0 * newBri) / puPerMilliamp;
//currentMilliamps = (powerSum0 * newBri) / puPerMilliamp; // for NPBrightnessBus
currentMilliamps = (powerSum0 * scaleB) / puPerMilliamp; // for NPBus-LG
} else {
currentMilliamps = powerSum / puPerMilliamp;
busses.setBrightness(_brightness, false); // set new brightness for next frame
Expand Down

0 comments on commit 2562f30

Please sign in to comment.