diff --git a/wled00/json.cpp b/wled00/json.cpp index 70e05cb2..4dad36a0 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -8,7 +8,7 @@ bool getVal(JsonVariant elem, byte* val, byte vmin=0, byte vmax=255) { if (elem.is()) { - if (elem < 0) return false; //ignore e.g. {"ps":-1} + if (elem < 0) return false; //ignore e.g. {"ps":-1} *val = elem; return true; } else if (elem.is()) { @@ -82,7 +82,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId) uint16_t grp = elem["grp"] | seg.grouping; uint16_t spc = elem[F("spc")] | seg.spacing; - uint16_t of = seg.offset; + uint16_t of = seg.offset; if (!(elem[F("spc")].isNull() && elem["grp"].isNull())) effectChanged = true; //send UDP uint16_t len = 1; @@ -95,7 +95,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId) of = offsetAbs; } if (stop > start && of > len -1) of = len -1; - strip.setSegment(id, start, stop, grp, spc, of); + strip.setSegment(id, start, stop, grp, spc, of); byte segbri = 0; if (getVal(elem["bri"], &segbri)) { @@ -110,9 +110,9 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId) if (elem["frz"].is() && elem["frz"].as()[0] == 't') frz = !seg.getOption(SEG_OPTION_FREEZE); seg.setOption(SEG_OPTION_FREEZE, frz, id); - uint8_t cctPrev = seg.cct; + uint8_t cctPrev = seg.cct; seg.setCCT(elem["cct"] | seg.cct, id); - if (seg.cct != cctPrev && id == strip.getMainSegmentId()) effectChanged = true; //send UDP + if (seg.cct != cctPrev && id == strip.getMainSegmentId()) effectChanged = true; //send UDP JsonArray colarr = elem["col"]; if (!colarr.isNull()) @@ -398,12 +398,12 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId) void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool forPreset, bool segmentBounds) { - root["id"] = id; + root["id"] = id; if (segmentBounds) { root["start"] = seg.start; root["stop"] = seg.stop; } - if (!forPreset) root[F("len")] = seg.stop - seg.start; + if (!forPreset) root[F("len")] = seg.stop - seg.start; root["grp"] = seg.grouping; root[F("spc")] = seg.spacing; root[F("of")] = seg.offset; @@ -438,12 +438,12 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo strcat_P(colstr, PSTR("]")); root["col"] = serialized(colstr); - root["fx"] = seg.mode; - root[F("sx")] = seg.speed; - root[F("ix")] = seg.intensity; - root["pal"] = seg.palette; - root[F("sel")] = seg.isSelected(); - root["rev"] = seg.getOption(SEG_OPTION_REVERSED); + root["fx"] = seg.mode; + root[F("sx")] = seg.speed; + root[F("ix")] = seg.intensity; + root["pal"] = seg.palette; + root[F("sel")] = seg.isSelected(); + root["rev"] = seg.getOption(SEG_OPTION_REVERSED); root[F("mi")] = seg.getOption(SEG_OPTION_MIRROR); } @@ -527,12 +527,12 @@ void serializeInfo(JsonObject root) leds[F("rgbw")] = strip.isRgbw; leds[F("wv")] = false; leds["cct"] = correctWB || strip.hasCCTBus(); - switch (Bus::getAutoWhiteMode()) { - case RGBW_MODE_MANUAL_ONLY: - case RGBW_MODE_DUAL: - if (strip.isRgbw) leds[F("wv")] = true; - break; - } + switch (Bus::getAutoWhiteMode()) { + case RGBW_MODE_MANUAL_ONLY: + case RGBW_MODE_DUAL: + if (strip.isRgbw) leds[F("wv")] = true; + break; + } leds[F("pwr")] = strip.currentMilliamps; leds["fps"] = strip.getFps(); diff --git a/wled00/led.cpp b/wled00/led.cpp index 069aaba8..f5c235bf 100644 --- a/wled00/led.cpp +++ b/wled00/led.cpp @@ -130,7 +130,7 @@ void colorUpdated(int callMode) void updateInterfaces(uint8_t callMode) { sendDataWs(); - lastInterfaceUpdate = millis(); + lastInterfaceUpdate = millis(); if (callMode == CALL_MODE_WS_SEND) return; #ifndef WLED_DISABLE_ALEXA diff --git a/wled00/udp.cpp b/wled00/udp.cpp index 87867c9d..f04a6e78 100644 --- a/wled00/udp.cpp +++ b/wled00/udp.cpp @@ -19,7 +19,7 @@ void notify(byte callMode, bool followUp) case CALL_MODE_INIT: return; case CALL_MODE_DIRECT_CHANGE: if (!notifyDirect) return; break; case CALL_MODE_BUTTON: if (!notifyButton) return; break; - case CALL_MODE_BUTTON_PRESET: if (!notifyButton) return; break; + case CALL_MODE_BUTTON_PRESET: if (!notifyButton) return; break; case CALL_MODE_NIGHTLIGHT: if (!notifyDirect) return; break; case CALL_MODE_HUE: if (!notifyHue) return; break; case CALL_MODE_PRESET_CYCLE: if (!notifyDirect) return; break; @@ -28,7 +28,7 @@ void notify(byte callMode, bool followUp) default: return; } byte udpOut[WLEDPACKETSIZE]; - WS2812FX::Segment& mainseg = strip.getSegment(strip.getMainSegmentId()); + WS2812FX::Segment& mainseg = strip.getSegment(strip.getMainSegmentId()); udpOut[0] = 0; //0: wled notifier protocol 1: WARLS protocol udpOut[1] = callMode; udpOut[2] = bri; @@ -81,22 +81,22 @@ void notify(byte callMode, bool followUp) //sync groups udpOut[36] = syncGroups; - - //Might be changed to Kelvin in the future, receiver code should handle that case - //0: byte 38 contains 0-255 value, 255: no valid CCT, 1-254: Kelvin value MSB - udpOut[37] = strip.hasCCTBus() ? 0 : 255; //check this is 0 for the next value to be significant - udpOut[38] = mainseg.cct; - udpOut[39] = strip.getMaxSegments(); - udpOut[40] = UDP_SEG_SIZE; //size of each loop iteration (one segment) + //Might be changed to Kelvin in the future, receiver code should handle that case + //0: byte 38 contains 0-255 value, 255: no valid CCT, 1-254: Kelvin value MSB + udpOut[37] = strip.hasCCTBus() ? 0 : 255; //check this is 0 for the next value to be significant + udpOut[38] = mainseg.cct; + + udpOut[39] = strip.getMaxSegments(); + udpOut[40] = UDP_SEG_SIZE; //size of each loop iteration (one segment) for (uint8_t i = 0; i < strip.getMaxSegments(); i++) { WS2812FX::Segment &selseg = strip.getSegment(i); - uint16_t ofs = 41 + i*UDP_SEG_SIZE; //start of segment offset byte - udpOut[0 +ofs] = i; - udpOut[1 +ofs] = selseg.start >> 8; - udpOut[2 +ofs] = selseg.start & 0xFF; - udpOut[3 +ofs] = selseg.stop >> 8; - udpOut[4 +ofs] = selseg.stop & 0xFF; + uint16_t ofs = 41 + i*UDP_SEG_SIZE; //start of segment offset byte + udpOut[0 +ofs] = i; + udpOut[1 +ofs] = selseg.start >> 8; + udpOut[2 +ofs] = selseg.start & 0xFF; + udpOut[3 +ofs] = selseg.stop >> 8; + udpOut[4 +ofs] = selseg.stop & 0xFF; udpOut[5 +ofs] = selseg.grouping; udpOut[6 +ofs] = selseg.spacing; udpOut[7 +ofs] = selseg.offset >> 8; @@ -119,11 +119,11 @@ void notify(byte callMode, bool followUp) 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; + udpOut[27+ofs] = selseg.cct; } - //uint16_t offs = SEG_OFFSET; - //next value to be added has index: udpOut[offs + 0] + //uint16_t offs = SEG_OFFSET; + //next value to be added has index: udpOut[offs + 0] IPAddress broadcastIp; broadcastIp = ~uint32_t(Network.subnetMask()) | uint32_t(Network.gatewayIP()); @@ -290,9 +290,9 @@ void handleNotifications() //apply colors from notification to main segment, only if not syncing full segments if ((receiveNotificationColor || !someSel) && (version < 11 || !receiveSegmentOptions)) { - col[0] = udpIn[3]; - col[1] = udpIn[4]; - col[2] = udpIn[5]; + col[0] = udpIn[3]; + col[1] = udpIn[4]; + col[2] = udpIn[5]; if (version > 0) //sending module's white val is intended { col[3] = udpIn[10]; @@ -304,59 +304,59 @@ void handleNotifications() } if (version > 6) { 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 - uint8_t cct = udpIn[38]; - if (udpIn[37] > 0) { //Kelvin - cct = (((udpIn[37] << 8) + udpIn[38]) - 1900) >> 5; - } - uint8_t segid = strip.getMainSegmentId(); - strip.getSegment(segid).setCCT(cct, segid); - } + if (version > 9 && version < 200 && udpIn[37] < 255) { //valid CCT/Kelvin value + uint8_t cct = udpIn[38]; + if (udpIn[37] > 0) { //Kelvin + cct = (((udpIn[37] << 8) + udpIn[38]) - 1900) >> 5; + } + uint8_t segid = strip.getMainSegmentId(); + strip.getSegment(segid).setCCT(cct, segid); + } } } } bool timebaseUpdated = false; //apply effects from notification - bool applyEffects = (receiveNotificationEffects || !someSel); + bool applyEffects = (receiveNotificationEffects || !someSel); 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++) { - 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 - 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) { - strip.setMode(id, udpIn[11+ofs]); - selseg.speed = udpIn[12+ofs]; - selseg.intensity = udpIn[13+ofs]; - 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 - } + //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++) { + 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 + 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) { + strip.setMode(id, udpIn[11+ofs]); + selseg.speed = udpIn[12+ofs]; + selseg.intensity = udpIn[13+ofs]; + 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(); effectChanged = true; colorChanged = true; } else if (applyEffects) { //simple effect sync, applies to all selected - if (udpIn[8] < strip.getModeCount()) effectCurrent = udpIn[8]; - effectSpeed = udpIn[9]; - if (version > 2) effectIntensity = udpIn[16]; - if (version > 4 && udpIn[19] < strip.getPaletteCount()) effectPalette = udpIn[19]; - } + if (udpIn[8] < strip.getModeCount()) effectCurrent = udpIn[8]; + effectSpeed = udpIn[9]; + if (version > 2) effectIntensity = udpIn[16]; + if (version > 4 && udpIn[19] < strip.getPaletteCount()) effectPalette = udpIn[19]; + } if (applyEffects && version > 5) { uint32_t t = (udpIn[25] << 24) | (udpIn[26] << 16) | (udpIn[27] << 8) | (udpIn[28]);