Skip to content

Commit 7e1920d

Browse files
authored
Remove ledCount (wled#2300)
Bus initialization on reading from eeprom
1 parent a93f05c commit 7e1920d

File tree

12 files changed

+40
-35
lines changed

12 files changed

+40
-35
lines changed

usermods/Artemis_reciever/usermod.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void RGBNET_readValues() {
2424
int channel = UDP.read();
2525

2626
//channel data is not used we only supports one channel
27-
int len = UDP.read(RGBNET_packet, ledCount*3);
27+
int len = UDP.read(RGBNET_packet, strip.getLengthTotal()*3);
2828
if(len==0){
2929
return;
3030
}
@@ -50,7 +50,7 @@ void handleConfig(AsyncWebServerRequest *request)
5050
\"channels\": [\
5151
{\
5252
\"channel\": 1,\
53-
\"leds\": " + ledCount + "\
53+
\"leds\": " + strip.getLengthTotal() + "\
5454
},\
5555
{\
5656
\"channel\": 2,\

usermods/project_cars_shiftlight/wled06_usermod.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* I've had good results with settings around 5 (20 fps).
66
*
77
*/
8+
#include "wled.h"
9+
810
const uint8_t PCARS_dimcolor = 20;
911
WiFiUDP UDP;
1012
const unsigned int PCARS_localUdpPort = 5606; // local port to listen on
@@ -49,11 +51,12 @@ void PCARS_readValues() {
4951
void PCARS_buildcolorbars() {
5052
boolean activated = false;
5153
float ledratio = 0;
54+
uint16_t totalLen = strip.getLengthTotal();
5255

53-
for (uint16_t i = 0; i < ledCount; i++) {
56+
for (uint16_t i = 0; i < totalLen; i++) {
5457
if (PCARS_rpmRatio < .95 || (millis() % 100 > 70 )) {
5558

56-
ledratio = (float)i / (float)ledCount;
59+
ledratio = (float)i / (float)totalLen;
5760
if (ledratio < PCARS_rpmRatio) {
5861
activated = true;
5962
} else {

wled00/FX_fcn.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ void WS2812FX::finalizeInit(void)
108108
if (pins[0] == 3) bd->reinit();
109109
#endif
110110
}
111-
ledCount = _length;
112111

113112
//segments are created in makeAutoSegments();
114113

wled00/cfg.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,12 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
7878
// initialize LED pins and lengths prior to other HW (except for ethernet)
7979
JsonObject hw_led = hw[F("led")];
8080

81-
CJSON(ledCount, hw_led[F("total")]);
82-
if (ledCount > MAX_LEDS) ledCount = MAX_LEDS;
83-
8481
CJSON(strip.ablMilliampsMax, hw_led[F("maxpwr")]);
8582
CJSON(strip.milliampsPerLed, hw_led[F("ledma")]);
8683
CJSON(strip.rgbwMode, hw_led[F("rgbwm")]);
8784

8885
JsonArray ins = hw_led["ins"];
89-
90-
uint16_t lC = 0;
91-
86+
9287
if (fromFS || !ins.isNull()) {
9388
uint8_t s = 0; // bus iterator
9489
busses.removeAll();
@@ -115,15 +110,12 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
115110
bool refresh = elm["ref"] | false;
116111
ledType |= refresh << 7; // hack bit 7 to indicate strip requires off refresh
117112
s++;
118-
uint16_t busEnd = start + length;
119-
if (busEnd > lC) lC = busEnd;
120113
BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst);
121114
mem += BusManager::memUsage(bc);
122115
if (mem <= MAX_LED_MEMORY && busses.getNumBusses() <= WLED_MAX_BUSSES) busses.add(bc); // finalization will be done in WLED::beginStrip()
123116
}
124117
// finalization done in beginStrip()
125118
}
126-
if (lC > ledCount) ledCount = lC; // fix incorrect total length (honour analog setup)
127119
if (hw_led["rev"]) busses.getBus(0)->reversed = true; //set 0.11 global reversed setting for first bus
128120

129121
// read multiple button configuration
@@ -526,7 +518,7 @@ void serializeConfig() {
526518
JsonObject hw = doc.createNestedObject("hw");
527519

528520
JsonObject hw_led = hw.createNestedObject("led");
529-
hw_led[F("total")] = ledCount;
521+
hw_led[F("total")] = strip.getLengthTotal(); //no longer read, but provided for compatibility on downgrade
530522
hw_led[F("maxpwr")] = strip.ablMilliampsMax;
531523
hw_led[F("ledma")] = strip.milliampsPerLed;
532524
hw_led[F("rgbwm")] = strip.rgbwMode;

wled00/dmx.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ void handleDMX()
1818

1919
uint8_t brightness = strip.getBrightness();
2020

21-
for (int i = DMXStartLED; i < ledCount; i++) { // uses the amount of LEDs as fixture count
21+
uint16_t len = strip.getLengthTotal();
22+
for (int i = DMXStartLED; i < len; i++) { // uses the amount of LEDs as fixture count
2223

2324
uint32_t in = strip.getPixelColor(i); // get the colors for the individual fixtures as suggested by Aircoookie in issue #462
2425
byte w = in >> 24 & 0xFF;

wled00/e131.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
102102
// update status info
103103
realtimeIP = clientIP;
104104
byte wChannel = 0;
105+
uint16_t totalLen = strip.getLengthTotal();
105106

106107
switch (DMXMode) {
107108
case DMX_MODE_DISABLED:
@@ -114,7 +115,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
114115
realtimeLock(realtimeTimeoutMs, mde);
115116
if (realtimeOverride) return;
116117
wChannel = (dmxChannels-DMXAddress+1 > 3) ? e131_data[DMXAddress+3] : 0;
117-
for (uint16_t i = 0; i < ledCount; i++)
118+
for (uint16_t i = 0; i < totalLen; i++)
118119
setRealtimePixel(i, e131_data[DMXAddress+0], e131_data[DMXAddress+1], e131_data[DMXAddress+2], wChannel);
119120
break;
120121

@@ -129,7 +130,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
129130
bri = e131_data[DMXAddress+0];
130131
strip.setBrightness(bri);
131132
}
132-
for (uint16_t i = 0; i < ledCount; i++)
133+
for (uint16_t i = 0; i < totalLen; i++)
133134
setRealtimePixel(i, e131_data[DMXAddress+1], e131_data[DMXAddress+2], e131_data[DMXAddress+3], wChannel);
134135
break;
135136

wled00/json.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ void serializeInfo(JsonObject root)
490490
//root[F("cn")] = WLED_CODENAME;
491491

492492
JsonObject leds = root.createNestedObject("leds");
493-
leds[F("count")] = ledCount;
493+
leds[F("count")] = strip.getLengthTotal();
494494
leds[F("rgbw")] = strip.isRgbw;
495495
leds[F("wv")] = strip.isRgbw && (strip.rgbwMode == RGBW_MODE_MANUAL_ONLY || strip.rgbwMode == RGBW_MODE_DUAL); //should a white channel slider be displayed?
496496
leds[F("pwr")] = strip.currentMilliamps;
@@ -853,7 +853,7 @@ bool serveLiveLeds(AsyncWebServerRequest* request, uint32_t wsClient)
853853
#endif
854854
}
855855

856-
uint16_t used = ledCount;
856+
uint16_t used = strip.getLengthTotal();
857857
uint16_t n = (used -1) /MAX_LIVE_LEDS +1; //only serve every n'th LED if count over MAX_LIVE_LEDS
858858
char buffer[2000];
859859
strcpy_P(buffer, PSTR("{\"leds\":["));

wled00/udp.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ void notify(byte callMode, bool followUp)
9292
void realtimeLock(uint32_t timeoutMs, byte md)
9393
{
9494
if (!realtimeMode && !realtimeOverride){
95-
for (uint16_t i = 0; i < ledCount; i++)
95+
uint16_t totalLen = strip.getLengthTotal();
96+
for (uint16_t i = 0; i < totalLen; i++)
9697
{
9798
strip.setPixelColor(i,0,0,0,0);
9899
}
@@ -168,10 +169,11 @@ void handleNotifications()
168169
realtimeLock(realtimeTimeoutMs, REALTIME_MODE_HYPERION);
169170
if (realtimeOverride) return;
170171
uint16_t id = 0;
172+
uint16_t totalLen = strip.getLengthTotal();
171173
for (uint16_t i = 0; i < packetSize -2; i += 3)
172174
{
173175
setRealtimePixel(id, lbuf[i], lbuf[i+1], lbuf[i+2], 0);
174-
id++; if (id >= ledCount) break;
176+
id++; if (id >= totalLen) break;
175177
}
176178
strip.show();
177179
return;
@@ -339,9 +341,10 @@ void handleNotifications()
339341
byte numPackets = udpIn[5];
340342

341343
uint16_t id = (tpmPayloadFrameSize/3)*(packetNum-1); //start LED
344+
uint16_t totalLen = strip.getLengthTotal();
342345
for (uint16_t i = 6; i < tpmPayloadFrameSize + 4; i += 3)
343346
{
344-
if (id < ledCount)
347+
if (id < totalLen)
345348
{
346349
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0);
347350
id++;
@@ -372,6 +375,7 @@ void handleNotifications()
372375
}
373376
if (realtimeOverride) return;
374377

378+
uint16_t totalLen = strip.getLengthTotal();
375379
if (udpIn[0] == 1) //warls
376380
{
377381
for (uint16_t i = 2; i < packetSize -3; i += 4)
@@ -385,7 +389,7 @@ void handleNotifications()
385389
{
386390
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0);
387391

388-
id++; if (id >= ledCount) break;
392+
id++; if (id >= totalLen) break;
389393
}
390394
} else if (udpIn[0] == 3) //drgbw
391395
{
@@ -394,14 +398,14 @@ void handleNotifications()
394398
{
395399
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]);
396400

397-
id++; if (id >= ledCount) break;
401+
id++; if (id >= totalLen) break;
398402
}
399403
} else if (udpIn[0] == 4) //dnrgb
400404
{
401405
uint16_t id = ((udpIn[3] << 0) & 0xFF) + ((udpIn[2] << 8) & 0xFF00);
402406
for (uint16_t i = 4; i < packetSize -2; i += 3)
403407
{
404-
if (id >= ledCount) break;
408+
if (id >= totalLen) break;
405409
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0);
406410
id++;
407411
}
@@ -410,7 +414,7 @@ void handleNotifications()
410414
uint16_t id = ((udpIn[3] << 0) & 0xFF) + ((udpIn[2] << 8) & 0xFF00);
411415
for (uint16_t i = 4; i < packetSize -2; i += 4)
412416
{
413-
if (id >= ledCount) break;
417+
if (id >= totalLen) break;
414418
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]);
415419
id++;
416420
}
@@ -438,7 +442,7 @@ void handleNotifications()
438442
void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w)
439443
{
440444
uint16_t pix = i + arlsOffset;
441-
if (pix < ledCount)
445+
if (pix < strip.getLengthTotal())
442446
{
443447
if (!arlsDisableGammaCorrection && strip.gammaCorrectCol)
444448
{

wled00/wled.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,10 @@ void WLED::loop()
212212
bool aligned = strip.checkSegmentAlignment(); //see if old segments match old bus(ses)
213213
busses.removeAll();
214214
uint32_t mem = 0;
215-
ledCount = 1;
216215
for (uint8_t i = 0; i < WLED_MAX_BUSSES; i++) {
217216
if (busConfigs[i] == nullptr) break;
218217
mem += BusManager::memUsage(*busConfigs[i]);
219218
if (mem <= MAX_LED_MEMORY) {
220-
uint16_t totalNew = busConfigs[i]->start + busConfigs[i]->count;
221-
if (totalNew > ledCount && totalNew <= MAX_LEDS) ledCount = totalNew; //total is end of last bus (where start + len is max.)
222219
busses.add(*busConfigs[i]);
223220
}
224221
delete busConfigs[i]; busConfigs[i] = nullptr;

wled00/wled.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ WLED_GLOBAL bool noWifiSleep _INIT(false);
262262
#endif
263263

264264
// LED CONFIG
265-
WLED_GLOBAL uint16_t ledCount _INIT(DEFAULT_LED_COUNT); // overcurrent prevented by ABL
266265
WLED_GLOBAL bool turnOnAtBoot _INIT(true); // turn on LEDs at power-up
267266
WLED_GLOBAL byte bootPreset _INIT(0); // save preset to load after power-up
268267

0 commit comments

Comments
 (0)