Skip to content

Commit a60be25

Browse files
committed
fix nitpicks from coderabbit
1 parent f8ce598 commit a60be25

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

usermods/udp_name_sync/udp_name_sync.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ class UdpNameSync : public Usermod {
55
private:
66

77
bool enabled = false;
8-
bool initDone = false;
9-
unsigned long lastTime = 0;
108
char segmentName[WLED_MAX_SEGNAME_LEN] = {0};
119
static const char _name[];
1210
static const char _enabled[];
@@ -15,15 +13,14 @@ class UdpNameSync : public Usermod {
1513
/**
1614
* Enable/Disable the usermod
1715
*/
18-
inline void enable(bool enable) { enabled = enable; }
16+
inline void enable(bool value) { enabled = value; }
1917

2018
/**
2119
* Get usermod enabled/disabled state
2220
*/
23-
inline bool isEnabled() { return enabled; }
21+
inline bool isEnabled() const { return enabled; }
2422

2523
void setup() override {
26-
initDone = true;
2724
}
2825

2926
void loop() override {
@@ -32,10 +29,9 @@ class UdpNameSync : public Usermod {
3229
Segment& mainseg = strip.getMainSegment();
3330
if (!strlen(segmentName) && !mainseg.name) return; //name was never set, do nothing
3431

35-
IPAddress broadcastIp = ~uint32_t(Network.subnetMask()) | uint32_t(Network.gatewayIP());
32+
IPAddress broadcastIp = uint32_t(Network.localIP()) | ~uint32_t(Network.subnetMask());
3633
byte udpOut[WLED_MAX_SEGNAME_LEN + 2];
37-
udpOut[0] = 200; // 0: wled notifier protocol, 1: warls protocol, 2 is free
38-
34+
udpOut[0] = 200; // custom usermod packet type (avoid 0..5 used by core protocols)
3935
if (strlen(segmentName) && !mainseg.name) { // name cleared
4036
notifierUdp.beginPacket(broadcastIp, udpPort);
4137
segmentName[0] = '\0';
@@ -52,7 +48,6 @@ class UdpNameSync : public Usermod {
5248
notifierUdp.beginPacket(broadcastIp, udpPort);
5349
DEBUG_PRINT(F("UdpNameSync: saving segment name "));
5450
DEBUG_PRINTLN(mainseg.name);
55-
size_t length = strlen(mainseg.name);
5651
strlcpy(segmentName, mainseg.name, sizeof(segmentName));
5752
strlcpy((char *)&udpOut[1], segmentName, sizeof(udpOut) - 1); // leave room for header byte
5853
notifierUdp.write(udpOut, 2 + strnlen((char *)&udpOut[1], sizeof(udpOut) - 1));

0 commit comments

Comments
 (0)