Skip to content

Commit efa32ed

Browse files
committed
Size optimisations
1 parent 551b8af commit efa32ed

File tree

12 files changed

+144
-145
lines changed

12 files changed

+144
-145
lines changed

wled00/bus_manager.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ uint8_t IRAM_ATTR ColorOrderMap::getPixelColorOrder(uint16_t pix, uint8_t defaul
8080

8181

8282
uint32_t Bus::autoWhiteCalc(uint32_t c) {
83-
uint8_t aWM = _autoWhiteMode;
83+
unsigned aWM = _autoWhiteMode;
8484
if (_gAWM < AW_GLOBAL_DISABLED) aWM = _gAWM;
8585
if (aWM == RGBW_MODE_MANUAL_ONLY) return c;
86-
uint8_t w = W(c);
86+
unsigned w = W(c);
8787
//ignore auto-white calculation if w>0 and mode DUAL (DUAL behaves as BRIGHTER if w==0)
8888
if (w > 0 && aWM == RGBW_MODE_DUAL) return c;
89-
uint8_t r = R(c);
90-
uint8_t g = G(c);
91-
uint8_t b = B(c);
89+
unsigned r = R(c);
90+
unsigned g = G(c);
91+
unsigned b = B(c);
9292
if (aWM == RGBW_MODE_MAX) return RGBW32(r, g, b, r > g ? (r > b ? r : b) : (g > b ? g : b)); // brightest RGB channel
9393
w = r < g ? (r < b ? r : b) : (g < b ? g : b);
9494
if (aWM == RGBW_MODE_AUTO_ACCURATE) { r -= w; g -= w; b -= w; } //subtract w in ACCURATE mode
@@ -207,15 +207,15 @@ void BusDigital::show() {
207207
if (!_valid) return;
208208

209209
uint8_t cctWW = 0, cctCW = 0;
210-
uint8_t newBri = estimateCurrentAndLimitBri(); // will fill _milliAmpsTotal
210+
unsigned newBri = estimateCurrentAndLimitBri(); // will fill _milliAmpsTotal
211211
if (newBri < _bri) PolyBus::setBrightness(_busPtr, _iType, newBri); // limit brightness to stay within current limits
212212

213213
if (_data) {
214214
size_t channels = getNumberOfChannels();
215215
int16_t oldCCT = Bus::_cct; // temporarily save bus CCT
216216
for (size_t i=0; i<_len; i++) {
217217
size_t offset = i * channels;
218-
uint8_t co = _colorOrderMap.getPixelColorOrder(i+_start, _colorOrder);
218+
unsigned co = _colorOrderMap.getPixelColorOrder(i+_start, _colorOrder);
219219
uint32_t c;
220220
if (_type == TYPE_WS2812_1CH_X3) { // map to correct IC, each controls 3 LEDs (_len is always a multiple of 3)
221221
switch (i%3) {
@@ -234,7 +234,7 @@ void BusDigital::show() {
234234
Bus::_cct = _data[offset+channels-1];
235235
Bus::calculateCCT(c, cctWW, cctCW);
236236
}
237-
uint16_t pix = i;
237+
unsigned pix = i;
238238
if (_reversed) pix = _len - pix -1;
239239
pix += _skip;
240240
PolyBus::setPixelColor(_busPtr, _iType, pix, c, co, (cctCW<<8) | cctWW);
@@ -246,7 +246,7 @@ void BusDigital::show() {
246246
Bus::_cct = oldCCT;
247247
} else {
248248
if (newBri < _bri) {
249-
uint16_t hwLen = _len;
249+
unsigned hwLen = _len;
250250
if (_type == TYPE_WS2812_1CH_X3) hwLen = NUM_ICS_WS2812_1CH_3X(_len); // only needs a third of "RGB" LEDs for NeoPixelBus
251251
for (unsigned i = 0; i < hwLen; i++) {
252252
// use 0 as color order, actual order does not matter here as we just update the channel values as-is
@@ -302,9 +302,9 @@ void IRAM_ATTR BusDigital::setPixelColor(uint16_t pix, uint32_t c) {
302302
} else {
303303
if (_reversed) pix = _len - pix -1;
304304
pix += _skip;
305-
uint8_t co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder);
305+
unsigned co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder);
306306
if (_type == TYPE_WS2812_1CH_X3) { // map to correct IC, each controls 3 LEDs
307-
uint16_t pOld = pix;
307+
unsigned pOld = pix;
308308
pix = IC_INDEX_WS2812_1CH_3X(pix);
309309
uint32_t cOld = restoreColorLossy(PolyBus::getPixelColor(_busPtr, _iType, pix, co),_bri);
310310
switch (pOld % 3) { // change only the single channel (TODO: this can cause loss because of get/set)
@@ -333,12 +333,12 @@ uint32_t IRAM_ATTR BusDigital::getPixelColor(uint16_t pix) {
333333
} else {
334334
if (_reversed) pix = _len - pix -1;
335335
pix += _skip;
336-
uint8_t co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder);
336+
unsigned co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder);
337337
uint32_t c = restoreColorLossy(PolyBus::getPixelColor(_busPtr, _iType, (_type==TYPE_WS2812_1CH_X3) ? IC_INDEX_WS2812_1CH_3X(pix) : pix, co),_bri);
338338
if (_type == TYPE_WS2812_1CH_X3) { // map to correct IC, each controls 3 LEDs
339-
uint8_t r = R(c);
340-
uint8_t g = _reversed ? B(c) : G(c); // should G and B be switched if _reversed?
341-
uint8_t b = _reversed ? G(c) : B(c);
339+
unsigned r = R(c);
340+
unsigned g = _reversed ? B(c) : G(c); // should G and B be switched if _reversed?
341+
unsigned b = _reversed ? G(c) : B(c);
342342
switch (pix % 3) { // get only the single channel
343343
case 0: c = RGBW32(g, g, g, g); break;
344344
case 1: c = RGBW32(r, r, r, r); break;
@@ -350,7 +350,7 @@ uint32_t IRAM_ATTR BusDigital::getPixelColor(uint16_t pix) {
350350
}
351351

352352
uint8_t BusDigital::getPins(uint8_t* pinArray) {
353-
uint8_t numPins = IS_2PIN(_type) ? 2 : 1;
353+
unsigned numPins = IS_2PIN(_type) ? 2 : 1;
354354
for (unsigned i = 0; i < numPins; i++) pinArray[i] = _pins[i];
355355
return numPins;
356356
}
@@ -382,7 +382,7 @@ BusPwm::BusPwm(BusConfig &bc)
382382
: Bus(bc.type, bc.start, bc.autoWhite, 1, bc.reversed)
383383
{
384384
if (!IS_PWM(bc.type)) return;
385-
uint8_t numPins = NUM_PWM_PINS(bc.type);
385+
unsigned numPins = NUM_PWM_PINS(bc.type);
386386
_frequency = bc.frequency ? bc.frequency : WLED_PWM_FREQ;
387387

388388
#ifdef ESP8266
@@ -512,7 +512,7 @@ static const uint16_t cieLUT[256] = {
512512

513513
void BusPwm::show() {
514514
if (!_valid) return;
515-
uint8_t numPins = NUM_PWM_PINS(_type);
515+
unsigned numPins = NUM_PWM_PINS(_type);
516516
unsigned maxBri = (1<<_depth) - 1;
517517
#ifdef ESP8266
518518
unsigned pwmBri = (unsigned)(roundf(powf((float)_bri / 255.0f, 1.7f) * (float)maxBri)); // using gamma 1.7 to extrapolate PWM duty cycle
@@ -532,15 +532,15 @@ void BusPwm::show() {
532532

533533
uint8_t BusPwm::getPins(uint8_t* pinArray) {
534534
if (!_valid) return 0;
535-
uint8_t numPins = NUM_PWM_PINS(_type);
535+
unsigned numPins = NUM_PWM_PINS(_type);
536536
for (unsigned i = 0; i < numPins; i++) {
537537
pinArray[i] = _pins[i];
538538
}
539539
return numPins;
540540
}
541541

542542
void BusPwm::deallocatePins() {
543-
uint8_t numPins = NUM_PWM_PINS(_type);
543+
unsigned numPins = NUM_PWM_PINS(_type);
544544
for (unsigned i = 0; i < numPins; i++) {
545545
pinManager.deallocatePin(_pins[i], PinOwner::BusPwm);
546546
if (!pinManager.isPinOk(_pins[i])) continue;
@@ -632,7 +632,7 @@ void BusNetwork::setPixelColor(uint16_t pix, uint32_t c) {
632632
if (!_valid || pix >= _len) return;
633633
if (_rgbw) c = autoWhiteCalc(c);
634634
if (Bus::_cct >= 1900) c = colorBalanceFromKelvin(Bus::_cct, c); //color correction from CCT
635-
uint16_t offset = pix * _UDPchannels;
635+
unsigned offset = pix * _UDPchannels;
636636
_data[offset] = R(c);
637637
_data[offset+1] = G(c);
638638
_data[offset+2] = B(c);
@@ -641,7 +641,7 @@ void BusNetwork::setPixelColor(uint16_t pix, uint32_t c) {
641641

642642
uint32_t BusNetwork::getPixelColor(uint16_t pix) {
643643
if (!_valid || pix >= _len) return 0;
644-
uint16_t offset = pix * _UDPchannels;
644+
unsigned offset = pix * _UDPchannels;
645645
return RGBW32(_data[offset], _data[offset+1], _data[offset+2], (_rgbw ? _data[offset+3] : 0));
646646
}
647647

@@ -854,7 +854,7 @@ Bus* BusManager::getBus(uint8_t busNr) {
854854

855855
//semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit())
856856
uint16_t BusManager::getTotalLength() {
857-
uint16_t len = 0;
857+
unsigned len = 0;
858858
for (unsigned i=0; i<numBusses; i++) len += busses[i]->getLength();
859859
return len;
860860
}

wled00/button.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void doublePressAction(uint8_t b)
9393
bool isButtonPressed(uint8_t i)
9494
{
9595
if (btnPin[i]<0) return false;
96-
uint8_t pin = btnPin[i];
96+
unsigned pin = btnPin[i];
9797

9898
switch (buttonType[i]) {
9999
case BTN_TYPE_NONE:
@@ -171,7 +171,7 @@ void handleAnalog(uint8_t b)
171171
{
172172
static uint8_t oldRead[WLED_MAX_BUTTONS] = {0};
173173
static float filteredReading[WLED_MAX_BUTTONS] = {0.0f};
174-
uint16_t rawReading; // raw value from analogRead, scaled to 12bit
174+
unsigned rawReading; // raw value from analogRead, scaled to 12bit
175175

176176
DEBUG_PRINT(F("Analog: Reading button ")); DEBUG_PRINTLN(b);
177177

@@ -184,7 +184,7 @@ void handleAnalog(uint8_t b)
184184
yield(); // keep WiFi task running - analog read may take several millis on ESP8266
185185

186186
filteredReading[b] += POT_SMOOTHING * ((float(rawReading) / 16.0f) - filteredReading[b]); // filter raw input, and scale to [0..255]
187-
uint16_t aRead = max(min(int(filteredReading[b]), 255), 0); // squash into 8bit
187+
unsigned aRead = max(min(int(filteredReading[b]), 255), 0); // squash into 8bit
188188
if(aRead <= POT_SENSITIVITY) aRead = 0; // make sure that 0 and 255 are used
189189
if(aRead >= 255-POT_SENSITIVITY) aRead = 255;
190190

@@ -260,7 +260,7 @@ void handleButton()
260260
if (strip.isUpdating() && (now - lastRun < ANALOG_BTN_READ_CYCLE+1)) return; // don't interfere with strip update (unless strip is updating continuously, e.g. very long strips)
261261
lastRun = now;
262262

263-
for (uint8_t b=0; b<WLED_MAX_BUTTONS; b++) {
263+
for (unsigned b=0; b<WLED_MAX_BUTTONS; b++) {
264264
#ifdef ESP8266
265265
if ((btnPin[b]<0 && !(buttonType[b] == BTN_TYPE_ANALOG || buttonType[b] == BTN_TYPE_ANALOG_INVERTED)) || buttonType[b] == BTN_TYPE_NONE) continue;
266266
#else

wled00/colors.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
uint32_t color_blend(uint32_t color1, uint32_t color2, uint16_t blend, bool b16) {
1111
if(blend == 0) return color1;
12-
uint16_t blendmax = b16 ? 0xFFFF : 0xFF;
12+
unsigned blendmax = b16 ? 0xFFFF : 0xFF;
1313
if(blend == blendmax) return color2;
1414
uint8_t shift = b16 ? 16 : 8;
1515

@@ -52,7 +52,7 @@ uint32_t color_add(uint32_t c1, uint32_t c2, bool fast)
5252
uint32_t g = G(c1) + G(c2);
5353
uint32_t b = B(c1) + B(c2);
5454
uint32_t w = W(c1) + W(c2);
55-
uint16_t max = r;
55+
unsigned max = r;
5656
if (g > max) max = g;
5757
if (b > max) max = b;
5858
if (w > max) max = w;

0 commit comments

Comments
 (0)