Skip to content

Commit 4865ddb

Browse files
committed
Fix realtime mode disabled by brightness change
Fix realtime mode not working immediately at turn on Fix individual segment control not working immediately at turn on
1 parent a556732 commit 4865ddb

File tree

6 files changed

+34
-16
lines changed

6 files changed

+34
-16
lines changed

wled00/FX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ class WS2812FX {
625625
setColor(uint8_t slot, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0),
626626
setColor(uint8_t slot, uint32_t c),
627627
setCCT(uint16_t k),
628-
setBrightness(uint8_t b),
628+
setBrightness(uint8_t b, bool direct = false),
629629
setRange(uint16_t i, uint16_t i2, uint32_t col),
630630
setShowCallback(show_callback cb),
631631
setTransition(uint16_t t),

wled00/FX_fcn.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ void WS2812FX::service() {
133133

134134
if (!SEGMENT.isActive()) continue;
135135

136-
if(nowUp > SEGENV.next_time || _triggered || (doShow && SEGMENT.mode == 0)) //last is temporary
136+
// last condition ensures all solid segments are updated at the same time
137+
if(nowUp > SEGENV.next_time || _triggered || (doShow && SEGMENT.mode == 0))
137138
{
138139
if (SEGMENT.grouping == 0) SEGMENT.grouping = 1; //sanity check
139140
doShow = true;
@@ -426,7 +427,7 @@ void WS2812FX::setCCT(uint16_t k) {
426427
}
427428
}
428429

429-
void WS2812FX::setBrightness(uint8_t b) {
430+
void WS2812FX::setBrightness(uint8_t b, bool direct) {
430431
if (gammaCorrectBri) b = gamma8(b);
431432
if (_brightness == b) return;
432433
_brightness = b;
@@ -436,8 +437,13 @@ void WS2812FX::setBrightness(uint8_t b) {
436437
_segments[i].setOption(SEG_OPTION_FREEZE, false);
437438
}
438439
}
439-
unsigned long t = millis();
440-
if (_segment_runtimes[0].next_time > t + 22 && t - _lastShow > MIN_SHOW_DELAY) show(); //apply brightness change immediately if no refresh soon
440+
if (direct) {
441+
// would be dangerous if applied immediately (could exceed ABL), but will not output until the next show()
442+
busses.setBrightness(b);
443+
} else {
444+
unsigned long t = millis();
445+
if (_segment_runtimes[0].next_time > t + 22 && t - _lastShow > MIN_SHOW_DELAY) show(); //apply brightness change immediately if no refresh soon
446+
}
441447
}
442448

443449
uint8_t WS2812FX::getBrightness(void) {

wled00/e131.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
130130
if (DMXOldDimmer != e131_data[DMXAddress+0]) {
131131
DMXOldDimmer = e131_data[DMXAddress+0];
132132
bri = e131_data[DMXAddress+0];
133-
strip.setBrightness(bri);
133+
strip.setBrightness(bri, true);
134134
}
135135
for (uint16_t i = 0; i < totalLen; i++)
136136
setRealtimePixel(i, e131_data[DMXAddress+1], e131_data[DMXAddress+2], e131_data[DMXAddress+3], wChannel);
@@ -184,7 +184,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
184184
previousLeds = 0;
185185
// First DMX address is dimmer in DMX_MODE_MULTIPLE_DRGB mode.
186186
if (DMXMode == DMX_MODE_MULTIPLE_DRGB) {
187-
strip.setBrightness(e131_data[dmxOffset++]);
187+
strip.setBrightness(e131_data[dmxOffset++], true);
188188
}
189189
} else {
190190
// All subsequent universes start at the first channel.

wled00/json.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,12 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
177177
if (!iarr.isNull()) {
178178
uint8_t oldSegId = strip.setPixelSegment(id);
179179

180-
//freeze and init to black
180+
// set brightness immediately and disable transition
181+
transitionDelayTemp = 0;
182+
jsonTransitionOnce = true;
183+
strip.setBrightness(scaledBri(bri), true);
184+
185+
// freeze and init to black
181186
if (!seg.getOption(SEG_OPTION_FREEZE)) {
182187
seg.setOption(SEG_OPTION_FREEZE, true);
183188
strip.fill(0);
@@ -263,7 +268,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
263268
transitionDelayTemp *= 100;
264269
jsonTransitionOnce = true;
265270
}
266-
strip.setTransition(transitionDelayTemp);
271+
strip.setTransition(transitionDelayTemp); // required here for color transitions to have correct duration
267272

268273
tr = root[F("tb")] | -1;
269274
if (tr >= 0) strip.timebase = ((uint32_t)tr) - millis();
@@ -290,10 +295,16 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
290295
realtimeOverride = root[F("lor")] | realtimeOverride;
291296
if (realtimeOverride > 2) realtimeOverride = REALTIME_OVERRIDE_ALWAYS;
292297

298+
bool liveEnabled = false;
293299
if (root.containsKey("live")) {
294300
bool lv = root["live"];
295-
if (lv) realtimeLock(65000); //enter realtime without timeout
296-
else realtimeTimeout = 0; //cancel realtime mode immediately
301+
if (lv) {
302+
transitionDelayTemp = 0;
303+
jsonTransitionOnce = true;
304+
liveEnabled = true; // triggers realtimeLock() below
305+
realtimeLock(65000);
306+
}
307+
else realtimeTimeout = 0; //cancel realtime mode immediately
297308
}
298309

299310
strip.setMainSegmentId(root[F("mainseg")] | strip.getMainSegmentId());
@@ -370,6 +381,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
370381
}
371382

372383
stateUpdated(callMode);
384+
if (liveEnabled) realtimeTimeout = UINT32_MAX; // force indefinite timeout if this request contained {"live":true}
373385

374386
return stateResponse;
375387
}

wled00/udp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ void realtimeLock(uint32_t timeoutMs, byte md)
153153
if (timeoutMs == 255001 || timeoutMs == 65000) realtimeTimeout = UINT32_MAX;
154154
}
155155
// if strip is off (bri==0) and not already in RTM
156-
if (bri == 0 && !realtimeMode) {
157-
strip.setBrightness(scaledBri(briLast));
156+
if (briT == 0 && !realtimeMode) {
157+
strip.setBrightness(scaledBri(briLast), true);
158158
}
159159
realtimeMode = md;
160160

161-
if (arlsForceMaxBri && !realtimeOverride) strip.setBrightness(scaledBri(255));
162-
if (md == REALTIME_MODE_GENERIC) strip.show();
161+
if (arlsForceMaxBri && !realtimeOverride) strip.setBrightness(scaledBri(255), true);
162+
if (briT > 0 && md == REALTIME_MODE_GENERIC) strip.show();
163163
}
164164

165165

wled00/wled_serial.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void handleSerial()
174174
if (!realtimeOverride) setRealtimePixel(pixel++, red, green, blue, 0);
175175
if (--count > 0) state = AdaState::Data_Red;
176176
else {
177-
if (!realtimeMode && bri == 0) strip.setBrightness(briLast);
177+
if (!realtimeMode && bri == 0) strip.setBrightness(briLast, true);
178178
realtimeLock(realtimeTimeoutMs, REALTIME_MODE_ADALIGHT);
179179

180180
if (!realtimeOverride) strip.show();

0 commit comments

Comments
 (0)