fix more nitpicks comments
This commit is contained in:
@@ -22,6 +22,7 @@ class UdpNameSync : public Usermod {
|
|||||||
inline bool isEnabled() const { return enabled; }
|
inline bool isEnabled() const { return enabled; }
|
||||||
|
|
||||||
void setup() override {
|
void setup() override {
|
||||||
|
// Enabled when this usermod is compiled, set to false if you prefer runtime opt-in
|
||||||
enable(true);
|
enable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,12 +31,16 @@ class UdpNameSync : public Usermod {
|
|||||||
if (!WLED_CONNECTED) return;
|
if (!WLED_CONNECTED) return;
|
||||||
if (!udpConnected) return;
|
if (!udpConnected) return;
|
||||||
Segment& mainseg = strip.getMainSegment();
|
Segment& mainseg = strip.getMainSegment();
|
||||||
if (!strlen(segmentName) && !mainseg.name) return; //name was never set, do nothing
|
if (segmentName[0] == '\0' && !mainseg.name) return; //name was never set, do nothing
|
||||||
|
|
||||||
|
const char* curName = mainseg.name ? mainseg.name : "";
|
||||||
|
if (strncmp(curName, segmentName, sizeof(segmentName)) == 0) return; // same name, do nothing
|
||||||
|
|
||||||
IPAddress broadcastIp = uint32_t(Network.localIP()) | ~uint32_t(Network.subnetMask());
|
IPAddress broadcastIp = uint32_t(Network.localIP()) | ~uint32_t(Network.subnetMask());
|
||||||
byte udpOut[WLED_MAX_SEGNAME_LEN + 2];
|
byte udpOut[WLED_MAX_SEGNAME_LEN + 2];
|
||||||
udpOut[0] = kPacketType; // custom usermod packet type (avoid 0..5 used by core protocols)
|
udpOut[0] = kPacketType; // custom usermod packet type (avoid 0..5 used by core protocols)
|
||||||
if (strlen(segmentName) && !mainseg.name) { // name cleared
|
|
||||||
|
if (segmentName[0] != '\0' && !mainseg.name) { // name cleared
|
||||||
notifierUdp.beginPacket(broadcastIp, udpPort);
|
notifierUdp.beginPacket(broadcastIp, udpPort);
|
||||||
segmentName[0] = '\0';
|
segmentName[0] = '\0';
|
||||||
DEBUG_PRINTLN(F("UdpNameSync: sending empty name"));
|
DEBUG_PRINTLN(F("UdpNameSync: sending empty name"));
|
||||||
@@ -45,19 +50,17 @@ class UdpNameSync : public Usermod {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* curName = mainseg.name ? mainseg.name : "";
|
|
||||||
if (strncmp(curName, segmentName, sizeof(segmentName)) == 0) return; // same name, do nothing
|
|
||||||
|
|
||||||
notifierUdp.beginPacket(broadcastIp, udpPort);
|
notifierUdp.beginPacket(broadcastIp, udpPort);
|
||||||
DEBUG_PRINT(F("UdpNameSync: saving segment name "));
|
DEBUG_PRINT(F("UdpNameSync: saving segment name "));
|
||||||
DEBUG_PRINTLN(mainseg.name);
|
|
||||||
DEBUG_PRINTLN(curName);
|
DEBUG_PRINTLN(curName);
|
||||||
strlcpy(segmentName, mainseg.name, sizeof(segmentName));
|
strlcpy(segmentName, curName, sizeof(segmentName));
|
||||||
strlcpy((char *)&udpOut[1], segmentName, sizeof(udpOut) - 1); // leave room for header byte
|
strlcpy((char *)&udpOut[1], segmentName, sizeof(udpOut) - 1); // leave room for header byte
|
||||||
notifierUdp.write(udpOut, 2 + strnlen((char *)&udpOut[1], sizeof(udpOut) - 1));
|
size_t nameLen = strnlen((char *)&udpOut[1], sizeof(udpOut) - 1);
|
||||||
|
notifierUdp.write(udpOut, 2 + nameLen);
|
||||||
notifierUdp.endPacket();
|
notifierUdp.endPacket();
|
||||||
DEBUG_PRINT(F("UdpNameSync: Sent segment name : "));
|
DEBUG_PRINT(F("UdpNameSync: Sent segment name : "));
|
||||||
DEBUG_PRINTLN(segmentName);
|
DEBUG_PRINTLN(segmentName);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onUdpPacket(uint8_t * payload, size_t len) override {
|
bool onUdpPacket(uint8_t * payload, size_t len) override {
|
||||||
@@ -78,10 +81,5 @@ class UdpNameSync : public Usermod {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// add more strings here to reduce flash memory usage
|
|
||||||
const char UdpNameSync::_name[] PROGMEM = "UdpNameSync";
|
|
||||||
const char UdpNameSync::_enabled[] PROGMEM = "enabled";
|
|
||||||
|
|
||||||
static UdpNameSync udp_name_sync;
|
static UdpNameSync udp_name_sync;
|
||||||
REGISTER_USERMOD(udp_name_sync);
|
REGISTER_USERMOD(udp_name_sync);
|
||||||
|
|||||||
Reference in New Issue
Block a user