Skip to content

Conversation

@MarcelMuxio
Copy link

@MarcelMuxio MarcelMuxio commented Jul 24, 2025

Summary by CodeRabbit

  • New Features

    • Added support for a rotary rack dimmer usermod, enabling brightness adjustment via a rotary encoder.
    • The new usermod displays its active status in system information.
  • Chores

    • Updated build environments to focus on the esp32dev platform for continuous integration and release binaries.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 24, 2025

Walkthrough

A new usermod for a rotary rack dimmer was added, including its implementation and header files. The build configuration was updated to compile only for the esp32dev environment, and a preprocessor flag specific to the new usermod was introduced. A minor formatting change was made in the usermod source aggregator.

Changes

Files/Groups Change Summary
platformio.ini Limited build environments to esp32dev and added USERMOD_ROTARYRACKDIMMER build flag.
usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.cpp, .h Introduced new usermod for rotary rack dimmer with brightness control logic, JSON info reporting, and setup hooks.
wled00/usermod.cpp Added a blank line after the include directive for formatting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

  • Moderate complexity due to the introduction of a new usermod with hardware interaction logic and configuration changes. The build and formatting changes are straightforward and low-effort.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 5

🧹 Nitpick comments (1)
usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.cpp (1)

9-9: Consider using English for comments and messages.

The comments and debug messages are in Dutch/German. For consistency with the WLED codebase, consider using English:

-  Serial.println(F("[RotaryRackDimmer] usermod geladen!"));
+  Serial.println(F("[RotaryRackDimmer] usermod loaded!"));
-  // Optioneel
+  // Optional
-  // Optioneel, laat usermod zelf zijn werk doen
+  // Optional, let usermod handle its own work
-  user["RotaryRackDimmer"] = "Actief";
+  user["RotaryRackDimmer"] = "Active";

Also applies to: 13-13, 17-17, 22-22

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2f5bec and 304adc8.

📒 Files selected for processing (4)
  • platformio.ini (2 hunks)
  • usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.cpp (1 hunks)
  • usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.h (1 hunks)
  • wled00/usermod.cpp (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: willmmiles
PR: wled/WLED#4623
File: usermods/word-clock-matrix/word-clock-matrix.cpp:332-332
Timestamp: 2025-03-29T01:22:54.617Z
Learning: In the WLED project, hardcoded usermod IDs (like 500 in the WordClockMatrix's getId() method) are intentionally used as part of a strategy to avoid modifying core code. There are plans to remove numeric usermod IDs entirely in the future.
Learnt from: KrX3D
PR: wled/WLED#4585
File: usermods/seven_segment_display_reloaded_v2/seven_segment_display_reloaded_v2.h:121-137
Timestamp: 2025-04-27T10:06:22.545Z
Learning: In the Seven Segment Display Reloaded usermod, the dimension mismatch between the default array (umSSDRNumbers[11][7]) and the override (umSSDRNumbers[11][10] = umSSDR_NUMBERS) is intentional by design, allowing for different use cases with varying numbers of segments per digit.
wled00/usermod.cpp (9)

Learnt from: willmmiles
PR: #4623
File: usermods/word-clock-matrix/word-clock-matrix.cpp:332-332
Timestamp: 2025-03-29T01:22:54.617Z
Learning: In the WLED project, hardcoded usermod IDs (like 500 in the WordClockMatrix's getId() method) are intentionally used as part of a strategy to avoid modifying core code. There are plans to remove numeric usermod IDs entirely in the future.

Learnt from: KrX3D
PR: #4664
File: wled00/syslog.cpp:50-51
Timestamp: 2025-04-26T12:51:04.993Z
Learning: In the WLED codebase, syslog configuration variables (syslogHost, syslogPort, syslogProtocol, syslogFacility, syslogSeverity) are defined as global variables in wled.h and are accessed directly in the SyslogPrinter implementation, rather than being class members.

Learnt from: KrX3D
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.

Learnt from: netmindz
PR: #4728
File: wled00/FX.h:378-378
Timestamp: 2025-06-15T09:59:52.720Z
Learning: In WLED's FX.h, MODE_COUNT represents the highest FX_MODE_ ID + 1, not the total count of FX_MODE_ definitions. This is because some effects may have been removed but their IDs are not reused, creating gaps in the numbering sequence. MODE_COUNT is used for array bounds and range checking.

Learnt from: netmindz
PR: #4728
File: wled00/FX.h:378-378
Timestamp: 2025-06-15T09:59:52.720Z
Learning: In WLED's FX.h, MODE_COUNT represents the highest FX_MODE_ ID + 1, not the total count of FX_MODE_ definitions. This is because some effects may have been removed but their IDs are not reused, creating gaps in the numbering sequence. MODE_COUNT is used for array bounds and range checking.

Learnt from: KrX3D
PR: #4585
File: usermods/seven_segment_display_reloaded_v2/seven_segment_display_reloaded_v2.cpp:430-435
Timestamp: 2025-04-28T20:51:29.773Z
Learning: In WLED, bri is a global variable used for brightness control.

Learnt from: KrX3D
PR: #4585
File: usermods/seven_segment_display_reloaded_v2/seven_segment_display_reloaded_v2.h:121-136
Timestamp: 2025-04-27T09:37:28.415Z
Learning: Using PROGMEM for the seven-segment font array (umSSDRNumbers) in the WLED SSDR usermod causes compilation problems, so it should be left as a regular array.

Learnt from: blazoncek
PR: #4658
File: wled00/const.h:140-141
Timestamp: 2025-04-26T19:19:07.600Z
Learning: In WLED, the WLED_MAX_PANELS macro is intentionally defined as a fixed constant value (18) with no redefinition mechanism, making it "unoverridable" - there's no need for a static assertion to check its maximum value.

Learnt from: DedeHai
PR: #4750
File: usermods/audioreactive/audio_reactive.cpp:311-321
Timestamp: 2025-06-27T06:04:44.652Z
Learning: In WLED's AudioReactive usermod, FFT buffer memory (valFFT, windowFFT) is allocated once during initialization and never deallocated, following typical embedded system design where core functionality buffers persist for the application lifetime. Raw buffer pointers for aligned allocations don't need to be tracked in the current implementation since deallocation is never performed.

platformio.ini (3)

Learnt from: Jason2866
PR: #4167
File: platformio.ini:427-430
Timestamp: 2025-07-06T16:15:24.051Z
Learning: In espressif Arduino framework, -fno-lto is set as a standard default in the platformio-build.py script. Therefore, using -fno-lto in build_unflags is not only valid but necessary to remove this default setting before enabling LTO with -flto=auto or -flto=4 in build_flags.

Learnt from: Jason2866
PR: #4167
File: platformio.ini:427-430
Timestamp: 2025-07-06T16:11:05.896Z
Learning: In PlatformIO, using -fno-lto in build_unflags is a valid pattern to remove potentially existing -fno-lto flags from the build system before adding -flto=auto in build_flags. This ensures that LTO can be enabled without conflicts from default build system flags that might disable LTO.

Learnt from: blazoncek
PR: #4482
File: wled00/udp.cpp:147-149
Timestamp: 2025-02-19T12:43:34.199Z
Learning: ESP8266 and ESP32 platforms have different maximum segment name lengths in WLED, which can cause truncation when syncing segment names between devices. This platform difference affects the user experience when using the segment name sync feature.

usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.cpp (1)

Learnt from: willmmiles
PR: #4623
File: usermods/word-clock-matrix/word-clock-matrix.cpp:332-332
Timestamp: 2025-03-29T01:22:54.617Z
Learning: In the WLED project, hardcoded usermod IDs (like 500 in the WordClockMatrix's getId() method) are intentionally used as part of a strategy to avoid modifying core code. There are plans to remove numeric usermod IDs entirely in the future.

usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.h (1)

Learnt from: willmmiles
PR: #4623
File: usermods/word-clock-matrix/word-clock-matrix.cpp:332-332
Timestamp: 2025-03-29T01:22:54.617Z
Learning: In the WLED project, hardcoded usermod IDs (like 500 in the WordClockMatrix's getId() method) are intentionally used as part of a strategy to avoid modifying core code. There are plans to remove numeric usermod IDs entirely in the future.

🔇 Additional comments (5)
wled00/usermod.cpp (1)

2-2: Minor formatting improvement.

The addition of a blank line after the include statement improves readability and follows common formatting conventions.

platformio.ini (2)

448-449: USERMOD flag correctly added.

The preprocessor definition -D USERMOD_ROTARYRACKDIMMER is properly added to enable compilation of the new usermod. The placement within the esp32dev environment is appropriate.


13-13: Confirm default_envs restriction

I only see default_envs = esp32dev in platformio.ini (line 13); all other default_envs entries are in sample or usermods-specific override files, which aren’t applied by default.

Please verify that:

  • Your CI/release pipeline will import usermods/platformio_override.usermods.ini (or another override) to build the additional environments, or
  • You intentionally intend to limit the default build to ESP32 only.

Files to review:

  • platformio.ini: line 13
  • usermods/platformio_override.usermods.ini (override for other targets)
usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.cpp (1)

1-10: Usermod registration implementation looks correct.

The global pointer approach and usermod registration in userSetup() follows WLED usermod patterns correctly. The instance creation and addition to the usermods list is properly implemented.

usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.h (1)

12-16: Setup method implementation is correct.

The pin initialization with pull-up resistors and initial state reading follows good practices for rotary encoder interfacing.

Comment on lines +20 to +23
void Usermod_RotaryRackDimmer::addToJsonInfo(JsonObject &root) {
JsonObject user = root["usermod"];
user["RotaryRackDimmer"] = "Actief";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Move method implementation to header file.

The addToJsonInfo method implementation should be in the header file since it's part of the class definition. Implementing class methods in separate files outside the class definition violates C++ best practices and can cause linking issues.

Move this implementation to the header file within the class definition:

-void Usermod_RotaryRackDimmer::addToJsonInfo(JsonObject &root) {
-  JsonObject user = root["usermod"];
-  user["RotaryRackDimmer"] = "Actief";
-}

Add to the header file within the class:

void addToJsonInfo(JsonObject &root) override {
  JsonObject user = root["usermod"];
  user["RotaryRackDimmer"] = "Active";
}
🤖 Prompt for AI Agents
In usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.cpp lines 20 to
23, move the implementation of the addToJsonInfo method from the .cpp file to
the header file. Place the method definition inside the class declaration in the
header file, marking it as override, and update the string value to "Active" as
suggested. This ensures the method is inline and avoids potential linking
issues.

Comment on lines +7 to +9
int pinA = 33; // A (CLK) pin van de encoder
int pinB = 13; // B (DT) pin van de encoder
int lastState = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Make pin assignments and step size configurable.

The hardcoded pin assignments and brightness step should be configurable through the WLED web interface for better usability and hardware flexibility.

 class Usermod_RotaryRackDimmer : public Usermod {
 private:
-  int pinA = 33;  // A (CLK) pin van de encoder
-  int pinB = 13;  // B (DT) pin van de encoder
+  int pinA = 33;  // A (CLK) pin of encoder - configurable
+  int pinB = 13;  // B (DT) pin of encoder - configurable
+  int stepSize = 5;  // Brightness step size - configurable
   int lastState = 0;

Then implement proper addToConfig and readFromConfig methods to handle these parameters.

🤖 Prompt for AI Agents
In usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.h around lines 7
to 9, the pin assignments and step size are hardcoded, limiting flexibility.
Modify the code to make pinA, pinB, and the brightness step size configurable
via the WLED web interface by adding corresponding variables and UI controls.
Then implement the addToConfig and readFromConfig methods to save and load these
parameters from the configuration, ensuring they persist across restarts.

Comment on lines +18 to +31
void loop() override {
int currentState = digitalRead(pinA);
if (currentState != lastState) {
if (digitalRead(pinB) != currentState) {
// Rechtsom → dim omhoog
bri = min(255, bri + 5);
} else {
// Linksom → dim omlaag
bri = max(0, bri - 5);
}
lastState = currentState;
colorUpdated(CALL_MODE_DIRECT_CHANGE);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add debouncing to prevent erratic behavior.

Rotary encoders are prone to bouncing, which will cause erratic brightness changes. The current implementation lacks debouncing and may trigger multiple times per detent.

Add debouncing with a simple time-based approach:

 class Usermod_RotaryRackDimmer : public Usermod {
 private:
   int pinA = 33;
   int pinB = 13;
   int lastState = 0;
+  unsigned long lastChangeTime = 0;
+  const unsigned long debounceDelay = 2; // 2ms debounce

   void loop() override {
     int currentState = digitalRead(pinA);
-    if (currentState != lastState) {
+    if (currentState != lastState && (millis() - lastChangeTime) > debounceDelay) {
       if (digitalRead(pinB) != currentState) {
-        bri = min(255, bri + 5);
+        bri = min(255, bri + stepSize);
       } else {
-        bri = max(0, bri - 5);
+        bri = max(0, bri - stepSize);
       }
       lastState = currentState;
+      lastChangeTime = millis();
       colorUpdated(CALL_MODE_DIRECT_CHANGE);
     }
   }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.h around lines 18
to 31, the loop function handling the rotary encoder input lacks debouncing,
causing erratic brightness changes due to signal bouncing. To fix this,
implement a simple time-based debounce by recording the last time the state
changed and only processing changes if a minimum debounce interval (e.g., 5-10
milliseconds) has passed since the last update. Add a timestamp variable to
track the last update time and check this before updating brightness and
lastState.

Comment on lines +23 to +26
bri = min(255, bri + 5);
} else {
// Linksom → dim omlaag
bri = max(0, bri - 5);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using stepSize variable instead of hardcoded value.

The brightness adjustment uses a hardcoded step of 5, but this should use the configurable stepSize variable for consistency.

       if (digitalRead(pinB) != currentState) {
-        bri = min(255, bri + 5);
+        bri = min(255, bri + stepSize);
       } else {
-        bri = max(0, bri - 5);
+        bri = max(0, bri - stepSize);
       }
🤖 Prompt for AI Agents
In usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.h around lines 23
to 26, the brightness adjustment uses a hardcoded step value of 5. Replace this
hardcoded value with the configurable stepSize variable to ensure consistent and
adjustable brightness increments and decrements.

Comment on lines +33 to +34
void addToConfig(JsonObject &root) override {}
bool readFromConfig(JsonObject &root) override { return true; }
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Implement proper configuration methods.

The configuration methods are currently empty but should handle the configurable parameters (pins and step size) to make the usermod user-friendly.

-  void addToConfig(JsonObject &root) override {}
-  bool readFromConfig(JsonObject &root) override { return true; }
+  void addToConfig(JsonObject &root) override {
+    JsonObject top = root.createNestedObject(FPSTR("RotaryRackDimmer"));
+    top["pinA"] = pinA;
+    top["pinB"] = pinB;
+    top["stepSize"] = stepSize;
+  }
+  
+  bool readFromConfig(JsonObject &root) override {
+    JsonObject top = root[FPSTR("RotaryRackDimmer")];
+    if (top.isNull()) return false;
+    
+    pinA = top["pinA"] | pinA;
+    pinB = top["pinB"] | pinB;
+    stepSize = top["stepSize"] | stepSize;
+    
+    return true;
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void addToConfig(JsonObject &root) override {}
bool readFromConfig(JsonObject &root) override { return true; }
void addToConfig(JsonObject &root) override {
JsonObject top = root.createNestedObject(FPSTR("RotaryRackDimmer"));
top["pinA"] = pinA;
top["pinB"] = pinB;
top["stepSize"] = stepSize;
}
bool readFromConfig(JsonObject &root) override {
JsonObject top = root[FPSTR("RotaryRackDimmer")];
if (top.isNull()) return false;
pinA = top["pinA"] | pinA;
pinB = top["pinB"] | pinB;
stepSize = top["stepSize"] | stepSize;
return true;
}
🤖 Prompt for AI Agents
In usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.h at lines 33-34,
the addToConfig and readFromConfig methods are empty and need to be implemented
to handle the usermod's configurable parameters such as pins and step size.
Modify addToConfig to serialize these parameters into the provided JsonObject,
and update readFromConfig to deserialize and apply these parameters from the
JsonObject, ensuring the usermod can save and restore its configuration
properly.

@MarcelMuxio MarcelMuxio deleted the MarcelMuxio-patch-1 branch July 24, 2025 16:00
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