From 788a276616bad2c50891bc3b33d896a8814d4452 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 6 Jul 2023 19:06:31 +0200 Subject: [PATCH] fix power calculation for NeoPixelBusLg 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. --- wled00/FX_fcn.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 51ef8caf..fa3b7e6d 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -1223,7 +1223,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 { @@ -1232,9 +1233,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