Skip to content

Conversation

@DedeHai
Copy link
Collaborator

@DedeHai DedeHai commented Dec 21, 2025

Summary by CodeRabbit

  • Refactor
    • Standardized JSON-buffer locking across the codebase by replacing numeric lock IDs with named lock identifiers.
    • Introduced explicit lock identifiers for distinct JSON operations to improve clarity and future maintainability.
    • No user-facing functionality, configuration signatures, or behavior changes; existing behavior and error handling remain the same.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 21, 2025

Walkthrough

Replaces hard-coded numeric JSON buffer lock IDs with named JSON_LOCK_* constants across many modules, adds those constants to wled00/const.h, and changes default JSON lock parameter to JSON_LOCK_UNKNOWN for lock requests and the JSONBufferGuard constructor.

Changes

Cohort / File(s) Summary
Constants Definition
wled00/const.h
Adds JSON_LOCK_UNKNOWN and a sequence of JSON_LOCK_* macros mapping previous numeric lock IDs to named constants (CFG_DES, CFG_SER, CFG_SEC_DES, CFG_SEC_SER, SETTINGS, XML, LEDMAP, PRESET_LOAD, PRESET_SAVE, WS_RECEIVE, WS_SEND, IR, SERVER, MQTT, SERIAL, SERVEJSON, NOTIFY, PRESET_NAME, LEDGAP, LEDMAP_ENUM, REMOTE).
Function Declarations / RAII Guard
wled00/fcn_declare.h
Changes default parameter from 255 to JSON_LOCK_UNKNOWN for requestJSONBufferLock(uint8_t moduleID=...) and JSONBufferGuard constructor.
Configuration Management
wled00/cfg.cpp
Replaces numeric lock IDs with JSON_LOCK_CFG_DES, JSON_LOCK_CFG_SER, JSON_LOCK_CFG_SEC_DES, JSON_LOCK_CFG_SEC_SER in config (de)serialization paths.
Preset Handling
wled00/presets.cpp
Uses JSON_LOCK_PRESET_SAVE, JSON_LOCK_PRESET_NAME, JSON_LOCK_PRESET_LOAD instead of hard-coded IDs in save/load/preset-name flows.
Communication & API
wled00/mqtt.cpp, wled00/json.cpp, wled00/wled_server.cpp, wled00/ws.cpp, wled00/wled_serial.cpp, wled00/udp.cpp
Replace magic lock numbers with JSON_LOCK_MQTT, JSON_LOCK_SERVEJSON, JSON_LOCK_SERVER, JSON_LOCK_WS_RECEIVE, JSON_LOCK_WS_SEND, JSON_LOCK_SERIAL, JSON_LOCK_NOTIFY in MQTT, HTTP/json, WebSocket, serial, and UDP handling.
Settings & Feature Modules
wled00/set.cpp, wled00/ir.cpp, wled00/util.cpp, usermods/usermod_v2_RF433/usermod_v2_RF433.cpp, wled00/remote.cpp
Replace numeric lock IDs with JSON_LOCK_SETTINGS, JSON_LOCK_IR, JSON_LOCK_LEDMAP_ENUM, JSON_LOCK_REMOTE in settings, IR, LED map enumeration, remote/usermod handling.
LED Effect Processing
wled00/FX_fcn.cpp, wled00/FX_2Dfcn.cpp
Replace numeric lock IDs with JSON_LOCK_LEDMAP and JSON_LOCK_LEDGAP for LED map/gap JSON access.
XML / Usermod Pins
wled00/xml.cpp
Replaces numeric lock ID with JSON_LOCK_XML when parsing usermod pins.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Changes are widespread but homogeneous (literal → named-constant replacements) with one API default change.
  • Review focus:
    • Verify mapping values in wled00/const.h exactly match prior numeric IDs.
    • Confirm the new default JSON_LOCK_UNKNOWN (was 255) preserves intended behavior where omitted.
    • Spot-check a few callsites to ensure no accidental misuse of the wrong constant (e.g., neighboring lock values).

Possibly related PRs

Suggested reviewers

  • willmmiles
  • blazoncek

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 39.13% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing hard-coded numeric lock identifiers with named constants throughout the codebase.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 809732b and e43a7b8.

📒 Files selected for processing (2)
  • wled00/remote.cpp (1 hunks)
  • wled00/xml.cpp (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
wled00/**/*.cpp

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use 2-space indentation for C++ source files (.cpp)

Files:

  • wled00/remote.cpp
  • wled00/xml.cpp
🧠 Learnings (3)
📓 Common learnings
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:11.994Z
Learning: In WLED code reviews, when code is modified or added, look for "magic numbers" (hardcoded numeric literals) and suggest replacing them with appropriate defined constants when those constants are meaningful in the context of the PR. For example, the hardcoded value 32 should be replaced with WLED_MAX_SEGNAME_LEN when it represents a segment name length limit. This improves code maintainability and reduces the risk of inconsistencies.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:30.955Z
Learning: In WLED code reviews, when code is modified or added, look for "magic numbers" (hardcoded numeric literals) and suggest replacing them with defined constants when meaningful constants exist in the codebase. For example, suggest replacing hardcoded "32" with WLED_MAX_SEGNAME_LEN if the context relates to segment name length limits.
Learnt from: mval-sg
Repo: wled/WLED PR: 4876
File: wled00/xml.cpp:0-0
Timestamp: 2025-08-28T08:09:20.630Z
Learning: The WLED codebase has opportunities for refactoring hardcoded array bounds (like the "15" used for DMX channels) to use sizeof(array)/sizeof(array[0]) for more maintainable code, but such changes should be done consistently across the entire codebase in a dedicated refactoring effort.
Learnt from: DedeHai
Repo: wled/WLED PR: 4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR #4798, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:30.955Z
Learning: In WLED code reviews, verify that file operations (especially file.open()) respect LittleFS filename limitations. Assume default WLED configuration with LittleFS default filename limit of 255 bytes. Do not assume extreme configuration values like WLED_MAX_SEGNAME_LEN = 512 which would not be standard configurations.
Learnt from: DedeHai
Repo: wled/WLED PR: 4791
File: wled00/util.cpp:737-743
Timestamp: 2025-09-15T19:13:56.469Z
Learning: In WLED's util.cpp, the *_realloc_malloc functions (p_realloc_malloc and d_realloc_malloc) are intentionally designed to free the original buffer on realloc failure and allocate a new buffer, implementing a "replace buffer" semantic rather than traditional realloc behavior. This is documented in the function comments and is the intended design by the author DedeHai.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:11.994Z
Learning: In WLED code reviews, file operations (especially file.open()) should be checked to ensure they respect LittleFS filename limitations. The default LittleFS filename limit is 255 bytes (LFS_NAME_MAX). Reviews should assume default WLED configuration defines and not extreme edge-case values (e.g., WLED_MAX_SEGNAME_LEN = 512 would not be standard). File paths should be validated to stay within the 255-byte limit.
Learnt from: BobLoeffler68
Repo: wled/WLED PR: 4891
File: wled00/FX.cpp:3333-3349
Timestamp: 2025-08-31T03:38:14.114Z
Learning: WLED PacMan effect (wled00/FX.cpp): Keep pacmancharacters_t position fields as signed int (not int16_t). Maintainer preference (blazoncek) prioritizes avoiding potential overhead/regressions over minor RAM savings. Avoid type shrinking here unless memory pressure is demonstrated.
Learnt from: BobLoeffler68
Repo: wled/WLED PR: 5109
File: wled00/FX.cpp:3174-3343
Timestamp: 2025-11-27T06:33:11.436Z
Learning: WLED Ants effect (wled00/FX.cpp): The author prefers the current velocity initialization using hw_random16(1000, 5000)/5000.0f, resulting in an effective range of ~3.6–10.0 (with VELOCITY_MIN=2.0, VELOCITY_MAX=10.0), and wants the code kept as-is with comments updated to document this behavior. Avoid suggesting changes to span the full 2.0–10.0 range in future reviews.
📚 Learning: 2025-11-14T13:37:11.994Z
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:11.994Z
Learning: In WLED code reviews, when code is modified or added, look for "magic numbers" (hardcoded numeric literals) and suggest replacing them with appropriate defined constants when those constants are meaningful in the context of the PR. For example, the hardcoded value 32 should be replaced with WLED_MAX_SEGNAME_LEN when it represents a segment name length limit. This improves code maintainability and reduces the risk of inconsistencies.

Applied to files:

  • wled00/remote.cpp
  • wled00/xml.cpp
📚 Learning: 2025-11-14T13:37:30.955Z
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:30.955Z
Learning: In WLED code reviews, when code is modified or added, look for "magic numbers" (hardcoded numeric literals) and suggest replacing them with defined constants when meaningful constants exist in the codebase. For example, suggest replacing hardcoded "32" with WLED_MAX_SEGNAME_LEN if the context relates to segment name length limits.

Applied to files:

  • wled00/remote.cpp
🧬 Code graph analysis (1)
wled00/xml.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
🔇 Additional comments (2)
wled00/remote.cpp (1)

123-123: LGTM! Excellent improvement to code maintainability.

The replacement of the hardcoded lock ID 22 with the named constant JSON_LOCK_REMOTE improves code readability and aligns with WLED best practices for eliminating magic numbers.

Based on learnings, replacing magic numbers with defined constants is a preferred practice in the WLED codebase.

wled00/xml.cpp (1)

102-102: Excellent refactoring - magic number replaced with named constant.

This change improves code maintainability by replacing the hardcoded lock ID 6 with the self-documenting constant JSON_LOCK_XML, making the lock's purpose immediately clear and reducing the risk of inconsistencies.

Based on learnings, this type of refactoring aligns with WLED coding standards.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
wled00/udp.cpp (1)

333-339: Bug: segment check flags all assigned into check1

In parseNotifyPacket(), the three check bits from udpIn[31+ofs] are decoded but all stored into selseg.check1:

selseg.check1  = (udpIn[31+ofs]>>5) & 0x1;
selseg.check1  = (udpIn[31+ofs]>>6) & 0x1;
selseg.check1  = (udpIn[31+ofs]>>7) & 0x1;

This appears to be a copy/paste error; check2 and check3 are never set, and check1 is overwritten twice.

Proposed fix for the check flag assignments
-          selseg.check1  = (udpIn[31+ofs]>>5) & 0x1;
-          selseg.check1  = (udpIn[31+ofs]>>6) & 0x1;
-          selseg.check1  = (udpIn[31+ofs]>>7) & 0x1;
+          selseg.check1  = (udpIn[31+ofs]>>5) & 0x1;
+          selseg.check2  = (udpIn[31+ofs]>>6) & 0x1;
+          selseg.check3  = (udpIn[31+ofs]>>7) & 0x1;
🧹 Nitpick comments (2)
wled00/fcn_declare.h (1)

397-498: Default JSON lock constant is appropriate; consider aligning JSONBufferGuard too

Using JSON_LOCK_UNKNOWN as the default for requestJSONBufferLock() matches the new lock ID scheme and keeps behavior unchanged.

For consistency with this refactor, you could also change JSONBufferGuard’s default constructor argument from 255 to JSON_LOCK_UNKNOWN so there are no remaining literal “unknown lock” IDs in this header.

wled00/const.h (1)

444-467: Excellent alignment with codebase standards—replacing magic numbers with named constants.

This addition properly eliminates magic numbers, improving maintainability. The naming convention is clear and consistent.

Note: Gap at value 8

The sequence jumps from 7 to 9, skipping 8. This appears intentional (present in the initial design), but lacks documentation. If 8 is reserved for future use or a deprecated lock type, consider clarifying with a brief comment:

 #define JSON_LOCK_LEDMAP           7
+// Lock ID 8 is reserved
 #define JSON_LOCK_PRESET_LOAD      9

Optional: Enhanced documentation

The section comment "JSON buffer lock owners" is minimal. Consider expanding it to clarify purpose for future maintainers:

-// JSON buffer lock owners
+// JSON buffer lock owners - identifies which component currently holds the shared JSON buffer lock
 #define JSON_LOCK_UNKNOWN        255

All 22 lock identifiers are properly used throughout the codebase via named constants—no hardcoded numeric lock IDs remain.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 304c59e and 61fd6ca.

📒 Files selected for processing (16)
  • usermods/usermod_v2_RF433/usermod_v2_RF433.cpp (1 hunks)
  • wled00/FX_2Dfcn.cpp (1 hunks)
  • wled00/FX_fcn.cpp (1 hunks)
  • wled00/cfg.cpp (4 hunks)
  • wled00/const.h (1 hunks)
  • wled00/fcn_declare.h (1 hunks)
  • wled00/ir.cpp (1 hunks)
  • wled00/json.cpp (1 hunks)
  • wled00/mqtt.cpp (1 hunks)
  • wled00/presets.cpp (3 hunks)
  • wled00/set.cpp (1 hunks)
  • wled00/udp.cpp (1 hunks)
  • wled00/util.cpp (1 hunks)
  • wled00/wled_serial.cpp (1 hunks)
  • wled00/wled_server.cpp (1 hunks)
  • wled00/ws.cpp (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
wled00/**/!(html_*)*.h

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use 2-space indentation for non-generated C++ header files (.h)

Files:

  • wled00/fcn_declare.h
  • wled00/const.h
wled00/**/*.cpp

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use 2-space indentation for C++ source files (.cpp)

Files:

  • wled00/mqtt.cpp
  • wled00/udp.cpp
  • wled00/FX_fcn.cpp
  • wled00/ir.cpp
  • wled00/presets.cpp
  • wled00/json.cpp
  • wled00/wled_server.cpp
  • wled00/cfg.cpp
  • wled00/ws.cpp
  • wled00/set.cpp
  • wled00/util.cpp
  • wled00/FX_2Dfcn.cpp
  • wled00/wled_serial.cpp
🧠 Learnings (15)
📓 Common learnings
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:11.994Z
Learning: In WLED code reviews, when code is modified or added, look for "magic numbers" (hardcoded numeric literals) and suggest replacing them with appropriate defined constants when those constants are meaningful in the context of the PR. For example, the hardcoded value 32 should be replaced with WLED_MAX_SEGNAME_LEN when it represents a segment name length limit. This improves code maintainability and reduces the risk of inconsistencies.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:30.955Z
Learning: In WLED code reviews, when code is modified or added, look for "magic numbers" (hardcoded numeric literals) and suggest replacing them with defined constants when meaningful constants exist in the codebase. For example, suggest replacing hardcoded "32" with WLED_MAX_SEGNAME_LEN if the context relates to segment name length limits.
Learnt from: mval-sg
Repo: wled/WLED PR: 4876
File: wled00/xml.cpp:0-0
Timestamp: 2025-08-28T08:09:20.630Z
Learning: The WLED codebase has opportunities for refactoring hardcoded array bounds (like the "15" used for DMX channels) to use sizeof(array)/sizeof(array[0]) for more maintainable code, but such changes should be done consistently across the entire codebase in a dedicated refactoring effort.
Learnt from: DedeHai
Repo: wled/WLED PR: 4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR #4798, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:30.955Z
Learning: In WLED code reviews, verify that file operations (especially file.open()) respect LittleFS filename limitations. Assume default WLED configuration with LittleFS default filename limit of 255 bytes. Do not assume extreme configuration values like WLED_MAX_SEGNAME_LEN = 512 which would not be standard configurations.
Learnt from: DedeHai
Repo: wled/WLED PR: 4791
File: wled00/util.cpp:737-743
Timestamp: 2025-09-15T19:13:56.469Z
Learning: In WLED's util.cpp, the *_realloc_malloc functions (p_realloc_malloc and d_realloc_malloc) are intentionally designed to free the original buffer on realloc failure and allocate a new buffer, implementing a "replace buffer" semantic rather than traditional realloc behavior. This is documented in the function comments and is the intended design by the author DedeHai.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:11.994Z
Learning: In WLED code reviews, file operations (especially file.open()) should be checked to ensure they respect LittleFS filename limitations. The default LittleFS filename limit is 255 bytes (LFS_NAME_MAX). Reviews should assume default WLED configuration defines and not extreme edge-case values (e.g., WLED_MAX_SEGNAME_LEN = 512 would not be standard). File paths should be validated to stay within the 255-byte limit.
Learnt from: BobLoeffler68
Repo: wled/WLED PR: 4891
File: wled00/FX.cpp:3333-3349
Timestamp: 2025-08-31T03:38:14.114Z
Learning: WLED PacMan effect (wled00/FX.cpp): Keep pacmancharacters_t position fields as signed int (not int16_t). Maintainer preference (blazoncek) prioritizes avoiding potential overhead/regressions over minor RAM savings. Avoid type shrinking here unless memory pressure is demonstrated.
Learnt from: BobLoeffler68
Repo: wled/WLED PR: 5109
File: wled00/FX.cpp:3174-3343
Timestamp: 2025-11-27T06:33:11.436Z
Learning: WLED Ants effect (wled00/FX.cpp): The author prefers the current velocity initialization using hw_random16(1000, 5000)/5000.0f, resulting in an effective range of ~3.6–10.0 (with VELOCITY_MIN=2.0, VELOCITY_MAX=10.0), and wants the code kept as-is with comments updated to document this behavior. Avoid suggesting changes to span the full 2.0–10.0 range in future reviews.
📚 Learning: 2025-04-18T22:27:58.634Z
Learnt from: KrX3D
Repo: wled/WLED PR: 4237
File: usermods/INA219_v2/INA219_v2.cpp:265-276
Timestamp: 2025-04-18T22:27:58.634Z
Learning: When implementing MQTT message handling in WLED usermods, use `strstr(topic, "/specific/path")` instead of `strcmp_P(topic, PSTR("/specific/path"))` to properly match topics that include the device prefix. The full MQTT topic typically follows the pattern `<mqttDeviceTopic>/specific/path`.

Applied to files:

  • wled00/mqtt.cpp
📚 Learning: 2025-11-14T13:37:11.994Z
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:11.994Z
Learning: In WLED code reviews, when code is modified or added, look for "magic numbers" (hardcoded numeric literals) and suggest replacing them with appropriate defined constants when those constants are meaningful in the context of the PR. For example, the hardcoded value 32 should be replaced with WLED_MAX_SEGNAME_LEN when it represents a segment name length limit. This improves code maintainability and reduces the risk of inconsistencies.

Applied to files:

  • wled00/udp.cpp
  • wled00/const.h
  • wled00/wled_server.cpp
  • wled00/cfg.cpp
  • wled00/util.cpp
  • wled00/FX_2Dfcn.cpp
  • wled00/wled_serial.cpp
📚 Learning: 2025-08-26T11:51:21.817Z
Learnt from: DedeHai
Repo: wled/WLED PR: 4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR #4798, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.

Applied to files:

  • wled00/FX_fcn.cpp
  • wled00/FX_2Dfcn.cpp
📚 Learning: 2025-08-29T00:26:15.808Z
Learnt from: ksedgwic
Repo: wled/WLED PR: 4883
File: usermods/usermod_v2_skystrip/rest_json_client.h:6-14
Timestamp: 2025-08-29T00:26:15.808Z
Learning: WLED uses a vendored ArduinoJson library (version 6) located at "src/dependencies/json/ArduinoJson-v6.h" which is included through wled.h. Usermods should not directly include ArduinoJson headers but instead rely on wled.h for ArduinoJson symbols. The standard pattern is to include wled.h and use JsonObject, JsonArray, DynamicJsonDocument, etc. without additional includes.

Applied to files:

  • wled00/FX_fcn.cpp
  • wled00/json.cpp
  • wled00/const.h
  • wled00/wled_server.cpp
  • wled00/util.cpp
  • wled00/FX_2Dfcn.cpp
  • wled00/wled_serial.cpp
📚 Learning: 2025-08-31T03:38:14.114Z
Learnt from: BobLoeffler68
Repo: wled/WLED PR: 4891
File: wled00/FX.cpp:3333-3349
Timestamp: 2025-08-31T03:38:14.114Z
Learning: WLED PacMan effect (wled00/FX.cpp): Keep pacmancharacters_t position fields as signed int (not int16_t). Maintainer preference (blazoncek) prioritizes avoiding potential overhead/regressions over minor RAM savings. Avoid type shrinking here unless memory pressure is demonstrated.

Applied to files:

  • wled00/FX_fcn.cpp
📚 Learning: 2025-11-16T19:40:46.260Z
Learnt from: DedeHai
Repo: wled/WLED PR: 4926
File: wled00/FX.cpp:4727-4730
Timestamp: 2025-11-16T19:40:46.260Z
Learning: WLED AuroraWave (wled00/FX.cpp): wave_start and wave_end intentionally use int16_t; segments longer than 32k LEDs are not supported (bounded by MAX_LEDS), so widening to 32-bit is unnecessary.

Applied to files:

  • wled00/FX_fcn.cpp
  • wled00/FX_2Dfcn.cpp
📚 Learning: 2025-09-16T18:08:42.848Z
Learnt from: DedeHai
Repo: wled/WLED PR: 4939
File: wled00/FX_fcn.cpp:1176-1187
Timestamp: 2025-09-16T18:08:42.848Z
Learning: In WLED finalizeInit() bus creation (wled00/FX_fcn.cpp), intentionally allowing memory overruns when bus configurations exceed MAX_LED_MEMORY is a deliberate design choice. The trade-off prioritizes creating buses with reduced LED counts over completely failing to create buses, which would cause no LED output and UI failures. This approach forces users to update configurations after migrating to version 0.16 while maintaining basic functionality.

Applied to files:

  • wled00/FX_fcn.cpp
📚 Learning: 2025-09-01T10:26:17.959Z
Learnt from: mval-sg
Repo: wled/WLED PR: 4876
File: wled00/wled_eeprom.cpp:0-0
Timestamp: 2025-09-01T10:26:17.959Z
Learning: In WLED PR #4876, the DMXStartLED EEPROM backward compatibility issue was partially addressed by keeping it at address 2550 and reading it as a 16-bit value, with DMXChannelsValue array moved to addresses 2552-2566. This maintains compatibility with pre-0.11 EEPROM layouts for DMXStartLED, though legacy "Set to 255" (code 6) configurations may still need migration logic.

Applied to files:

  • wled00/FX_fcn.cpp
📚 Learning: 2025-11-27T06:33:11.436Z
Learnt from: BobLoeffler68
Repo: wled/WLED PR: 5109
File: wled00/FX.cpp:3174-3343
Timestamp: 2025-11-27T06:33:11.436Z
Learning: WLED Ants effect (wled00/FX.cpp): The author prefers the current velocity initialization using hw_random16(1000, 5000)/5000.0f, resulting in an effective range of ~3.6–10.0 (with VELOCITY_MIN=2.0, VELOCITY_MAX=10.0), and wants the code kept as-is with comments updated to document this behavior. Avoid suggesting changes to span the full 2.0–10.0 range in future reviews.

Applied to files:

  • wled00/FX_fcn.cpp
📚 Learning: 2025-09-12T17:29:43.826Z
Learnt from: DedeHai
Repo: wled/WLED PR: 4923
File: wled00/FX.cpp:4883-4901
Timestamp: 2025-09-12T17:29:43.826Z
Learning: In WLED’s web UI, only one slider value (e.g., SEGMENT.intensity or SEGMENT.custom1) changes at a time; code relying on this may use simplified change guards, though presets/JSON can still update multiple fields atomically.

Applied to files:

  • wled00/presets.cpp
📚 Learning: 2025-11-14T13:37:30.955Z
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:30.955Z
Learning: In WLED code reviews, when code is modified or added, look for "magic numbers" (hardcoded numeric literals) and suggest replacing them with defined constants when meaningful constants exist in the codebase. For example, suggest replacing hardcoded "32" with WLED_MAX_SEGNAME_LEN if the context relates to segment name length limits.

Applied to files:

  • wled00/const.h
  • wled00/wled_server.cpp
  • wled00/util.cpp
  • wled00/FX_2Dfcn.cpp
  • wled00/wled_serial.cpp
📚 Learning: 2025-10-05T15:24:05.545Z
Learnt from: CR
Repo: wled/WLED PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-05T15:24:05.545Z
Learning: Applies to wled00/html_*.h : DO NOT edit generated embedded web header files (wled00/html_*.h)

Applied to files:

  • wled00/const.h
  • wled00/util.cpp
  • wled00/FX_2Dfcn.cpp
📚 Learning: 2025-08-29T00:26:15.808Z
Learnt from: ksedgwic
Repo: wled/WLED PR: 4883
File: usermods/usermod_v2_skystrip/rest_json_client.h:6-14
Timestamp: 2025-08-29T00:26:15.808Z
Learning: In WLED projects, ArduinoJson.h is not directly included via #include <ArduinoJson.h> - the ArduinoJson symbols are made available through the WLED build system and wled.h transitive includes, so explicitly adding #include <ArduinoJson.h> is not necessary and may not work.

Applied to files:

  • wled00/const.h
  • wled00/wled_server.cpp
  • wled00/wled_serial.cpp
📚 Learning: 2025-08-28T08:09:20.630Z
Learnt from: mval-sg
Repo: wled/WLED PR: 4876
File: wled00/xml.cpp:0-0
Timestamp: 2025-08-28T08:09:20.630Z
Learning: The WLED codebase has opportunities for refactoring hardcoded array bounds (like the "15" used for DMX channels) to use sizeof(array)/sizeof(array[0]) for more maintainable code, but such changes should be done consistently across the entire codebase in a dedicated refactoring effort.

Applied to files:

  • wled00/wled_serial.cpp
🧬 Code graph analysis (13)
wled00/fcn_declare.h (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
wled00/mqtt.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
wled00/udp.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
wled00/FX_fcn.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
wled00/ir.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
wled00/json.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
wled00/wled_server.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
wled00/cfg.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
wled00/ws.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
wled00/set.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
usermods/usermod_v2_RF433/usermod_v2_RF433.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
wled00/FX_2Dfcn.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
wled00/wled_serial.cpp (1)
wled00/util.cpp (2)
  • requestJSONBufferLock (167-202)
  • requestJSONBufferLock (167-167)
🔇 Additional comments (14)
wled00/FX_fcn.cpp (1)

1968-2057: LED map JSON lock constant usage is correct and balanced

Switching to JSON_LOCK_LEDMAP here is consistent with the new lock IDs, and the acquire/release paths in deserializeMap() remain balanced (explicit release on error and before the final return).

wled00/ir.cpp (1)

554-631: IR JSON handler correctly uses JSON_LOCK_IR

Using JSON_LOCK_IR instead of the numeric ID improves traceability of who owns the JSON buffer, and decodeIRJson() still releases the lock on all paths after acquisition.

wled00/FX_2Dfcn.cpp (1)

51-98: Gap map JSON lock now uses JSON_LOCK_LEDGAP as intended

The change to JSON_LOCK_LEDGAP matches the new naming scheme, and the lock is still properly released after reading /2d-gaps.json, so behavior is preserved.

wled00/json.cpp (1)

1111-1192: serveJson uses JSON_LOCK_SERVEJSON consistently with RAII unlock

Swapping the literal lock ID for JSON_LOCK_SERVEJSON keeps the existing semantics: the lock is acquired once for the request and then released by LockedJsonResponse after the JSON payload has been sent (or on destruction), with the failure case still handled via deferResponse().

usermods/usermod_v2_RF433/usermod_v2_RF433.cpp (1)

121-175: RF433 remote JSON now uses JSON_LOCK_REMOTE with balanced locking

Using JSON_LOCK_REMOTE instead of the raw numeric ID cleanly identifies this usermod as the JSON buffer owner, and remoteJson433() still releases the lock in both the “no mapping found” path and the success path.

wled00/wled_server.cpp (1)

394-449: /json POST handler correctly switches to JSON_LOCK_SERVER

Replacing the numeric module ID with JSON_LOCK_SERVER keeps the JSON lock acquisition and release behavior intact in the /json POST handler and makes logging/diagnostics around JSON buffer ownership clearer.

wled00/util.cpp (1)

542-587: Consistent use of JSON_LOCK_LEDMAP_ENUM for ledmap enumeration

Switching to JSON_LOCK_LEDMAP_ENUM keeps behavior identical while making the caller identity clearer in lock debugging; acquire/release pattern around readObjectFromFile remains correct.

wled00/wled_serial.cpp (1)

103-126: Serial JSON path correctly tagged with JSON_LOCK_SERIAL

Using JSON_LOCK_SERIAL here cleanly documents that this lock user is the serial JSON API; control flow on failure and the lock release path are unchanged and correct.

wled00/mqtt.cpp (1)

112-126: MQTT /api handler now clearly identified via JSON_LOCK_MQTT

Replacing the magic lock ID with JSON_LOCK_MQTT keeps the acquisition/release logic intact and makes log output and ownership tracking for MQTT JSON handling clearer.

wled00/ws.cpp (1)

44-77: WebSocket RX/TX paths correctly distinguished with JSON_LOCK_WS_RECEIVE / JSON_LOCK_WS_SEND

Using distinct lock IDs for receive (JSON_LOCK_WS_RECEIVE) and send (JSON_LOCK_WS_SEND) keeps the existing behavior, avoids nested locking (RX is released before TX is acquired), and improves traceability in debug output.

Also applies to: 139-186

wled00/set.cpp (1)

651-787: Usermod settings now use JSON_LOCK_SETTINGS for JSON buffer access

The USERMODS form handler correctly tags its JSON buffer usage with JSON_LOCK_SETTINGS, preserving the existing defer/return-on-failure behavior and ensuring the lock is released after UsermodManager::readFromConfig.

wled00/udp.cpp (1)

649-660: UDP API path correctly labeled with JSON_LOCK_NOTIFY

Switching the UDP API section to JSON_LOCK_NOTIFY keeps the lock scope and behavior the same while tying this use of the JSON buffer clearly to the notification/UDP handler.

wled00/cfg.cpp (1)

790-806: Config and secure-config flows correctly separated with JSON_LOCK_CFG_ constants*

Using JSON_LOCK_CFG_DES/CFG_SER for main config and JSON_LOCK_CFG_SEC_DES/CFG_SEC_SER for the secure config cleanly documents which path owns the JSON buffer at each point. Each function still acquires at most one lock at a time and reliably calls releaseJSONBufferLock() on all paths.

Also applies to: 808-826, 1255-1307, 1310-1351

wled00/presets.cpp (1)

29-85: Preset save/load/name paths now use dedicated JSON_LOCK_PRESET_ IDs*

The preset code now clearly distinguishes save (JSON_LOCK_PRESET_SAVE), name lookup (JSON_LOCK_PRESET_NAME), and load (JSON_LOCK_PRESET_LOAD) as separate JSON buffer users. Lock acquisition, error handling, and release behavior remain the same, so this is a pure readability/diagnostics improvement.

Also applies to: 87-100, 145-215

these changes somehow did not get commited previously
@DedeHai DedeHai requested a review from netmindz December 22, 2025 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant