Send segment ID, start, stop, and cct

This commit is contained in:
cschwinne 2022-01-24 18:31:05 +01:00
parent d28eb6ae21
commit 5f0b102671
4 changed files with 75 additions and 67 deletions

View File

@ -82,8 +82,8 @@ UDP Port: <input name="UP" type="number" min="1" max="65535" class="d5" required
<td><input type="checkbox" id="R8" name="R8"></td> <td><input type="checkbox" id="R8" name="R8"></td>
</tr> </tr>
</table><br> </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>
<input type="checkbox" name="SO">Segment options<br> <input type="checkbox" name="SO"> Segment options<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>
Send Alexa notifications: <input type="checkbox" name="SA"><br> Send Alexa notifications: <input type="checkbox" name="SA"><br>

View File

@ -725,9 +725,6 @@ void serializePalettes(JsonObject root, AsyncWebServerRequest* request)
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
JsonArray curPalette = palettes.createNestedArray(String(i)); JsonArray curPalette = palettes.createNestedArray(String(i));
CRGB prim;
CRGB sec;
CRGB ter;
switch (i) { switch (i) {
case 0: //default palette case 0: //default palette
setPaletteColors(curPalette, PartyColors_p); setPaletteColors(curPalette, PartyColors_p);

View File

@ -129,8 +129,8 @@ void colorUpdated(int callMode)
void updateInterfaces(uint8_t callMode) void updateInterfaces(uint8_t callMode)
{ {
lastInterfaceUpdate = millis();
sendDataWs(); sendDataWs();
lastInterfaceUpdate = millis();
if (callMode == CALL_MODE_WS_SEND) return; if (callMode == CALL_MODE_WS_SEND) return;
#ifndef WLED_DISABLE_ALEXA #ifndef WLED_DISABLE_ALEXA

View File

@ -4,7 +4,7 @@
* UDP sync notifier / Realtime / Hyperion / TPM2.NET * UDP sync notifier / Realtime / Hyperion / TPM2.NET
*/ */
#define UDP_SEG_SIZE 22 #define UDP_SEG_SIZE 28
#define SEG_OFFSET (41+(MAX_NUM_SEGMENTS*UDP_SEG_SIZE)) #define SEG_OFFSET (41+(MAX_NUM_SEGMENTS*UDP_SEG_SIZE))
#define WLEDPACKETSIZE (41+(MAX_NUM_SEGMENTS*UDP_SEG_SIZE)+0) #define WLEDPACKETSIZE (41+(MAX_NUM_SEGMENTS*UDP_SEG_SIZE)+0)
#define UDP_IN_MAXSIZE 1472 #define UDP_IN_MAXSIZE 1472
@ -92,28 +92,34 @@ void notify(byte callMode, bool followUp)
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) { for (uint8_t i = 0; i < strip.getMaxSegments(); i++) {
WS2812FX::Segment &selseg = strip.getSegment(i); WS2812FX::Segment &selseg = strip.getSegment(i);
uint16_t ofs = 41 + i*UDP_SEG_SIZE; //start of segment offset byte uint16_t ofs = 41 + i*UDP_SEG_SIZE; //start of segment offset byte
udpOut[0 +ofs] = selseg.grouping; udpOut[0 +ofs] = i;
udpOut[1 +ofs] = selseg.spacing; udpOut[1 +ofs] = selseg.start >> 8;
udpOut[2 +ofs] = selseg.offset >> 8; udpOut[2 +ofs] = selseg.start & 0xFF;
udpOut[3 +ofs] = selseg.offset & 0xFF; udpOut[3 +ofs] = selseg.stop >> 8;
udpOut[4 +ofs] = selseg.options & 0x0F; //only take into account mirrored, selected, on, reversed udpOut[4 +ofs] = selseg.stop & 0xFF;
udpOut[5 +ofs] = selseg.opacity; udpOut[5 +ofs] = selseg.grouping;
udpOut[6 +ofs] = selseg.mode; udpOut[6 +ofs] = selseg.spacing;
udpOut[7 +ofs] = selseg.speed; udpOut[7 +ofs] = selseg.offset >> 8;
udpOut[8 +ofs] = selseg.intensity; udpOut[8 +ofs] = selseg.offset & 0xFF;
udpOut[9 +ofs] = selseg.palette; udpOut[9 +ofs] = selseg.options & 0x0F; //only take into account mirrored, selected, on, reversed
udpOut[10+ofs] = R(selseg.colors[0]); udpOut[10+ofs] = selseg.opacity;
udpOut[11+ofs] = G(selseg.colors[0]); udpOut[11+ofs] = selseg.mode;
udpOut[12+ofs] = B(selseg.colors[0]); udpOut[12+ofs] = selseg.speed;
udpOut[13+ofs] = W(selseg.colors[0]); udpOut[13+ofs] = selseg.intensity;
udpOut[14+ofs] = R(selseg.colors[1]); udpOut[14+ofs] = selseg.palette;
udpOut[15+ofs] = G(selseg.colors[1]); udpOut[15+ofs] = R(selseg.colors[0]);
udpOut[16+ofs] = B(selseg.colors[1]); udpOut[16+ofs] = G(selseg.colors[0]);
udpOut[17+ofs] = W(selseg.colors[1]); udpOut[17+ofs] = B(selseg.colors[0]);
udpOut[18+ofs] = R(selseg.colors[2]); udpOut[18+ofs] = W(selseg.colors[0]);
udpOut[19+ofs] = G(selseg.colors[2]); udpOut[19+ofs] = R(selseg.colors[1]);
udpOut[20+ofs] = B(selseg.colors[2]); udpOut[20+ofs] = G(selseg.colors[1]);
udpOut[21+ofs] = W(selseg.colors[2]); udpOut[21+ofs] = B(selseg.colors[1]);
udpOut[22+ofs] = W(selseg.colors[1]);
udpOut[23+ofs] = R(selseg.colors[2]);
udpOut[24+ofs] = G(selseg.colors[2]);
udpOut[25+ofs] = B(selseg.colors[2]);
udpOut[26+ofs] = W(selseg.colors[2]);
udpOut[27+ofs] = selseg.cct;
} }
//uint16_t offs = SEG_OFFSET; //uint16_t offs = SEG_OFFSET;
@ -281,73 +287,78 @@ void handleNotifications()
} else if (!(receiveGroups & udpIn[36])) return; } else if (!(receiveGroups & udpIn[36])) return;
bool someSel = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects); bool someSel = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects);
//apply colors from notification
if (receiveNotificationColor || !someSel) { //apply colors from notification to main segment, only if not syncing full segments
if (version < 11 || !receiveSegmentOptions) { if ((receiveNotificationColor || !someSel) && (version < 11 || !receiveSegmentOptions)) {
// only change col[] if not syncing full segments col[0] = udpIn[3];
col[0] = udpIn[3]; col[1] = udpIn[4];
col[1] = udpIn[4]; col[2] = udpIn[5];
col[2] = udpIn[5];
}
if (version > 0) //sending module's white val is intended if (version > 0) //sending module's white val is intended
{ {
// only change col[3] if not syncing full segments col[3] = udpIn[10];
if (version < 11 || !receiveSegmentOptions) col[3] = udpIn[10]; if (version > 1) {
if (version > 1 && (version < 11 || !receiveSegmentOptions)) {
// only change colSec[] if not syncing full segments
colSec[0] = udpIn[12]; colSec[0] = udpIn[12];
colSec[1] = udpIn[13]; colSec[1] = udpIn[13];
colSec[2] = udpIn[14]; colSec[2] = udpIn[14];
colSec[3] = udpIn[15]; colSec[3] = udpIn[15];
} }
if (version > 6 && (version < 11 || !receiveSegmentOptions)) { if (version > 6) {
strip.setColor(2, RGBW32(udpIn[20], udpIn[21], udpIn[22], udpIn[23])); //tertiary color strip.setColor(2, RGBW32(udpIn[20], udpIn[21], udpIn[22], udpIn[23])); //tertiary color
} if (version > 9 && version < 200 && udpIn[37] < 255) { //valid CCT/Kelvin value
if (version > 9 && version < 200 && udpIn[37] < 255) { //valid CCT/Kelvin value uint8_t cct = udpIn[38];
uint8_t cct = udpIn[38]; if (udpIn[37] > 0) { //Kelvin
if (udpIn[37] > 0) { //Kelvin cct = (((udpIn[37] << 8) + udpIn[38]) - 1900) >> 5;
cct = (((udpIn[37] << 8) + udpIn[38]) - 1900) >> 5; }
uint8_t segid = strip.getMainSegmentId();
strip.getSegment(segid).setCCT(cct, segid);
} }
uint8_t segid = strip.getMainSegmentId(); }
strip.getSegment(segid).setCCT(cct, segid);
}
} }
} }
bool timebaseUpdated = false; bool timebaseUpdated = false;
//apply effects from notification //apply effects from notification
if (version < 200 && (receiveNotificationEffects || !someSel)) bool applyEffects = (receiveNotificationEffects || !someSel);
if (version < 200)
{ {
if (currentPlaylist>=0) unloadPlaylist(); if (applyEffects && currentPlaylist >= 0) unloadPlaylist();
if (version > 10 && receiveSegmentOptions) { if (version > 10 && receiveSegmentOptions) {
//does not sync start & stop //does not sync start & stop
uint8_t srcSegs = udpIn[39]; uint8_t srcSegs = udpIn[39];
if (srcSegs > strip.getMaxSegments()) srcSegs = strip.getMaxSegments(); //if (srcSegs > strip.getMaxSegments()) srcSegs = strip.getMaxSegments();
for (uint8_t i = 0; i < srcSegs; i++) { for (uint8_t i = 0; i < srcSegs; i++) {
WS2812FX::Segment& selseg = strip.getSegment(i); uint16_t ofs = 41 + i*udpIn[40]; //start of segment offset byte
uint16_t ofs = 41 + i*UDP_SEG_SIZE; //start of segment offset byte uint8_t id = udpIn[0 +ofs];
for (uint8_t j = 0; j<4; j++) selseg.setOption(j, (udpIn[4 +ofs] >> j) & 0x01); //only take into account mirrored, selected, on, reversed if (id > strip.getMaxSegments()) continue;
selseg.setOpacity( udpIn[5+ofs], i); WS2812FX::Segment& selseg = strip.getSegment(id);
strip.setMode(i, udpIn[6+ofs]); //bytes 1+2 contain start, 3+4 stop, unused at this time
selseg.speed = udpIn[7+ofs]; 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.intensity = udpIn[8+ofs]; selseg.setOpacity(udpIn[10+ofs], id);
selseg.palette = udpIn[9+ofs]; if (applyEffects) {
selseg.setColor(0, RGBW32(udpIn[10+ofs],udpIn[11+ofs],udpIn[12+ofs],udpIn[13+ofs]), i); strip.setMode(id, udpIn[11+ofs]);
selseg.setColor(1, RGBW32(udpIn[14+ofs],udpIn[15+ofs],udpIn[16+ofs],udpIn[17+ofs]), i); selseg.speed = udpIn[12+ofs];
selseg.setColor(2, RGBW32(udpIn[18+ofs],udpIn[19+ofs],udpIn[20+ofs],udpIn[21+ofs]), i); selseg.intensity = udpIn[13+ofs];
strip.setSegment(i, selseg.start, selseg.stop, udpIn[0+ofs], udpIn[1+ofs], (udpIn[2+ofs]<<8 | udpIn[3+ofs])); //also properly resets segments selseg.palette = udpIn[14+ofs];
}
if (receiveNotificationColor || !someSel) {
selseg.setColor(0, RGBW32(udpIn[15+ofs],udpIn[16+ofs],udpIn[17+ofs],udpIn[18+ofs]), id);
selseg.setColor(1, RGBW32(udpIn[19+ofs],udpIn[20+ofs],udpIn[21+ofs],udpIn[22+ofs]), id);
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
} }
setValuesFromMainSeg(); setValuesFromMainSeg();
effectChanged = true; effectChanged = true;
colorChanged = true; colorChanged = true;
} else { //simple effect sync, applies to all selected } else if (applyEffects) { //simple effect sync, applies to all selected
if (udpIn[8] < strip.getModeCount()) effectCurrent = udpIn[8]; if (udpIn[8] < strip.getModeCount()) effectCurrent = udpIn[8];
effectSpeed = udpIn[9]; effectSpeed = udpIn[9];
if (version > 2) effectIntensity = udpIn[16]; if (version > 2) effectIntensity = udpIn[16];
if (version > 4 && udpIn[19] < strip.getPaletteCount()) effectPalette = udpIn[19]; if (version > 4 && udpIn[19] < strip.getPaletteCount()) effectPalette = udpIn[19];
} }
if (version > 5) { if (applyEffects && version > 5) {
uint32_t t = (udpIn[25] << 24) | (udpIn[26] << 16) | (udpIn[27] << 8) | (udpIn[28]); uint32_t t = (udpIn[25] << 24) | (udpIn[26] << 16) | (udpIn[27] << 8) | (udpIn[28]);
t += PRESUMED_NETWORK_DELAY; //adjust trivially for network delay t += PRESUMED_NETWORK_DELAY; //adjust trivially for network delay
t -= millis(); t -= millis();