Encapsulate wled.cpp's own runtime state as static, not global - #5778
Encapsulate wled.cpp's own runtime state as static, not global#5778netmindz wants to merge 1 commit into
Conversation
8 WLED_GLOBAL variables were referenced only in wled.cpp: ddp, e131 (the ESPAsyncE131 sender objects), lastMqttReconnectAttempt, lastReconnectAttempt, ledStatusLastMillis, ledStatusState, ledStatusType, udpRgbPort. Converted all 8 to file-local `static`, preserving the #if defined(STATUSLED) guard around the three ledStatus* variables and using direct constructor syntax for the two ESPAsyncE131 objects (equivalent to what WLED_GLOBAL/_INIT_N expanded to when wled.cpp itself was the definition TU). No behavior change - purely a storage-class change. Verified: esp32dev builds and links cleanly via `pio run -e esp32dev` (1,320,323 bytes flash, no warnings from either changed file). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UtCyBD91vAYWvBzaMyQSHd
WalkthroughThe change moves MQTT, WiFi, UDP RGB, E1.31/DDP, and status LED runtime state into file-local declarations in ChangesRuntime state privacy
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
||
| // Runtime state private to this file - previously WLED_GLOBAL, a leftover from | ||
| // when all state lived in one big extern block regardless of who used it. | ||
| static unsigned long lastMqttReconnectAttempt = 0; // used for other periodic tasks too |
There was a problem hiding this comment.
@coderabbitai please double-check if any of these now static variables is used in any usermod/
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- Usermod directories ---'
fd --type d --ignore-case 'usermod' . || true
printf '%s\n' '--- Direct identifier references in usermod-related C++ files ---'
rg -n -P -i \
--glob '*.{c,cc,cpp,cxx,h,hpp,ino}' \
--glob '*usermod*/*' \
'\b(ddp|e131|lastMqttReconnectAttempt|lastReconnectAttempt|ledStatusLastMillis|ledStatusState|ledStatusType|udpRgbPort)\b' \
. || true
printf '%s\n' '--- Usermod-related C++ filenames found by path ---'
fd --type f --ignore-case 'usermod' . -e c -e cc -e cpp -e cxx -e h -e hpp -e ino || trueLength of output: 9445
@softhack007, I found no direct references to any of the eight variables in usermods/.
The only usermod search result was a comment in usermods/audioreactive/audio_reactive.cpp that mentions the E1.31 protocol. It does not reference the e131 object.
The new file-local static declarations do not break an in-tree usermod reference.
You are interacting with an AI system.
Summary
Part of an ongoing pass identifying
WLED_GLOBALdeclarations that are actually only referenced in one file (see #5777 for the first of these). 8 more turned out to be private towled.cppitself:ddp,e131(theESPAsyncE131sender objects),lastMqttReconnectAttempt,lastReconnectAttempt,ledStatusLastMillis,ledStatusState,ledStatusType,udpRgbPort.Converted all 8 to file-local
static:ledStatus*variables keep their original#if defined(STATUSLED)guard.ddp/e131use direct constructor syntax (static ESPAsyncE131 e131(handleE131Packet);), equivalent to whatWLED_GLOBAL ESPAsyncE131 e131 _INIT_N(((handleE131Packet)));expanded to whenwled.cppitself was the definition translation unit (WLED_DEFINE_GLOBAL_VARS).No behavior change — purely a storage-class change, same types and initial values as before.
Test plan
esp32dev: builds and links cleanly viapio run -e esp32dev— 1,320,323 bytes flash, no warnings.wled00/,usermods/) that none of the 8 converted variables are referenced outsidewled.cpp.🤖 Generated with Claude Code
Summary by CodeRabbit