@@ -84,11 +84,12 @@ void stateUpdated(byte callMode) {
8484 // 6: fx changed 7: hue 8: preset cycle 9: blynk 10: alexa 11: ws send only 12: button preset
8585 setValuesFromFirstSelectedSeg (); // a much better approach would be to use main segment: setValuesFromMainSeg()
8686
87- if (bri != briOld || stateChanged) {
87+ // notifications
88+ if (bri != briOld || stateChanged) { // bri != briOld must be checked since changing brightness does not always set stateChanged
8889 if (stateChanged) currentPreset = 0 ; // something changed, so we are no longer in the preset
8990
9091 if (callMode != CALL_MODE_NOTIFICATION && callMode != CALL_MODE_NO_NOTIFY) notify (callMode);
91- if (bri != briOld && nodeBroadcastEnabled) sendSysInfoUDP (); // update on state
92+ if (bri != briOld && nodeBroadcastEnabled) sendSysInfoUDP (); // update "on" state
9293
9394 // set flag to update ws and mqtt
9495 interfaceUpdateCallMode = callMode;
@@ -99,21 +100,25 @@ void stateUpdated(byte callMode) {
99100 }
100101 }
101102
103+ // nightlight
102104 unsigned long now = millis ();
103- if (callMode != CALL_MODE_NO_NOTIFY && nightlightActive && (nightlightMode == NL_MODE_FADE || nightlightMode == NL_MODE_COLORFADE)) {
104- briNlT = bri;
105- nightlightDelayMs -= (now - nightlightStartTime);
106- nightlightStartTime = now;
105+ if (nightlightActive && callMode != CALL_MODE_NO_NOTIFY) {
106+ if (nightlightMode == NL_MODE_FADE || nightlightMode == NL_MODE_COLORFADE) {
107+ briNlT = bri;
108+ nightlightDelayMs -= (now - nightlightStartTime);
109+ nightlightStartTime = now;
110+ }
111+ // deactivate nightlight if target brightness is reached
112+ if (bri == nightlightTargetBri && nightlightMode != NL_MODE_SUN) nightlightActive = false ;
107113 }
114+
115+ // off
108116 if (briT == 0 ) {
109117 if (callMode != CALL_MODE_NOTIFICATION) strip.resetTimebase (); // effect start from beginning
110118 }
111119
112120 if (bri > 0 ) briLast = bri;
113121
114- // deactivate nightlight if target brightness is reached
115- if (bri == nightlightTargetBri && callMode != CALL_MODE_NO_NOTIFY && nightlightMode != NL_MODE_SUN) nightlightActive = false ;
116-
117122 // notify usermods of state change
118123 UsermodManager::onStateChange (callMode);
119124
@@ -128,11 +133,11 @@ void stateUpdated(byte callMode) {
128133 } else {
129134 if (transitionActive) {
130135 // already active, just update briOld to reflect current state (no further notifications sent during on/off fade)
131- briOld = briT;
132- } else {
133- // since not all effects are updated each frame we will need to force all segments into transtiton mode
134- // but we will do that after relay delay has passed
135- if (!rlyStartTime && (bri != briOld || stateChanged)) strip. setTransitionMode ( true ); // force all segments to transition mode
136+ briOld = briT; // briT is updated in handleOnOff()
137+ } else if (!rlyStartTime && (bri != briOld)) {
138+ // if relay is in idle state (!rlyStartTime) then we have change in brightness; start global brightness transition (may be to "off")
139+ // if relay is not in idle state (rlyStartTime>0) then we have an global "off" to "on" transition and LEDs start
140+ // with a delay (this delay is handled in handleOnOff())
136141 transitionActive = true ;
137142 transitionStartTime = now;
138143 }
@@ -165,6 +170,7 @@ void updateInterfaces(uint8_t callMode) {
165170// legacy method, applies values from col, effectCurrent, ... to selected segments
166171void colorUpdated (byte callMode) {
167172 applyValuesToSelectedSegs ();
173+ if (callMode != CALL_MODE_NO_NOTIFY && callMode != CALL_MODE_INIT) stateChanged = true ;
168174 stateUpdated (callMode);
169175}
170176
0 commit comments