Sync groups (#2150)

* Added UDP sync groups.

* Shortened string.

* Changed sync default to group 1 only.

* Make packets with version < 9 group 1

* Send sync group options as bytes, parse in JS

Co-authored-by: cschwinne <dev.aircoookie@gmail.com>
This commit is contained in:
Blaž Kristan 2021-08-25 16:39:12 +02:00 committed by GitHub
parent 77c0ba990d
commit b481c13829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 123 additions and 22 deletions

View File

@ -240,6 +240,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
CJSON(receiveNotificationBrightness, if_sync_recv["bri"]); CJSON(receiveNotificationBrightness, if_sync_recv["bri"]);
CJSON(receiveNotificationColor, if_sync_recv["col"]); CJSON(receiveNotificationColor, if_sync_recv["col"]);
CJSON(receiveNotificationEffects, if_sync_recv["fx"]); CJSON(receiveNotificationEffects, if_sync_recv["fx"]);
CJSON(receiveGroups, if_sync_recv["grp"]);
//! following line might be a problem if called after boot //! following line might be a problem if called after boot
receiveNotifications = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects); receiveNotifications = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects);
@ -252,6 +253,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
CJSON(notifyHue, if_sync_send["hue"]); CJSON(notifyHue, if_sync_send["hue"]);
CJSON(notifyMacro, if_sync_send["macro"]); CJSON(notifyMacro, if_sync_send["macro"]);
CJSON(notifyTwice, if_sync_send[F("twice")]); CJSON(notifyTwice, if_sync_send[F("twice")]);
CJSON(syncGroups, if_sync_send["grp"]);
JsonObject if_nodes = interfaces["nodes"]; JsonObject if_nodes = interfaces["nodes"];
CJSON(nodeListEnabled, if_nodes[F("list")]); CJSON(nodeListEnabled, if_nodes[F("list")]);
@ -594,6 +596,7 @@ void serializeConfig() {
if_sync_recv["bri"] = receiveNotificationBrightness; if_sync_recv["bri"] = receiveNotificationBrightness;
if_sync_recv["col"] = receiveNotificationColor; if_sync_recv["col"] = receiveNotificationColor;
if_sync_recv["fx"] = receiveNotificationEffects; if_sync_recv["fx"] = receiveNotificationEffects;
if_sync_recv["grp"] = receiveGroups;
JsonObject if_sync_send = if_sync.createNestedObject("send"); JsonObject if_sync_send = if_sync.createNestedObject("send");
if_sync_send[F("dir")] = notifyDirect; if_sync_send[F("dir")] = notifyDirect;
@ -602,6 +605,7 @@ void serializeConfig() {
if_sync_send["hue"] = notifyHue; if_sync_send["hue"] = notifyHue;
if_sync_send["macro"] = notifyMacro; if_sync_send["macro"] = notifyMacro;
if_sync_send[F("twice")] = notifyTwice; if_sync_send[F("twice")] = notifyTwice;
if_sync_send["grp"] = syncGroups;
JsonObject if_nodes = interfaces.createNestedObject("nodes"); JsonObject if_nodes = interfaces.createNestedObject("nodes");
if_nodes[F("list")] = nodeListEnabled; if_nodes[F("list")] = nodeListEnabled;

View File

@ -1,23 +1,86 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"><head><meta name="viewport" content="width=500"><meta charset="utf-8"><title>Sync Settings</title> <html lang="en"><head><meta name="viewport" content="width=500"><meta charset="utf-8"><title>Sync Settings</title>
<script>var d=document; <script>var d=document;
function gId(s)
{
return d.getElementById(s);
}
function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#sync-settings");}function B(){window.open("/settings","_self");} function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#sync-settings");}function B(){window.open("/settings","_self");}
function adj(){if (d.Sf.DI.value == 6454) {if (d.Sf.DA.value == 1) d.Sf.DA.value = 0; if (d.Sf.EU.value == 1) d.Sf.EU.value = 0;} function adj(){if (d.Sf.DI.value == 6454) {if (d.Sf.DA.value == 1) d.Sf.DA.value = 0; if (d.Sf.EU.value == 1) d.Sf.EU.value = 0;}
else if (d.Sf.DI.value == 5568) {if (d.Sf.DA.value == 0) d.Sf.DA.value = 1; if (d.Sf.EU.value == 0) d.Sf.EU.value = 1;} } else if (d.Sf.DI.value == 5568) {if (d.Sf.DA.value == 0) d.Sf.DA.value = 1; if (d.Sf.EU.value == 0) d.Sf.EU.value = 1;} }
function SP(){var p = d.Sf.DI.value; d.getElementById("xp").style.display = (p > 0)?"none":"block"; if (p > 0) d.Sf.EP.value = p;} function FC()
function SetVal(){switch(parseInt(d.Sf.EP.value)){case 5568: d.Sf.DI.value = 5568; break; case 6454: d.Sf.DI.value = 6454; break; case 4048: d.Sf.DI.value = 4048; break; }; SP();} {
for(j=0;j<8;j++)
{
gId("G"+(j+1)).checked=gId("GS").value>>j&1;
gId("R"+(j+1)).checked=gId("GR").value>>j&1;
}
}
function GC()
{
var a=0, b=0;
var m=1;
for(j=0;j<8;j++)
{
a+=gId("G"+(j+1)).checked*m;
b+=gId("R"+(j+1)).checked*m;
m*=2;
}
gId("GS").value=a;
gId("GR").value=b;
}
function SP(){var p = d.Sf.DI.value; gId("xp").style.display = (p > 0)?"none":"block"; if (p > 0) d.Sf.EP.value = p;}
function SetVal(){switch(parseInt(d.Sf.EP.value)){case 5568: d.Sf.DI.value = 5568; break; case 6454: d.Sf.DI.value = 6454; break; case 4048: d.Sf.DI.value = 4048; break; }; SP();FC();}
function S(){GetV();SetVal();} function S(){GetV();SetVal();}
function GetV(){var d=document;} function GetV(){var d=document;}
</script> </script>
<style>@import url("style.css");</style></head> <style>@import url("style.css");</style></head>
<body onload="S()"> <body onload="S()">
<form id="form_s" name="Sf" method="post"> <form id="form_s" name="Sf" method="post" onsubmit="GC()">
<div class="helpB"><button type="button" onclick="H()">?</button></div> <div class="helpB"><button type="button" onclick="H()">?</button></div>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr> <button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr>
<h2>Sync setup</h2> <h2>Sync setup</h2>
<h3>WLED Broadcast</h3> <h3>WLED Broadcast</h3>
UDP Port: <input name="UP" type="number" min="1" max="65535" class="d5" required><br> UDP Port: <input name="UP" type="number" min="1" max="65535" class="d5" required><br>
2nd Port: <input name="U2" type="number" min="1" max="65535" class="d5" required><br> 2nd Port: <input name="U2" type="number" min="1" max="65535" class="d5" required><br><br>
<input name="GS" id="GS" type="number" style="display: none;"> <!-- hidden inputs for bitwise group checkboxes -->
<input name="GR" id="GR" type="number" style="display: none;">
<table style="margin: 0 auto;">
<tr>
<td>Sync groups</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td>Send:</td>
<td><input type="checkbox" id="G1" name="G1"></td>
<td><input type="checkbox" id="G2" name="G2"></td>
<td><input type="checkbox" id="G3" name="G3"></td>
<td><input type="checkbox" id="G4" name="G4"></td>
<td><input type="checkbox" id="G5" name="G5"></td>
<td><input type="checkbox" id="G6" name="G6"></td>
<td><input type="checkbox" id="G7" name="G7"></td>
<td><input type="checkbox" id="G8" name="G8"></td>
</tr>
<tr>
<td>Receive:</td>
<td><input type="checkbox" id="R1" name="R1"></td>
<td><input type="checkbox" id="R2" name="R2"></td>
<td><input type="checkbox" id="R3" name="R3"></td>
<td><input type="checkbox" id="R4" name="R4"></td>
<td><input type="checkbox" id="R5" name="R5"></td>
<td><input type="checkbox" id="R6" name="R6"></td>
<td><input 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> Receive: <input type="checkbox" name="RB">Brightness, <input type="checkbox" name="RC">Color, and <input type="checkbox" name="RX">Effects<br>
Send notifications on direct change: <input type="checkbox" name="SD"><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 notifications on button press or IR: <input type="checkbox" name="SB"><br>

View File

@ -237,20 +237,35 @@ type="button" onclick="Save()">Save</button></form></body></html>)=====";
// Autogenerated from wled00/data/settings_sync.htm, do not edit!! // Autogenerated from wled00/data/settings_sync.htm, do not edit!!
const char PAGE_settings_sync[] PROGMEM = R"=====(<!DOCTYPE html><html lang="en"><head><meta name="viewport" content="width=500"> const char PAGE_settings_sync[] PROGMEM = R"=====(<!DOCTYPE html><html lang="en"><head><meta name="viewport" content="width=500">
<meta charset="utf-8"><title>Sync Settings</title><script> <meta charset="utf-8"><title>Sync Settings</title><script>
var d=document;function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#sync-settings")}function B(){window.open("/settings","_self")}function adj(){6454==d.Sf.DI.value?(1==d.Sf.DA.value&&(d.Sf.DA.value=0),1==d.Sf.EU.value&&(d.Sf.EU.value=0)):5568==d.Sf.DI.value&&(0==d.Sf.DA.value&&(d.Sf.DA.value=1),0==d.Sf.EU.value&&(d.Sf.EU.value=1))}function SP(){var e=d.Sf.DI.value;d.getElementById("xp").style.display=e>0?"none":"block",e>0&&(d.Sf.EP.value=e)}function SetVal(){switch(parseInt(d.Sf.EP.value)){case 5568:d.Sf.DI.value=5568;break;case 6454:d.Sf.DI.value=6454;break;case 4048:d.Sf.DI.value=4048}SP()}function S(){GetV(),SetVal()}function GetV() { var d=document;function gId(e){return d.getElementById(e)}function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#sync-settings")}function B(){window.open("/settings","_self")}function adj(){6454==d.Sf.DI.value?(1==d.Sf.DA.value&&(d.Sf.DA.value=0),1==d.Sf.EU.value&&(d.Sf.EU.value=0)):5568==d.Sf.DI.value&&(0==d.Sf.DA.value&&(d.Sf.DA.value=1),0==d.Sf.EU.value&&(d.Sf.EU.value=1))}function FC(){for(j=0;j<8;j++)gId("G"+(j+1)).checked=gId("GS").value>>j&1,gId("R"+(j+1)).checked=gId("GR").value>>j&1}function GC(){var e=0,d=0,n=1;for(j=0;j<8;j++)e+=gId("G"+(j+1)).checked*n,d+=gId("R"+(j+1)).checked*n,n*=2;gId("GS").value=e,gId("GR").value=d}function SP(){var e=d.Sf.DI.value;gId("xp").style.display=e>0?"none":"block",e>0&&(d.Sf.EP.value=e)}function SetVal(){switch(parseInt(d.Sf.EP.value)){case 5568:d.Sf.DI.value=5568;break;case 6454:d.Sf.DI.value=6454;break;case 4048:d.Sf.DI.value=4048}SP(),FC()}function S(){GetV(),SetVal()}function GetV() {
%CSS%%SCSS%</head><body onload="S()"><form %CSS%%SCSS%</head><body onload="S()"><form
id="form_s" name="Sf" method="post"><div class="helpB"><button type="button" id="form_s" name="Sf" method="post" onsubmit="GC()"><div class="helpB"><button
onclick="H()">?</button></div><button type="button" onclick="B()">Back</button> type="button" onclick="H()">?</button></div><button type="button" onclick="B()">
<button type="submit">Save</button><hr><h2>Sync setup</h2><h3>WLED Broadcast Back</button><button type="submit">Save</button><hr><h2>Sync setup</h2><h3>
</h3>UDP Port: <input name="UP" type="number" min="1" max="65535" class="d5" WLED Broadcast</h3>UDP Port: <input name="UP" type="number" min="1" max="65535"
required><br>2nd Port: <input name="U2" type="number" min="1" max="65535" class="d5" required><br>2nd Port: <input name="U2" type="number" min="1"
class="d5" required><br>Receive: <input type="checkbox" name="RB">Brightness, max="65535" class="d5" required><br><br><input name="GS" id="GS" type="number"
<input type="checkbox" name="RC">Color, and <input type="checkbox" name="RX"> style="display:none"> <input name="GR" id="GR" type="number"
Effects<br>Send notifications on direct change: <input type="checkbox" style="display:none"><table style="margin:0 auto"><tr><td>Sync groups</td><td>1
name="SD"><br>Send notifications on button press or IR: <input type="checkbox" </td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td></tr>
name="SB"><br>Send Alexa notifications: <input type="checkbox" name="SA"><br> <tr><td>Send:</td><td><input type="checkbox" id="G1" name="G1"></td><td><input
Send Philips Hue change notifications: <input type="checkbox" name="SH"><br> type="checkbox" id="G2" name="G2"></td><td><input type="checkbox" id="G3"
Send Macro notifications: <input type="checkbox" name="SM"><br> name="G3"></td><td><input type="checkbox" id="G4" name="G4"></td><td><input
type="checkbox" id="G5" name="G5"></td><td><input type="checkbox" id="G6"
name="G6"></td><td><input type="checkbox" id="G7" name="G7"></td><td><input
type="checkbox" id="G8" name="G8"></td></tr><tr><td>Receive:</td><td><input
type="checkbox" id="R1" name="R1"></td><td><input type="checkbox" id="R2"
name="R2"></td><td><input type="checkbox" id="R3" name="R3"></td><td><input
type="checkbox" id="R4" name="R4"></td><td><input type="checkbox" id="R5"
name="R5"></td><td><input type="checkbox" id="R6" name="R6"></td><td><input
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>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> Send notifications twice: <input type="checkbox" name="S2"><br><i>
Reboot required to apply changes.</i><h3>Instance List</h3> Reboot required to apply changes.</i><h3>Instance List</h3>
Enable instance list: <input type="checkbox" name="NL"><br> Enable instance list: <input type="checkbox" name="NL"><br>

View File

@ -22,7 +22,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
uint16_t len = elem[F("len")]; uint16_t len = elem[F("len")];
stop = (len > 0) ? start + len : seg.stop; stop = (len > 0) ? start + len : seg.stop;
} }
uint16_t grp = elem[F("grp")] | seg.grouping; uint16_t grp = elem["grp"] | seg.grouping;
uint16_t spc = elem[F("spc")] | seg.spacing; uint16_t spc = elem[F("spc")] | seg.spacing;
strip.setSegment(id, start, stop, grp, spc); strip.setSegment(id, start, stop, grp, spc);
@ -332,7 +332,7 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo
root["stop"] = seg.stop; root["stop"] = seg.stop;
} }
if (!forPreset) root[F("len")] = seg.stop - seg.start; if (!forPreset) root[F("len")] = seg.stop - seg.start;
root[F("grp")] = seg.grouping; root["grp"] = seg.grouping;
root[F("spc")] = seg.spacing; root[F("spc")] = seg.spacing;
root[F("of")] = seg.offset; root[F("of")] = seg.offset;
root["on"] = seg.getOption(SEG_OPTION_ON); root["on"] = seg.getOption(SEG_OPTION_ON);

View File

@ -209,6 +209,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
if (t > 0) udpPort = t; if (t > 0) udpPort = t;
t = request->arg(F("U2")).toInt(); t = request->arg(F("U2")).toInt();
if (t > 0) udpPort2 = t; if (t > 0) udpPort2 = t;
syncGroups = request->arg(F("GS")).toInt();
receiveGroups = request->arg(F("GR")).toInt();
receiveNotificationBrightness = request->hasArg(F("RB")); receiveNotificationBrightness = request->hasArg(F("RB"));
receiveNotificationColor = request->hasArg(F("RC")); receiveNotificationColor = request->hasArg(F("RC"));
receiveNotificationEffects = request->hasArg(F("RX")); receiveNotificationEffects = request->hasArg(F("RX"));

View File

@ -4,13 +4,14 @@
* UDP sync notifier / Realtime / Hyperion / TPM2.NET * UDP sync notifier / Realtime / Hyperion / TPM2.NET
*/ */
#define WLEDPACKETSIZE 36 #define WLEDPACKETSIZE 37
#define UDP_IN_MAXSIZE 1472 #define UDP_IN_MAXSIZE 1472
#define PRESUMED_NETWORK_DELAY 3 //how many ms could it take on avg to reach the receiver? This will be added to transmitted times #define PRESUMED_NETWORK_DELAY 3 //how many ms could it take on avg to reach the receiver? This will be added to transmitted times
void notify(byte callMode, bool followUp) void notify(byte callMode, bool followUp)
{ {
if (!udpConnected) return; if (!udpConnected) return;
if (!syncGroups) return;
switch (callMode) switch (callMode)
{ {
case CALL_MODE_INIT: return; case CALL_MODE_INIT: return;
@ -39,7 +40,8 @@ void notify(byte callMode, bool followUp)
//0: old 1: supports white 2: supports secondary color //0: old 1: supports white 2: supports secondary color
//3: supports FX intensity, 24 byte packet 4: supports transitionDelay 5: sup palette //3: supports FX intensity, 24 byte packet 4: supports transitionDelay 5: sup palette
//6: supports timebase syncing, 29 byte packet 7: supports tertiary color 8: supports sys time sync, 36 byte packet //6: supports timebase syncing, 29 byte packet 7: supports tertiary color 8: supports sys time sync, 36 byte packet
udpOut[11] = 8; //9: supports sync groups, 37 byte packet
udpOut[11] = 9;
udpOut[12] = colSec[0]; udpOut[12] = colSec[0];
udpOut[13] = colSec[1]; udpOut[13] = colSec[1];
udpOut[14] = colSec[2]; udpOut[14] = colSec[2];
@ -72,6 +74,9 @@ void notify(byte callMode, bool followUp)
uint16_t ms = tm.ms; uint16_t ms = tm.ms;
udpOut[34] = (ms >> 8) & 0xFF; udpOut[34] = (ms >> 8) & 0xFF;
udpOut[35] = (ms >> 0) & 0xFF; udpOut[35] = (ms >> 0) & 0xFF;
//sync groups
udpOut[36] = syncGroups;
IPAddress broadcastIp; IPAddress broadcastIp;
broadcastIp = ~uint32_t(Network.subnetMask()) | uint32_t(Network.gatewayIP()); broadcastIp = ~uint32_t(Network.subnetMask()) | uint32_t(Network.gatewayIP());
@ -219,6 +224,12 @@ void handleNotifications()
//compatibilityVersionByte: //compatibilityVersionByte:
byte version = udpIn[11]; byte version = udpIn[11];
// if we are not part of any sync group ignore message
if (version < 9 || version > 199) {
// legacy senders are treated as if sending in sync group 1 only
if (!(receiveGroups & 0x01)) return;
} else if (!(receiveGroups & udpIn[36])) return;
bool someSel = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects); bool someSel = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects);
//apply colors from notification //apply colors from notification
@ -263,7 +274,7 @@ void handleNotifications()
} }
//adjust system time, but only if sender is more accurate than self //adjust system time, but only if sender is more accurate than self
if (version > 7) if (version > 7 && version < 200)
{ {
Toki::Time tm; Toki::Time tm;
tm.sec = (udpIn[30] << 24) | (udpIn[31] << 16) | (udpIn[32] << 8) | (udpIn[33]); tm.sec = (udpIn[30] << 24) | (udpIn[31] << 16) | (udpIn[32] << 8) | (udpIn[33]);

View File

@ -298,6 +298,8 @@ WLED_GLOBAL bool liveHSVCorrection _INIT(false);
WLED_GLOBAL uint16_t liveHSVSaturation _INIT(13); WLED_GLOBAL uint16_t liveHSVSaturation _INIT(13);
WLED_GLOBAL uint16_t liveHSVValue _INIT(10); WLED_GLOBAL uint16_t liveHSVValue _INIT(10);
WLED_GLOBAL uint8_t syncGroups _INIT(0x01); // sync groups this instance syncs (bit mapped)
WLED_GLOBAL uint8_t receiveGroups _INIT(0x01); // sync receive groups this instance belongs to (bit mapped)
WLED_GLOBAL bool receiveNotificationBrightness _INIT(true); // apply brightness from incoming notifications WLED_GLOBAL bool receiveNotificationBrightness _INIT(true); // apply brightness from incoming notifications
WLED_GLOBAL bool receiveNotificationColor _INIT(true); // apply color WLED_GLOBAL bool receiveNotificationColor _INIT(true); // apply color
WLED_GLOBAL bool receiveNotificationEffects _INIT(true); // apply effects setup WLED_GLOBAL bool receiveNotificationEffects _INIT(true); // apply effects setup

View File

@ -396,6 +396,8 @@ void getSettingsJS(byte subPage, char* dest)
{ {
sappend('v',SET_F("UP"),udpPort); sappend('v',SET_F("UP"),udpPort);
sappend('v',SET_F("U2"),udpPort2); sappend('v',SET_F("U2"),udpPort2);
sappend('v',SET_F("GS"),syncGroups);
sappend('v',SET_F("GR"),receiveGroups);
sappend('c',SET_F("HX"),liveHSVCorrection); sappend('c',SET_F("HX"),liveHSVCorrection);
sappend('v',SET_F("HS"),liveHSVSaturation); sappend('v',SET_F("HS"),liveHSVSaturation);