Skip to content

Commit a0ed79b

Browse files
committed
Refactor: put max channels per fixture in a define
1 parent b4d976d commit a0ed79b

File tree

7 files changed

+18
-14
lines changed

7 files changed

+18
-14
lines changed

wled00/cfg.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,12 +751,12 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
751751
CJSON(DMXStartLED,dmx[F("start-led")]);
752752

753753
JsonArray dmx_fixmap = dmx[F("fixmap")];
754-
for (int i = 0; i < MIN(dmx_fixmap.size(), 15); i++) {
754+
for (int i = 0; i < MIN(dmx_fixmap.size(), MAX_CHANNELS_PER_FIXTURE); i++) {
755755
CJSON(DMXFixtureMap[i],dmx_fixmap[i]);
756756
}
757757

758758
JsonArray dmx_chsval = dmx[F("chsval")];
759-
for (int i = 0; i < MIN(dmx_chsval.size(), 15); i++) {
759+
for (int i = 0; i < MIN(dmx_chsval.size(), MAX_CHANNELS_PER_FIXTURE); i++) {
760760
CJSON(DMXChannelsValue[i],dmx_chsval[i]);
761761
}
762762

@@ -1257,12 +1257,12 @@ void serializeConfig(JsonObject root) {
12571257
dmx[F("start-led")] = DMXStartLED;
12581258

12591259
JsonArray dmx_fixmap = dmx.createNestedArray(F("fixmap"));
1260-
for (unsigned i = 0; i < 15; i++) {
1260+
for (unsigned i = 0; i < MAX_CHANNELS_PER_FIXTURE; i++) {
12611261
dmx_fixmap.add(DMXFixtureMap[i]);
12621262
}
12631263

12641264
JsonArray dmx_chsval = dmx.createNestedArray(F("chsval"));
1265-
for (unsigned i = 0; i < 15; i++) {
1265+
for (unsigned i = 0; i < MAX_CHANNELS_PER_FIXTURE; i++) {
12661266
dmx_chsval.add(DMXChannelsValue[i]);
12671267
}
12681268

wled00/const.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,4 +655,8 @@ static_assert(WLED_MAX_BUSSES <= 32, "WLED_MAX_BUSSES exceeds hard limit");
655655
#define IRAM_ATTR_YN IRAM_ATTR
656656
#endif
657657

658+
#ifdef WLED_ENABLE_DMX
659+
#define MAX_CHANNELS_PER_FIXTURE 15
660+
#endif
661+
658662
#endif

wled00/set.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,12 +640,12 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
640640
if (t>=0 && t < MAX_LEDS) {
641641
DMXStartLED = t;
642642
}
643-
for (int i=0; i<15; i++) {
643+
for (int i=0; i<MAX_CHANNELS_PER_FIXTURE; i++) {
644644
String argname = "CH" + String((i+1));
645645
t = request->arg(argname).toInt();
646646
DMXFixtureMap[i] = t;
647647
}
648-
for (int i=0; i<15; i++) {
648+
for (int i=0; i<MAX_CHANNELS_PER_FIXTURE; i++) {
649649
String argname = "DV" + String((i+1));
650650
t = request->arg(argname).toInt();
651651
DMXChannelsValue[i] = t;

wled00/wled.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ WLED_GLOBAL bool arlsForceMaxBri _INIT(false); // enable to f
473473
WLED_GLOBAL uint16_t e131ProxyUniverse _INIT(0); // output this E1.31 (sACN) / ArtNet universe via MAX485 (0 = disabled)
474474
// dmx CONFIG
475475
WLED_GLOBAL byte DMXChannels _INIT(7); // number of channels per fixture
476-
WLED_GLOBAL byte DMXFixtureMap[15] _INIT_N(({ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }));
477-
WLED_GLOBAL byte DMXChannelsValue[15] _INIT_N(({ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }));
476+
WLED_GLOBAL byte DMXFixtureMap[MAX_CHANNELS_PER_FIXTURE] _INIT_N(({ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }));
477+
WLED_GLOBAL byte DMXChannelsValue[MAX_CHANNELS_PER_FIXTURE] _INIT_N(({ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }));
478478
// assigns the different channels to different functions. See wled21_dmx.ino for more information.
479479
WLED_GLOBAL uint16_t DMXGap _INIT(10); // gap between the fixtures. makes addressing easier because you don't have to memorize odd numbers when climbing up onto a rig.
480480
WLED_GLOBAL uint16_t DMXStart _INIT(10); // start address of the first fixture

wled00/wled_eeprom.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,10 @@ void loadSettingsFromEEPROM()
348348
DMXGap = EEPROM.read(2531) + ((EEPROM.read(2532) << 8) & 0xFF00);
349349
DMXStart = EEPROM.read(2533) + ((EEPROM.read(2534) << 8) & 0xFF00);
350350

351-
for (int i=0;i<15;i++) {
351+
for (int i=0;i<MAX_CHANNELS_PER_FIXTURE;i++) {
352352
DMXFixtureMap[i] = EEPROM.read(2535+i);
353353
} //last used: 2549
354-
for (int i=0;i<15;i++) {
354+
for (int i=0;i<MAX_CHANNELS_PER_FIXTURE;i++) {
355355
DMXChannelsValue[i] = EEPROM.read(2550+i);
356356
} //last used: 2564
357357
DMXStartLED = EEPROM.read(2565);

wled00/wled_server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ static String dmxProcessor(const String& var)
134134
mapJS += F(";\nLC=");
135135
mapJS += String(strip.getLengthTotal());
136136
mapJS += F(";\nvar CH=[");
137-
for (int i=0; i<15; i++) {
137+
for (int i=0; i<MAX_CHANNELS_PER_FIXTURE; i++) {
138138
mapJS += String(DMXFixtureMap[i]) + ',';
139139
}
140140
mapJS += F("0];");
141141
mapJS += F(";\nvar DV=[");
142-
for (int i=0; i<15; i++) {
142+
for (int i=0; i<MAX_CHANNELS_PER_FIXTURE; i++) {
143143
mapJS += String(DMXChannelsValue[i]) + ',';
144144
}
145145
mapJS += F("0];");

wled00/xml.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,13 +634,13 @@ void getSettingsJS(byte subPage, Print& settingsScript)
634634
printSetFormValue(settingsScript,PSTR("CS"),DMXStart);
635635
printSetFormValue(settingsScript,PSTR("SL"),DMXStartLED);
636636

637-
for (int i = 0; i < 15; i++) {
637+
for (int i = 0; i < MAX_CHANNELS_PER_FIXTURE; i++) {
638638
char buf[5];
639639
snprintf_P(buf, sizeof(buf), PSTR("CH%d"), i+1);
640640
printSetFormIndex(settingsScript,buf,DMXFixtureMap[i]);
641641
}
642642

643-
for (int i = 0; i < 15; i++) {
643+
for (int i = 0; i < MAX_CHANNELS_PER_FIXTURE; i++) {
644644
char buf[5];
645645
snprintf_P(buf, sizeof(buf), PSTR("DV%d"), i+1);
646646
printSetFormValue(settingsScript,buf,DMXChannelsValue[i]);

0 commit comments

Comments
 (0)