Encapsulate 10 more read-only-from-outside Tier-2 globals - #5791
Conversation
Batch of the remaining confirmed "Do" items from the Tier-2 pass: each was verified to be read-only from every file except its owner (core files and usermods both checked), so each gets a by-value getter rather than a mutable reference - an accidental external write is now a build error instead of a silent bug. - selectedWiFi (wled.cpp owns) -> getSelectedWiFi(), read-only in network.cpp - statusESPNow (wled.cpp owns) -> getStatusESPNow(), read-only in udp.cpp - serialCanRX (wled.cpp owns) -> isSerialCanRX(), read-only in wled_serial.cpp - ntpLocalPort (wled.cpp owns) -> getNtpLocalPort(), read-only in set.cpp - unusual case: nothing in the codebase writes it beyond its default, so it's a static constexpr instead of a mutable static - doCloseFile (file.cpp owns) -> isDoCloseFile(), read-only in wled.cpp - currentLedmap (FX_fcn.cpp owns) -> getCurrentLedmap(), read-only in json.cpp - hueError (hue.cpp owns) -> getHueError(), read-only in xml.cpp - nightlightDelayMs(led.cpp owns) -> getNightlightDelayMs(), read-only in json.cpp - ledMaps (util.cpp owns) -> getLedMaps(), read-only in json.cpp (kept the existing WLED_MAX_LEDMAPS>16 uint32_t/uint16_t type split) - improvError (improv.cpp owns) -> getImprovError(), read-only in wled.cpp No behavior change - purely a storage/access-pattern change. Bundled as one PR since each is a small, independent, low-risk single-getter change of the same shape - not worth 10 separate review cycles. Verified: - esp32dev and nodemcuv2 both build and link cleanly via `pio run`. - usermods env (builds all 59 usermods) builds and links cleanly via `pio run -e usermods` - confirms none of these 10 have an external usermod consumer that would have broken. - Repo-wide grep confirms no remaining raw references to any of the 10 identifiers outside their owning file. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
WalkthroughWLED runtime globals were moved from public header declarations to file-private state with read-only accessors. JSON, network, serial, ESP-NOW, file, Improv, and Hue code now use those accessors. ChangesRuntime state encapsulation
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@wled00/wled.h`:
- Line 345: Document the intentional breaking API change for out-of-tree
usermods caused by removing the listed globals from wled.h. Add migration
guidance directing callers to getSelectedWiFi(), isSerialCanRX(),
getStatusESPNow(), getNtpLocalPort(), isDoCloseFile(), getCurrentLedmap(),
getHueError(), getImprovError(), getNightlightDelayMs(), and getLedMaps(), or
explicitly state that existing consumers must port to these replacement getters.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 9c2b6212-8c21-47cd-9db9-89752d8046fa
📒 Files selected for processing (15)
wled00/FX_fcn.cppwled00/fcn_declare.hwled00/file.cppwled00/hue.cppwled00/improv.cppwled00/json.cppwled00/led.cppwled00/network.cppwled00/set.cppwled00/udp.cppwled00/util.cppwled00/wled.cppwled00/wled.hwled00/wled_serial.cppwled00/xml.cpp
Summary
Batch of the remaining confirmed "Do" items from the Tier-2 pass (see #5777-#5790, #12 for earlier ones). Each of these 10 was verified to be read-only from every file except its owner (checked both core files and usermods), so each gets a by-value getter rather than a mutable reference — an accidental external write is now a build error instead of a silent bug, not just a rename.
selectedWiFiwled.cppnetwork.cppgetSelectedWiFi()statusESPNowwled.cppudp.cppgetStatusESPNow()serialCanRXwled.cppwled_serial.cppisSerialCanRX()ntpLocalPortwled.cppset.cppgetNtpLocalPort()— unusual: nothing in the codebase writes it beyond its default, so it's astatic constexprrather than a mutable staticdoCloseFilefile.cppwled.cppisDoCloseFile()currentLedmapFX_fcn.cppjson.cppgetCurrentLedmap()hueErrorhue.cppxml.cppgetHueError()nightlightDelayMsled.cppjson.cppgetNightlightDelayMs()ledMapsutil.cppjson.cppgetLedMaps()(kept the existingWLED_MAX_LEDMAPS>16uint32_t/uint16_ttype split)improvErrorimprov.cppwled.cppgetImprovError()No behavior change — purely a storage/access-pattern change. Bundled as one PR since each is a small, independent, low-risk single-getter change of the same shape — not worth 10 separate review cycles.
Test plan
esp32devandnodemcuv2: both build and link cleanly viapio run.usermodsenv (builds all 59 usermods): builds and links cleanly viapio run -e usermods— confirms none of these 10 have an external usermod consumer that would have broken (two earlier PRs in this series each found one that did).🤖 Generated with Claude Code
Summary by CodeRabbit