kopia lustrzana https://github.com/Aircoookie/WLED
				
				
				
			Segment bounds sync option
							rodzic
							
								
									447b811fa0
								
							
						
					
					
						commit
						7aef551292
					
				| 
						 | 
				
			
			@ -261,6 +261,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
 | 
			
		|||
  CJSON(receiveNotificationEffects, if_sync_recv["fx"]);
 | 
			
		||||
  CJSON(receiveGroups, if_sync_recv["grp"]);
 | 
			
		||||
  CJSON(receiveSegmentOptions, if_sync_recv["seg"]);
 | 
			
		||||
  CJSON(receiveSegmentBounds, if_sync_recv["sb"]);
 | 
			
		||||
  //! following line might be a problem if called after boot
 | 
			
		||||
  receiveNotifications = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects || receiveSegmentOptions);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -676,6 +677,7 @@ void serializeConfig() {
 | 
			
		|||
  if_sync_recv["fx"]  = receiveNotificationEffects;
 | 
			
		||||
  if_sync_recv["grp"] = receiveGroups;
 | 
			
		||||
  if_sync_recv["seg"] = receiveSegmentOptions;
 | 
			
		||||
  if_sync_recv["sb"]  = receiveSegmentBounds;
 | 
			
		||||
 | 
			
		||||
  JsonObject if_sync_send = if_sync.createNestedObject("send");
 | 
			
		||||
  if_sync_send[F("dir")] = notifyDirect;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -83,7 +83,7 @@ UDP Port: <input name="UP" type="number" min="1" max="65535" class="d5" required
 | 
			
		|||
    </tr>
 | 
			
		||||
</table><br>
 | 
			
		||||
Receive: <input type="checkbox" name="RB"> Brightness, <input type="checkbox" name="RC"> Color, and <input type="checkbox" name="RX"> Effects<br>
 | 
			
		||||
<input type="checkbox" name="SO"> Segment options<br>
 | 
			
		||||
<input type="checkbox" name="SO"> Segment options, <input type="checkbox" name="SG"> bounds<br>
 | 
			
		||||
Send notifications on direct change: <input type="checkbox" name="SD"><br>
 | 
			
		||||
Send notifications on button press or IR: <input type="checkbox" name="SB"><br>
 | 
			
		||||
Send Alexa notifications: <input type="checkbox" name="SA"><br>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -85,7 +85,7 @@ charset="utf-8"><meta name="theme-color" content="#222222"><title>
 | 
			
		|||
WLED Live Preview</title><style>
 | 
			
		||||
body{margin:0}#canv{background:#000;filter:brightness(175%);width:100%;height:100%;position:absolute}
 | 
			
		||||
</style></head><body><div id="canv"><script>
 | 
			
		||||
function updatePreview(e){var n="linear-gradient(90deg,",t=e.length;for(i=2;i<t;i+=3)n+=`rgb(${e[i]},${e[i+1]},${e[i+2]})`,i<t-3&&(n+=",");n+=")",document.getElementById("canv").style.background=n}function getLiveJson(e){try{if(e.data instanceof ArrayBuffer||"[object ArrayBuffer]"===toString.call(e.data)){let e=new Uint8Array(event.data);if(76!=e[0])return;updatePreview(e)}}catch(e){console.error("Peek WS error:",e)}}var ws=top.window.ws;ws&&ws.readyState===WebSocket.OPEN?(console.info("Peek uses top WS"),ws.send("{'lv':true}")):(console.info("Peek WS opening"),(ws=new WebSocket("ws://"+document.location.host+"/ws")).onopen=function(){console.info("Peek WS open"),ws.send("{'lv':true}")}),ws.binaryType="arraybuffer",ws.addEventListener("message",getLiveJson)
 | 
			
		||||
function updatePreview(e){var n="linear-gradient(90deg,",t=e.length;for(i=2;i<t;i+=3)n+=`rgb(${e[i]},${e[i+1]},${e[i+2]})`,i<t-3&&(n+=",");n+=")",document.getElementById("canv").style.background=n}function getLiveJson(e){try{if("[object ArrayBuffer]"===toString.call(e.data)){let e=new Uint8Array(event.data);if(76!=e[0])return;updatePreview(e)}}catch(e){console.error("Peek WS error:",e)}}var ws=top.window.ws;ws&&ws.readyState===WebSocket.OPEN?(console.info("Peek uses top WS"),ws.send("{'lv':true}")):(console.info("Peek WS opening"),(ws=new WebSocket("ws://"+document.location.host+"/ws")).onopen=function(){console.info("Peek WS open"),ws.send("{'lv':true}")}),ws.binaryType="arraybuffer",ws.addEventListener("message",getLiveJson)
 | 
			
		||||
</script></body></html>)=====";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -276,9 +276,10 @@ type="checkbox" id="R7" name="R7"></td><td><input type="checkbox" id="R8"
 | 
			
		|||
name="R8"></td></tr></table><br>Receive: <input type="checkbox" name="RB">
 | 
			
		||||
 Brightness, <input type="checkbox" name="RC"> Color, and <input 
 | 
			
		||||
type="checkbox" name="RX"> Effects<br><input type="checkbox" name="SO">
 | 
			
		||||
 Segment options<br>Send notifications on direct change: <input type="checkbox" 
 | 
			
		||||
name="SD"><br>Send notifications on button press or IR: <input type="checkbox" 
 | 
			
		||||
name="SB"><br>Send Alexa notifications: <input type="checkbox" name="SA"><br>
 | 
			
		||||
 Segment options, <input type="checkbox" name="SG"> bounds<br>
 | 
			
		||||
Send notifications on direct change: <input type="checkbox" name="SD"><br>
 | 
			
		||||
Send notifications on button press or IR: <input type="checkbox" name="SB"><br>
 | 
			
		||||
Send Alexa notifications: <input type="checkbox" name="SA"><br>
 | 
			
		||||
Send Philips Hue change notifications: <input type="checkbox" name="SH"><br>
 | 
			
		||||
Send Macro notifications: <input type="checkbox" name="SM"><br>
 | 
			
		||||
Send notifications twice: <input type="checkbox" name="S2"><br><i>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -233,6 +233,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
 | 
			
		|||
    receiveNotificationColor = request->hasArg(F("RC"));
 | 
			
		||||
    receiveNotificationEffects = request->hasArg(F("RX"));
 | 
			
		||||
    receiveSegmentOptions = request->hasArg(F("SO"));
 | 
			
		||||
    receiveSegmentBounds = request->hasArg(F("SG"));
 | 
			
		||||
    receiveNotifications = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects || receiveSegmentOptions);
 | 
			
		||||
    notifyDirectDefault = request->hasArg(F("SD"));
 | 
			
		||||
    notifyDirect = notifyDirectDefault;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -322,16 +322,20 @@ void handleNotifications()
 | 
			
		|||
    if (version < 200)
 | 
			
		||||
    {
 | 
			
		||||
      if (applyEffects && currentPlaylist >= 0) unloadPlaylist();
 | 
			
		||||
      if (version > 10 && receiveSegmentOptions) {
 | 
			
		||||
        //does not sync start & stop
 | 
			
		||||
        uint8_t srcSegs = udpIn[39];
 | 
			
		||||
        //if (srcSegs > strip.getMaxSegments()) srcSegs = strip.getMaxSegments();
 | 
			
		||||
        for (uint8_t i = 0; i < srcSegs; i++) {
 | 
			
		||||
      if (version > 10 && (receiveSegmentOptions || receiveSegmentBounds)) {
 | 
			
		||||
        uint8_t numSrcSegs = udpIn[39];
 | 
			
		||||
        for (uint8_t i = 0; i < numSrcSegs; i++) {
 | 
			
		||||
          uint16_t ofs = 41 + i*udpIn[40]; //start of segment offset byte
 | 
			
		||||
          uint8_t id = udpIn[0 +ofs];
 | 
			
		||||
          if (id > strip.getMaxSegments()) continue;
 | 
			
		||||
          WS2812FX::Segment& selseg = strip.getSegment(id);
 | 
			
		||||
          //bytes 1+2 contain start, 3+4 stop, unused at this time
 | 
			
		||||
          uint16_t start  = (udpIn[1+ofs] << 8 | udpIn[2+ofs]);
 | 
			
		||||
          uint16_t stop   = (udpIn[3+ofs] << 8 | udpIn[4+ofs]);
 | 
			
		||||
          uint16_t offset = (udpIn[7+ofs] << 8 | udpIn[8+ofs]);
 | 
			
		||||
          if (!receiveSegmentOptions) {
 | 
			
		||||
            strip.setSegment(id, start, stop, selseg.grouping, selseg.spacing, offset);
 | 
			
		||||
            continue;
 | 
			
		||||
          }
 | 
			
		||||
          for (uint8_t j = 0; j<4; j++) selseg.setOption(j, (udpIn[9 +ofs] >> j) & 0x01); //only take into account mirrored, selected, on, reversed
 | 
			
		||||
          selseg.setOpacity(udpIn[10+ofs], id);
 | 
			
		||||
          if (applyEffects) {
 | 
			
		||||
| 
						 | 
				
			
			@ -346,12 +350,19 @@ void handleNotifications()
 | 
			
		|||
            selseg.setColor(2, RGBW32(udpIn[23+ofs],udpIn[24+ofs],udpIn[25+ofs],udpIn[26+ofs]), id);
 | 
			
		||||
            selseg.setCCT(udpIn[27+ofs], id);
 | 
			
		||||
          }
 | 
			
		||||
          strip.setSegment(id, selseg.start, selseg.stop, udpIn[5+ofs], udpIn[6+ofs], (udpIn[7+ofs]<<8 | udpIn[8+ofs])); //also properly resets segments
 | 
			
		||||
          //setSegment() also properly resets segments
 | 
			
		||||
          if (receiveSegmentBounds) {
 | 
			
		||||
            strip.setSegment(id, start, stop, udpIn[5+ofs], udpIn[6+ofs], offset);
 | 
			
		||||
          } else {
 | 
			
		||||
            strip.setSegment(id, selseg.start, selseg.stop, udpIn[5+ofs], udpIn[6+ofs], selseg.offset);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        setValuesFromMainSeg();
 | 
			
		||||
        effectChanged = true;
 | 
			
		||||
        colorChanged = true;
 | 
			
		||||
      } else if (applyEffects) { //simple effect sync, applies to all selected
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      if (applyEffects && (version < 11 || !receiveSegmentOptions)) { //simple effect sync, applies to all selected
 | 
			
		||||
        if (udpIn[8] < strip.getModeCount()) effectCurrent = udpIn[8];
 | 
			
		||||
        effectSpeed   = udpIn[9];
 | 
			
		||||
        if (version > 2) effectIntensity = udpIn[16];
 | 
			
		||||
| 
						 | 
				
			
			@ -400,6 +411,7 @@ void handleNotifications()
 | 
			
		|||
    if (nightlightActive) nightlightDelayMins = udpIn[7];
 | 
			
		||||
    
 | 
			
		||||
    if (receiveNotificationBrightness || !someSel) bri = udpIn[2];
 | 
			
		||||
    strip.applyToAllSelected = !(version > 10 && receiveSegmentOptions);
 | 
			
		||||
    colorUpdated(CALL_MODE_NOTIFICATION);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -315,6 +315,7 @@ WLED_GLOBAL bool receiveNotificationBrightness _INIT(true);       // apply brigh
 | 
			
		|||
WLED_GLOBAL bool receiveNotificationColor      _INIT(true);       // apply color
 | 
			
		||||
WLED_GLOBAL bool receiveNotificationEffects    _INIT(true);       // apply effects setup
 | 
			
		||||
WLED_GLOBAL bool receiveSegmentOptions         _INIT(false);      // apply segment options
 | 
			
		||||
WLED_GLOBAL bool receiveSegmentBounds          _INIT(false);      // apply segment bounds (start, stop, offset)
 | 
			
		||||
WLED_GLOBAL bool notifyDirect _INIT(false);                       // send notification if change via UI or HTTP API
 | 
			
		||||
WLED_GLOBAL bool notifyButton _INIT(false);                       // send if updated by button or infrared remote
 | 
			
		||||
WLED_GLOBAL bool notifyAlexa  _INIT(false);                       // send notification if updated via Alexa
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -480,6 +480,7 @@ void getSettingsJS(byte subPage, char* dest)
 | 
			
		|||
    sappend('c',SET_F("RC"),receiveNotificationColor);
 | 
			
		||||
    sappend('c',SET_F("RX"),receiveNotificationEffects);
 | 
			
		||||
    sappend('c',SET_F("SO"),receiveSegmentOptions);
 | 
			
		||||
    sappend('c',SET_F("SG"),receiveSegmentBounds);
 | 
			
		||||
    sappend('c',SET_F("SD"),notifyDirectDefault);
 | 
			
		||||
    sappend('c',SET_F("SB"),notifyButton);
 | 
			
		||||
    sappend('c',SET_F("SH"),notifyHue);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue