Skip to content

Commit c8757d4

Browse files
committed
fix more nitpicks comments
1 parent 62fad4d commit c8757d4

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

usermods/udp_name_sync/udp_name_sync.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class UdpNameSync : public Usermod {
2222
inline bool isEnabled() const { return enabled; }
2323

2424
void setup() override {
25+
// Enabled when this usermod is compiled, set to false if you prefer runtime opt-in
2526
enable(true);
2627
}
2728

@@ -30,12 +31,16 @@ class UdpNameSync : public Usermod {
3031
if (!WLED_CONNECTED) return;
3132
if (!udpConnected) return;
3233
Segment& mainseg = strip.getMainSegment();
33-
if (!strlen(segmentName) && !mainseg.name) return; //name was never set, do nothing
34+
if (segmentName[0] == '\0' && !mainseg.name) return; //name was never set, do nothing
35+
36+
const char* curName = mainseg.name ? mainseg.name : "";
37+
if (strncmp(curName, segmentName, sizeof(segmentName)) == 0) return; // same name, do nothing
3438

3539
IPAddress broadcastIp = uint32_t(Network.localIP()) | ~uint32_t(Network.subnetMask());
3640
byte udpOut[WLED_MAX_SEGNAME_LEN + 2];
37-
udpOut[0] = kPacketType; // custom usermod packet type (avoid 0..5 used by core protocols)
38-
if (strlen(segmentName) && !mainseg.name) { // name cleared
41+
udpOut[0] = kPacketType; // custom usermod packet type (avoid 0..5 used by core protocols)
42+
43+
if (segmentName[0] != '\0' && !mainseg.name) { // name cleared
3944
notifierUdp.beginPacket(broadcastIp, udpPort);
4045
segmentName[0] = '\0';
4146
DEBUG_PRINTLN(F("UdpNameSync: sending empty name"));
@@ -45,19 +50,17 @@ class UdpNameSync : public Usermod {
4550
return;
4651
}
4752

48-
const char* curName = mainseg.name ? mainseg.name : "";
49-
if (strncmp(curName, segmentName, sizeof(segmentName)) == 0) return; // same name, do nothing
50-
5153
notifierUdp.beginPacket(broadcastIp, udpPort);
5254
DEBUG_PRINT(F("UdpNameSync: saving segment name "));
53-
DEBUG_PRINTLN(mainseg.name);
5455
DEBUG_PRINTLN(curName);
55-
strlcpy(segmentName, mainseg.name, sizeof(segmentName));
56+
strlcpy(segmentName, curName, sizeof(segmentName));
5657
strlcpy((char *)&udpOut[1], segmentName, sizeof(udpOut) - 1); // leave room for header byte
57-
notifierUdp.write(udpOut, 2 + strnlen((char *)&udpOut[1], sizeof(udpOut) - 1));
58+
size_t nameLen = strnlen((char *)&udpOut[1], sizeof(udpOut) - 1);
59+
notifierUdp.write(udpOut, 2 + nameLen);
5860
notifierUdp.endPacket();
5961
DEBUG_PRINT(F("UdpNameSync: Sent segment name : "));
6062
DEBUG_PRINTLN(segmentName);
63+
return;
6164
}
6265

6366
bool onUdpPacket(uint8_t * payload, size_t len) override {
@@ -78,10 +81,5 @@ class UdpNameSync : public Usermod {
7881
}
7982
};
8083

81-
82-
// add more strings here to reduce flash memory usage
83-
const char UdpNameSync::_name[] PROGMEM = "UdpNameSync";
84-
const char UdpNameSync::_enabled[] PROGMEM = "enabled";
85-
8684
static UdpNameSync udp_name_sync;
8785
REGISTER_USERMOD(udp_name_sync);

0 commit comments

Comments
 (0)