fix nitpicks from coderabbit

This commit is contained in:
Arthur Suzuki
2025-08-28 10:49:27 +02:00
parent f8ce5980a1
commit a60be251d2

View File

@@ -5,8 +5,6 @@ class UdpNameSync : public Usermod {
private: private:
bool enabled = false; bool enabled = false;
bool initDone = false;
unsigned long lastTime = 0;
char segmentName[WLED_MAX_SEGNAME_LEN] = {0}; char segmentName[WLED_MAX_SEGNAME_LEN] = {0};
static const char _name[]; static const char _name[];
static const char _enabled[]; static const char _enabled[];
@@ -15,15 +13,14 @@ class UdpNameSync : public Usermod {
/** /**
* Enable/Disable the usermod * Enable/Disable the usermod
*/ */
inline void enable(bool enable) { enabled = enable; } inline void enable(bool value) { enabled = value; }
/** /**
* Get usermod enabled/disabled state * Get usermod enabled/disabled state
*/ */
inline bool isEnabled() { return enabled; } inline bool isEnabled() const { return enabled; }
void setup() override { void setup() override {
initDone = true;
} }
void loop() override { void loop() override {
@@ -32,10 +29,9 @@ class UdpNameSync : public Usermod {
Segment& mainseg = strip.getMainSegment(); Segment& mainseg = strip.getMainSegment();
if (!strlen(segmentName) && !mainseg.name) return; //name was never set, do nothing 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]; 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 if (strlen(segmentName) && !mainseg.name) { // name cleared
notifierUdp.beginPacket(broadcastIp, udpPort); notifierUdp.beginPacket(broadcastIp, udpPort);
segmentName[0] = '\0'; segmentName[0] = '\0';
@@ -52,7 +48,6 @@ class UdpNameSync : public Usermod {
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(mainseg.name);
size_t length = strlen(mainseg.name);
strlcpy(segmentName, mainseg.name, sizeof(segmentName)); strlcpy(segmentName, mainseg.name, 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)); notifierUdp.write(udpOut, 2 + strnlen((char *)&udpOut[1], sizeof(udpOut) - 1));