From a60be251d237b20f86ee8c413eba52cca9509473 Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Thu, 28 Aug 2025 10:49:27 +0200 Subject: [PATCH] fix nitpicks from coderabbit --- usermods/udp_name_sync/udp_name_sync.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/usermods/udp_name_sync/udp_name_sync.cpp b/usermods/udp_name_sync/udp_name_sync.cpp index d7f67117e..fdeda78a9 100644 --- a/usermods/udp_name_sync/udp_name_sync.cpp +++ b/usermods/udp_name_sync/udp_name_sync.cpp @@ -5,8 +5,6 @@ class UdpNameSync : public Usermod { private: bool enabled = false; - bool initDone = false; - unsigned long lastTime = 0; char segmentName[WLED_MAX_SEGNAME_LEN] = {0}; static const char _name[]; static const char _enabled[]; @@ -15,15 +13,14 @@ class UdpNameSync : public Usermod { /** * Enable/Disable the usermod */ - inline void enable(bool enable) { enabled = enable; } + inline void enable(bool value) { enabled = value; } /** * Get usermod enabled/disabled state */ - inline bool isEnabled() { return enabled; } + inline bool isEnabled() const { return enabled; } void setup() override { - initDone = true; } void loop() override { @@ -32,10 +29,9 @@ class UdpNameSync : public Usermod { Segment& mainseg = strip.getMainSegment(); if (!strlen(segmentName) && !mainseg.name) return; //name was never set, do nothing - IPAddress broadcastIp = ~uint32_t(Network.subnetMask()) | uint32_t(Network.gatewayIP()); + IPAddress broadcastIp = uint32_t(Network.localIP()) | ~uint32_t(Network.subnetMask()); byte udpOut[WLED_MAX_SEGNAME_LEN + 2]; - udpOut[0] = 200; // 0: wled notifier protocol, 1: warls protocol, 2 is free - + udpOut[0] = 200; // custom usermod packet type (avoid 0..5 used by core protocols) if (strlen(segmentName) && !mainseg.name) { // name cleared notifierUdp.beginPacket(broadcastIp, udpPort); segmentName[0] = '\0'; @@ -52,7 +48,6 @@ class UdpNameSync : public Usermod { notifierUdp.beginPacket(broadcastIp, udpPort); DEBUG_PRINT(F("UdpNameSync: saving segment name ")); DEBUG_PRINTLN(mainseg.name); - size_t length = strlen(mainseg.name); strlcpy(segmentName, mainseg.name, sizeof(segmentName)); strlcpy((char *)&udpOut[1], segmentName, sizeof(udpOut) - 1); // leave room for header byte notifierUdp.write(udpOut, 2 + strnlen((char *)&udpOut[1], sizeof(udpOut) - 1));