diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 726beb3be7..2e931ffd8a 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -443,6 +443,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { CJSON(receiveNotificationPalette, if_sync_recv["pal"]); CJSON(receiveGroups, if_sync_recv["grp"]); CJSON(receiveSegmentOptions, if_sync_recv["seg"]); + CJSON(receiveSegmentName, if_sync_recv["sn"]); CJSON(receiveSegmentBounds, if_sync_recv["sb"]); JsonObject if_sync_send = if_sync[F("send")]; @@ -950,6 +951,7 @@ void serializeConfig() { if_sync_recv["pal"] = receiveNotificationPalette; if_sync_recv["grp"] = receiveGroups; if_sync_recv["seg"] = receiveSegmentOptions; + if_sync_recv["sn"] = receiveSegmentName; if_sync_recv["sb"] = receiveSegmentBounds; JsonObject if_sync_send = if_sync.createNestedObject(F("send")); diff --git a/wled00/data/settings_sync.htm b/wled00/data/settings_sync.htm index ca6c0fb59c..08a84465f3 100644 --- a/wled00/data/settings_sync.htm +++ b/wled00/data/settings_sync.htm @@ -101,7 +101,7 @@

Sync groups

Receive

Brightness, Color, Effects, and Palette
- Segment options, bounds + Segment options, name, bounds

Send

Enable Sync on start:
Send notifications on direct change:
@@ -241,4 +241,4 @@

Serial

- \ No newline at end of file + diff --git a/wled00/set.cpp b/wled00/set.cpp index 33d79d66ea..3c00b2edbf 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -379,6 +379,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) receiveNotificationEffects = request->hasArg(F("RX")); receiveNotificationPalette = request->hasArg(F("RP")); receiveSegmentOptions = request->hasArg(F("SO")); + receiveSegmentName = request->hasArg(F("SN")); receiveSegmentBounds = request->hasArg(F("SG")); sendNotifications = request->hasArg(F("SS")); notifyDirect = request->hasArg(F("SD")); diff --git a/wled00/udp.cpp b/wled00/udp.cpp index 4395b285d0..14414b4705 100644 --- a/wled00/udp.cpp +++ b/wled00/udp.cpp @@ -4,9 +4,9 @@ * UDP sync notifier / Realtime / Hyperion / TPM2.NET */ -#define UDP_SEG_SIZE 36 +#define UDP_SEG_SIZE (36+WLED_MAX_SEGNAME_LEN) #define SEG_OFFSET (41) -#define WLEDPACKETSIZE (41+(MAX_NUM_SEGMENTS*UDP_SEG_SIZE)+0) +#define WLEDPACKETSIZE (SEG_OFFSET+(MAX_NUM_SEGMENTS*UDP_SEG_SIZE)+0) #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 @@ -143,6 +143,11 @@ void notify(byte callMode, bool followUp) udpOut[33+ofs] = selseg.startY & 0xFF; udpOut[34+ofs] = selseg.stopY >> 8; // ATM always 0 as Segment::stopY is 8-bit udpOut[35+ofs] = selseg.stopY & 0xFF; + + if(selseg.name){ + strcpy((char *)&udpOut[36+ofs], selseg.name); + } + ++s; } @@ -155,15 +160,11 @@ void notify(byte callMode, bool followUp) // send global data DEBUG_PRINTLN(F("ESP-NOW sending first packet.")); const size_t bufferSize = sizeof(buffer.data)/sizeof(uint8_t); - size_t packetSize = 41; - size_t s0 = 0; + size_t packetSize = SEG_OFFSET; memcpy(buffer.data, udpOut, packetSize); - // stuff as many segments in first packet as possible (normally up to 5) - for (size_t i = 0; packetSize < bufferSize && i < s; i++) { - memcpy(buffer.data + packetSize, &udpOut[41+i*UDP_SEG_SIZE], UDP_SEG_SIZE); - packetSize += UDP_SEG_SIZE; - s0++; - } + // since we sync the name, only one segment can fit in the first packet + memcpy(buffer.data + packetSize, &udpOut[41+UDP_SEG_SIZE], UDP_SEG_SIZE); + size_t s0 = 1; if (s > s0) buffer.noOfPackets += 1 + ((s - s0) * UDP_SEG_SIZE) / bufferSize; // set number of packets auto err = quickEspNow.send(ESPNOW_BROADCAST_ADDRESS, reinterpret_cast(&buffer), packetSize+3); if (!err && s0 < s) { @@ -267,7 +268,7 @@ static void parseNotifyPacket(const uint8_t *udpIn) { } size_t inactiveSegs = 0; for (size_t i = 0; i < numSrcSegs && i < strip.getMaxSegments(); i++) { - unsigned ofs = 41 + i*udpIn[40]; //start of segment offset byte + unsigned ofs = SEG_OFFSET + i*udpIn[40]; //start of segment offset byte unsigned id = udpIn[0 +ofs]; DEBUG_PRINTF_P(PSTR("UDP segment received: %u\n"), id); if (id > strip.getSegmentsNum()) break; @@ -296,6 +297,7 @@ static void parseNotifyPacket(const uint8_t *udpIn) { uint16_t startY = version > 11 ? (udpIn[32+ofs] << 8 | udpIn[33+ofs]) : 0; uint16_t stopY = version > 11 ? (udpIn[34+ofs] << 8 | udpIn[35+ofs]) : 1; uint16_t offset = (udpIn[7+ofs] << 8 | udpIn[8+ofs]); + if (!receiveSegmentOptions) { DEBUG_PRINTF_P(PSTR("Set segment w/o options: %d [%d,%d;%d,%d]\n"), id, (int)start, (int)stop, (int)startY, (int)stopY); strip.suspend(); //should not be needed as UDP handling is not done in ISR callbacks but still added "just in case" @@ -338,6 +340,13 @@ static void parseNotifyPacket(const uint8_t *udpIn) { selseg.check1 = (udpIn[31+ofs]>>7) & 0x1; } } + if (receiveSegmentName) { + const char* name = (char *) &udpIn[36+ofs]; + if (strlen(name) < WLED_MAX_SEGNAME_LEN) { + selseg.clearName(); + selseg.setName(name); + } + } if (receiveSegmentBounds) { DEBUG_PRINTF_P(PSTR("Set segment w/ options: %d [%d,%d;%d,%d]\n"), id, (int)start, (int)stop, (int)startY, (int)stopY); strip.suspend(); //should not be needed as UDP handling is not done in ISR callbacks but still added "just in case" diff --git a/wled00/wled.h b/wled00/wled.h index 62eae73572..df4f2c07f7 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -650,6 +650,7 @@ typedef class Receive { bool Color : 1; bool Effects : 1; bool SegmentOptions : 1; + bool SegmentName : 1; bool SegmentBounds : 1; bool Direct : 1; bool Palette : 1; @@ -657,11 +658,12 @@ typedef class Receive { }; }; Receive(int i) { Options = i; } - Receive(bool b, bool c, bool e, bool sO, bool sB, bool p) + Receive(bool b, bool c, bool e, bool sO, bool sN, bool sB, bool p) : Brightness(b) , Color(c) , Effects(e) , SegmentOptions(sO) + , SegmentName(sN) , SegmentBounds(sB) , Palette(p) {}; @@ -693,6 +695,7 @@ WLED_GLOBAL send_notification_t notifyG _INIT(0b00001111); #define receiveNotificationEffects receiveN.Effects #define receiveNotificationPalette receiveN.Palette #define receiveSegmentOptions receiveN.SegmentOptions +#define receiveSegmentName receiveN.SegmentName #define receiveSegmentBounds receiveN.SegmentBounds #define receiveDirect receiveN.Direct #define notifyDirect notifyG.Direct @@ -705,6 +708,7 @@ WLED_GLOBAL bool receiveNotificationColor _INIT(true); // apply color WLED_GLOBAL bool receiveNotificationEffects _INIT(true); // apply effects setup WLED_GLOBAL bool receiveNotificationPalette _INIT(true); // apply palette WLED_GLOBAL bool receiveSegmentOptions _INIT(false); // apply segment options +WLED_GLOBAL bool receiveSegmentName _INIT(false); WLED_GLOBAL bool receiveSegmentBounds _INIT(false); // apply segment bounds (start, stop, offset) WLED_GLOBAL bool receiveDirect _INIT(true); // receive UDP/Hyperion realtime WLED_GLOBAL bool notifyDirect _INIT(false); // send notification if change via UI or HTTP API diff --git a/wled00/xml.cpp b/wled00/xml.cpp index dc36e29451..700f5ecd74 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -417,6 +417,7 @@ void getSettingsJS(byte subPage, Print& settingsScript) printSetFormCheckbox(settingsScript,PSTR("RX"),receiveNotificationEffects); printSetFormCheckbox(settingsScript,PSTR("RP"),receiveNotificationPalette); printSetFormCheckbox(settingsScript,PSTR("SO"),receiveSegmentOptions); + printSetFormCheckbox(settingsScript,PSTR("SN"),receiveSegmentName); printSetFormCheckbox(settingsScript,PSTR("SG"),receiveSegmentBounds); printSetFormCheckbox(settingsScript,PSTR("SS"),sendNotifications); printSetFormCheckbox(settingsScript,PSTR("SD"),notifyDirect);