Fix compilation and ABL scaling

pull/3280/head
cschwinne 2023-07-09 12:32:28 +02:00
rodzic 822298ab66
commit 6267d11e51
2 zmienionych plików z 11 dodań i 12 usunięć

Wyświetl plik

@ -1178,7 +1178,7 @@ uint8_t WS2812FX::estimateCurrentAndLimitBri() {
powerBudget = 0; powerBudget = 0;
} }
uint32_t powerSum = 0; uint32_t powerSum = 0; // could overflow if more than 22K LEDs (uint32_t MAX / 195075 PU per LED)
for (uint_fast8_t bNum = 0; bNum < busses.getNumBusses(); bNum++) { for (uint_fast8_t bNum = 0; bNum < busses.getNumBusses(); bNum++) {
Bus *bus = busses.getBus(bNum); Bus *bus = busses.getBus(bNum);
@ -1186,14 +1186,9 @@ uint8_t WS2812FX::estimateCurrentAndLimitBri() {
uint16_t len = bus->getLength(); uint16_t len = bus->getLength();
uint32_t busPowerSum = 0; uint32_t busPowerSum = 0;
for (uint_fast16_t i = 0; i < len; i++) { //sum up the usage of each LED for (uint_fast16_t i = 0; i < len; i++) { //sum up the usage of each LED
uint32_t c = bus->getPixelColor(i); uint32_t c = bus->getPixelColor(i); // always returns original or restored color without brightness scaling
byte r = R(c), g = G(c), b = B(c), w = W(c); byte r = R(c), g = G(c), b = B(c), w = W(c);
if (useGlobalLedBuffer) { // TODO this should only apply for digital bus typpes
r = scale8(r, _brightness);
g = scale8(g, _brightness);
b = scale8(b, _brightness);
w = scale8(w, _brightness);
}
if(useWackyWS2815PowerModel) { //ignore white component on WS2815 power calculation if(useWackyWS2815PowerModel) { //ignore white component on WS2815 power calculation
busPowerSum += (MAX(MAX(r,g),b)) * 3; busPowerSum += (MAX(MAX(r,g),b)) * 3;
} else { } else {
@ -1209,13 +1204,16 @@ uint8_t WS2812FX::estimateCurrentAndLimitBri() {
} }
uint8_t newBri = _brightness; uint8_t newBri = _brightness;
uint32_t powerSumUnscaled = powerSum;
powerSum *= _brightness;
if (powerSum > powerBudget) { //scale brightness down to stay in current limit if (powerSum > powerBudget) { //scale brightness down to stay in current limit
float scale = (float)powerBudget / (float)powerSum; float scale = (float)powerBudget / (float)powerSum;
uint16_t scaleI = scale * 255; uint16_t scaleI = scale * 255;
uint8_t scaleB = (scaleI > 255) ? 255 : scaleI; uint8_t scaleB = (scaleI > 255) ? 255 : scaleI;
newBri = scale8(_brightness, scaleB); newBri = scale8(_brightness, scaleB);
} }
currentMilliamps = (powerSum * newBri) / puPerMilliamp; currentMilliamps = (powerSumUnscaled * newBri) / puPerMilliamp;
currentMilliamps += MA_FOR_ESP; //add power of ESP back to estimate currentMilliamps += MA_FOR_ESP; //add power of ESP back to estimate
currentMilliamps += pLen; //add standby power back to estimate currentMilliamps += pLen; //add standby power back to estimate
return newBri; return newBri;

Wyświetl plik

@ -174,7 +174,7 @@ bool BusDigital::canShow() {
return PolyBus::canShow(_busPtr, _iType); return PolyBus::canShow(_busPtr, _iType);
} }
void BusDigital::setBrightness(uint8_t b, bool immediate) { void BusDigital::setBrightness(uint8_t b) {
//Fix for turning off onboard LED breaking bus //Fix for turning off onboard LED breaking bus
#ifdef LED_BUILTIN #ifdef LED_BUILTIN
if (_bri == 0 && b > 0) { if (_bri == 0 && b > 0) {
@ -224,6 +224,7 @@ void IRAM_ATTR BusDigital::setPixelColor(uint16_t pix, uint32_t c) {
} }
} }
// returns original color if global buffering is enabled, else returns lossly restored color from bus
uint32_t BusDigital::getPixelColor(uint16_t pix) { uint32_t BusDigital::getPixelColor(uint16_t pix) {
if (!_valid) return 0; if (!_valid) return 0;
if (buffering) { // should be _data != nullptr, but that causes ~20% FPS drop if (buffering) { // should be _data != nullptr, but that causes ~20% FPS drop
@ -587,9 +588,9 @@ void IRAM_ATTR BusManager::setPixelColor(uint16_t pix, uint32_t c) {
} }
} }
void BusManager::setBrightness(uint8_t b, bool immediate) { void BusManager::setBrightness(uint8_t b) {
for (uint8_t i = 0; i < numBusses; i++) { for (uint8_t i = 0; i < numBusses; i++) {
busses[i]->setBrightness(b, immediate); busses[i]->setBrightness(b);
} }
} }