Skip to content

Commit c24ab1b

Browse files
authored
Auto create segments setting (wled#2183)
1 parent 6a01658 commit c24ab1b

File tree

11 files changed

+72
-31
lines changed

11 files changed

+72
-31
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
### Builds after release 0.12.0
44

5+
#### Build 2109100
6+
7+
- Added an auto create segments per bus setting
8+
- Added 15 new palettes from SR branch (PR #2134)
9+
- Fixed segment runtime not reset on FX change via HTTP API
10+
- Changed AsyncTCP dependency to pbolduc fork v1.2.0
11+
512
#### Build 2108250
613

714
- Added Sync groups (PR #2150)

platformio.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ build_flags = -g
210210
lib_deps =
211211
${env.lib_deps}
212212
makuna/NeoPixelBus @ 2.6.7
213-
https://github.com/pbolduc/AsyncTCP.git
213+
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
214214

215215
[esp32s2]
216216
build_flags = -g
@@ -224,7 +224,7 @@ build_flags = -g
224224
lib_deps =
225225
${env.lib_deps}
226226
makuna/NeoPixelBus @ 2.6.7
227-
https://github.com/pbolduc/AsyncTCP.git
227+
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
228228

229229
# ------------------------------------------------------------------------------
230230
# WLED BUILDS

wled00/FX_fcn.cpp

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,25 @@ void WS2812FX::finalizeInit(uint16_t countPixels)
9898
setBrightness(_brightness);
9999

100100
//TODO make sure segments are only refreshed when bus config actually changed (new settings page)
101-
//make one segment per bus
102101
uint8_t s = 0;
103102
for (uint8_t i = 0; i < busses.getNumBusses(); i++) {
104103
Bus* b = busses.getBus(i);
105104

106-
segStarts[s] = b->getStart();
107-
segStops[s] = segStarts[s] + b->getLength();
108-
109-
//check for overlap with previous segments
110-
for (uint8_t j = 0; j < s; j++) {
111-
if (segStops[j] > segStarts[s] && segStarts[j] < segStops[s]) {
112-
//segments overlap, merge
113-
segStarts[j] = min(segStarts[s],segStarts[j]);
114-
segStops [j] = max(segStops [s],segStops [j]); segStops[s] = 0;
115-
s--;
105+
if (autoSegments) { //make one segment per bus
106+
segStarts[s] = b->getStart();
107+
segStops[s] = segStarts[s] + b->getLength();
108+
109+
//check for overlap with previous segments
110+
for (uint8_t j = 0; j < s; j++) {
111+
if (segStops[j] > segStarts[s] && segStarts[j] < segStops[s]) {
112+
//segments overlap, merge
113+
segStarts[j] = min(segStarts[s],segStarts[j]);
114+
segStops [j] = max(segStops [s],segStops [j]); segStops[s] = 0;
115+
s--;
116+
}
116117
}
118+
s++;
117119
}
118-
s++;
119120

120121
#ifdef ESP8266
121122
if ((!IS_DIGITAL(b->getType()) || IS_2PIN(b->getType()))) continue;
@@ -126,9 +127,29 @@ void WS2812FX::finalizeInit(uint16_t countPixels)
126127
#endif
127128
}
128129

129-
for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) {
130-
_segments[i].start = segStarts[i];
131-
_segments[i].stop = segStops [i];
130+
if (autoSegments) {
131+
for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) {
132+
_segments[i].start = segStarts[i];
133+
_segments[i].stop = segStops [i];
134+
}
135+
} else {
136+
//expand the main seg to the entire length, but only if there are no other segments
137+
uint8_t mainSeg = getMainSegmentId();
138+
bool isMultipleSegs = false;
139+
for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++)
140+
{
141+
if (i != mainSeg && _segments[i].isActive()) isMultipleSegs = true;
142+
}
143+
if (!isMultipleSegs) {
144+
_segments[mainSeg].start = 0; _segments[mainSeg].stop = _length;
145+
} else {
146+
//there are multiple segments, leave them, but prune length to total
147+
for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++)
148+
{
149+
if (_segments[i].start > _length) _segments[i].stop = 0;
150+
if (_segments[i].stop > _length) _segments[i].stop = _length;
151+
}
152+
}
132153
}
133154
}
134155

wled00/cfg.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
202202
JsonObject light = doc[F("light")];
203203
CJSON(briMultiplier, light[F("scale-bri")]);
204204
CJSON(strip.paletteBlend, light[F("pal-mode")]);
205+
CJSON(autoSegments, light[F("aseg")]);
205206

206207
float light_gc_bri = light["gc"]["bri"];
207208
float light_gc_col = light["gc"]["col"]; // 2.8
@@ -565,6 +566,7 @@ void serializeConfig() {
565566
JsonObject light = doc.createNestedObject(F("light"));
566567
light[F("scale-bri")] = briMultiplier;
567568
light[F("pal-mode")] = strip.paletteBlend;
569+
light[F("aseg")] = autoSegments;
568570

569571
JsonObject light_gc = light.createNestedObject("gc");
570572
light_gc["bri"] = (strip.gammaCorrectBri) ? 2.8 : 1.0;

wled00/data/settings_leds.htm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,9 @@ <h3>Hardware setup</h3>
369369
<div id="ledwarning" style="color: orange; display: none;">
370370
&#9888; You might run into stability or lag issues.<br>
371371
Use less than <span id="wreason">800 LEDs per pin</span> for the best experience!<br>
372-
</div><hr style="width:260px">
372+
</div>
373+
Make a segment for each output: <input type="checkbox" name="MS"> <br>
374+
<hr style="width:260px">
373375
<div id="btns"></div>
374376
Touch threshold: <input type="number" class="s" min="0" max="100" name="TT" required><br>
375377
IR pin: <input type="number" class="xs" min="-1" max="40" name="IR" onchange="UI()">&nbsp;<select name="IT" onchange="UI()">

wled00/html_settings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ id="dbar"
113113
style="display:inline-block;width:100px;height:10px;border-radius:20px"></div>
114114
<br><div id="ledwarning" style="color:orange;display:none">
115115
&#9888; You might run into stability or lag issues.<br>Use less than <span
116-
id="wreason">800 LEDs per pin</span> for the best experience!<br></div><hr
116+
id="wreason">800 LEDs per pin</span> for the best experience!<br></div>
117+
Make a segment for each output: <input type="checkbox" name="MS"><br><hr
117118
style="width:260px"><div id="btns"></div>Touch threshold: <input type="number"
118119
class="s" min="0" max="100" name="TT" required><br>IR pin: <input type="number"
119120
class="xs" min="-1" max="40" name="IR" onchange="UI()">&nbsp;<select name="IT"

wled00/hue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void onHueData(void* arg, AsyncClient* client, void *data, size_t len)
119119
const char* apikey = root[0][F("success")][F("username")];
120120
if (apikey != nullptr && strlen(apikey) < sizeof(hueApiKey))
121121
{
122-
strcpy(hueApiKey, apikey);
122+
strlcpy(hueApiKey, apikey, sizeof(hueApiKey));
123123
hueAuthRequired = false;
124124
hueNewKey = true;
125125
}

wled00/mqtt.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ void onMqttConnect(bool sessionPresent)
2626
char subuf[38];
2727

2828
if (mqttDeviceTopic[0] != 0) {
29-
strcpy(subuf, mqttDeviceTopic);
29+
strlcpy(subuf, mqttDeviceTopic, 33);
3030
mqtt->subscribe(subuf, 0);
3131
strcat_P(subuf, PSTR("/col"));
3232
mqtt->subscribe(subuf, 0);
33-
strcpy(subuf, mqttDeviceTopic);
33+
strlcpy(subuf, mqttDeviceTopic, 33);
3434
strcat_P(subuf, PSTR("/api"));
3535
mqtt->subscribe(subuf, 0);
3636
}
3737

3838
if (mqttGroupTopic[0] != 0) {
39-
strcpy(subuf, mqttGroupTopic);
39+
strlcpy(subuf, mqttGroupTopic, 33);
4040
mqtt->subscribe(subuf, 0);
4141
strcat_P(subuf, PSTR("/col"));
4242
mqtt->subscribe(subuf, 0);
43-
strcpy(subuf, mqttGroupTopic);
43+
strlcpy(subuf, mqttGroupTopic, 33);
4444
strcat_P(subuf, PSTR("/api"));
4545
mqtt->subscribe(subuf, 0);
4646
}
@@ -122,22 +122,22 @@ void publishMqtt()
122122
char subuf[38];
123123

124124
sprintf_P(s, PSTR("%u"), bri);
125-
strcpy(subuf, mqttDeviceTopic);
125+
strlcpy(subuf, mqttDeviceTopic, 33);
126126
strcat_P(subuf, PSTR("/g"));
127127
mqtt->publish(subuf, 0, true, s);
128128

129129
sprintf_P(s, PSTR("#%06X"), (col[3] << 24) | (col[0] << 16) | (col[1] << 8) | (col[2]));
130-
strcpy(subuf, mqttDeviceTopic);
130+
strlcpy(subuf, mqttDeviceTopic, 33);
131131
strcat_P(subuf, PSTR("/c"));
132132
mqtt->publish(subuf, 0, true, s);
133133

134-
strcpy(subuf, mqttDeviceTopic);
134+
strlcpy(subuf, mqttDeviceTopic, 33);
135135
strcat_P(subuf, PSTR("/status"));
136136
mqtt->publish(subuf, 0, true, "online");
137137

138138
char apires[1024];
139139
XML_response(nullptr, apires);
140-
strcpy(subuf, mqttDeviceTopic);
140+
strlcpy(subuf, mqttDeviceTopic, 33);
141141
strcat_P(subuf, PSTR("/v"));
142142
mqtt->publish(subuf, 0, false, apires);
143143
}
@@ -167,7 +167,7 @@ bool initMqtt()
167167
mqtt->setClientId(mqttClientID);
168168
if (mqttUser[0] && mqttPass[0]) mqtt->setCredentials(mqttUser, mqttPass);
169169

170-
strcpy(mqttStatusTopic, mqttDeviceTopic);
170+
strlcpy(mqttStatusTopic, mqttDeviceTopic, 33);
171171
strcat_P(mqttStatusTopic, PSTR("/status"));
172172
mqtt->setWill(mqttStatusTopic, 0, true, "offline");
173173
mqtt->setKeepAlive(MQTT_KEEP_ALIVE_TIME);

wled00/set.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
9595
uint16_t length, start;
9696
uint8_t pins[5] = {255, 255, 255, 255, 255};
9797

98+
autoSegments = request->hasArg(F("MS"));
99+
98100
for (uint8_t s = 0; s < WLED_MAX_BUSSES; s++) {
99101
char lp[4] = "L0"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin
100102
char lc[4] = "LC"; lc[2] = 48+s; lc[3] = 0; //strip length
@@ -327,7 +329,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
327329
analogClockSecondsTrail = request->hasArg(F("OS"));
328330

329331
#ifndef WLED_DISABLE_CRONIXIE
330-
strcpy(cronixieDisplay,request->arg(F("CX")).c_str());
332+
strlcpy(cronixieDisplay,request->arg(F("CX")).c_str(),7);
331333
cronixieBacklight = request->hasArg(F("CB"));
332334
#endif
333335
countdownMode = request->hasArg(F("CE"));

wled00/wled.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// version code in format yymmddb (b = daily build)
11-
#define VERSION 2108250
11+
#define VERSION 2109100
1212

1313
//uncomment this if you have a "my_config.h" file you'd like to use
1414
//#define WLED_USE_MY_CONFIG
@@ -267,6 +267,11 @@ WLED_GLOBAL uint16_t ledCount _INIT(DEFAULT_LED_COUNT); // overcurrent prevent
267267
WLED_GLOBAL bool turnOnAtBoot _INIT(true); // turn on LEDs at power-up
268268
WLED_GLOBAL byte bootPreset _INIT(0); // save preset to load after power-up
269269

270+
//if true, a segment per bus will be created on boot and LED settings save
271+
//if false, only one segment spanning the total LEDs is created,
272+
//but not on LED settings save if there is more than one segment currently
273+
WLED_GLOBAL bool autoSegments _INIT(false);
274+
270275
WLED_GLOBAL byte col[] _INIT_N(({ 255, 160, 0, 0 })); // current RGB(W) primary color. col[] should be updated if you want to change the color.
271276
WLED_GLOBAL byte colSec[] _INIT_N(({ 0, 0, 0, 0 })); // current RGB(W) secondary color
272277
WLED_GLOBAL byte briS _INIT(128); // default brightness

0 commit comments

Comments
 (0)