Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More usermod fixes #4623

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

willmmiles
Copy link
Member

@willmmiles willmmiles commented Mar 29, 2025

Fix up some more usermods that I missed in #4480. This is a replacement for #4601.

Summary by CodeRabbit

  • New Features

    • Enhanced sensor integrations for light, battery, and photoresistor measurements.
    • Added support for a four-line display and improved rotary encoder controls for better interactivity.
    • Introduced new usermod classes for managing photoresistor and BH1750 light sensor functionalities.
    • New usermod for HTTP pull light control added.
    • New usermod for rotary encoder UI added.
  • Refactor

    • Streamlined sensor reading and MQTT communication for increased reliability.
    • Simplified configuration management and reduced complexity in display handling.
    • Enhanced modularity in rotary encoder and display functionalities.
  • Documentation

    • Updated configuration instructions and dependency management to simplify setup.
  • Chores

    • Improved build scripts and removed obsolete elements for a cleaner codebase.

I've just assigned an arbitrary ID number.  The ID system should
get removed entirely; we don't want to have to change a base
system header to add each module.
Rename a macro that unfortunately collides with the ESP32 platform.
This allows re-enabling this usermod.
The String constructors are ambiguous with uint8_ts.
Get this usermod to build, and restore the interconnect with its
partner usermod_v2_rotary_encoder_ui_ALT.
Fix up the cross module binding for
usermods/seven_segment_display_reloaded.  This requires splitting off
headers for BH1750_v2 and SN_Photoresistor.
Copy link

coderabbitai bot commented Mar 29, 2025

Walkthrough

Multiple usermods have been updated across the codebase. Changes include restructuring sensor integrations, revising MQTT and JSON handling, renaming debug macros, and updating variable types. New header files, classes, and setup scripts have been added for modules such as BH1750, SN_Photoresistor, four-line display, and rotary encoder. Additionally, configuration files and PlatformIO environments have been refined, obsolete registrations and dependency directives removed, and conditional compilation mechanisms improved.

Changes

File(s) Change Summary
usermods/BH1750_v2/BH1750_v2.cpp
usermods/BH1750_v2/BH1750_v2.h
Restructured Usermod_BH1750: removed preprocessor constants, added checkBoundSensor, updated MQTT initialization, setup, loop, and JSON config methods; introduced a new class declaration with sensor integration.
usermods/BME68X_v2/BME68X_v2.cpp Renamed debug macros (e.g., OK to OK_MSG, etc.) and updated the file header comment to reflect the correct filename.
usermods/MAX17048_v2/MAX17048_v2.cpp
usermods/MAX17048_v2/readme.md
Changed variable types for VoltageDecimals and PercentDecimals from uint8_t to unsigned; removed explicit library dependencies and build flag instructions in the readme, replacing them with custom usermod integration tips.
usermods/PWM_fan/setup_deps.py Modified conditional logic to explicitly check for "PWM_fan" and raise a RuntimeError if neither "Temperature" nor "sht" is enabled.
usermods/SN_Photoresistor/SN_Photoresistor.cpp
usermods/SN_Photoresistor/SN_Photoresistor.h
usermods/SN_Photoresistor/usermods_list.cpp
Updated Usermod_SN_Photoresistor: removed fixed configuration constants, added checkBoundSensor, streamlined setup, loop, and JSON config methods (making previously private methods public), and removed the registration file.
usermods/seven_segment_display_reloaded/library.json
usermods/seven_segment_display_reloaded/setup_deps.py
usermods/seven_segment_display_reloaded/seven_segment_display_reloaded.cpp
Fixed JSON syntax (correcting the "name" key), added a build object with extraScript, created a dependency setup script to append CPPDEFINES, and introduced conditional header inclusion based on usermod definitions.
usermods/usermod_v2_HttpPullLightControl/usermod_v2_HttpPullLightControl.cpp Modified JSON deserialization in handleResponse by switching from a local document variable to pointer-based access (pDoc->as<JsonObject>()).
usermods/usermod_v2_brightness_follow_sun/library.json
usermods/usermod_v2_brightness_follow_sun/usermod_v2_brightness_follow_sun.cpp
Added a new library.json file and updated the cpp file to remove #pragma once and register a static instance using the REGISTER_USERMOD macro.
usermods/usermod_v2_four_line_display_ALT/4LD_wled_fonts.h
usermods/usermod_v2_four_line_display_ALT/library.json
usermods/usermod_v2_four_line_display_ALT/library.json.disabled
usermods/usermod_v2_four_line_display_ALT/platformio_override.sample.ini
usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display.h
usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.cpp
Removed extra blank lines and obsolete preprocessor definitions; added a new library metadata file and removed a disabled JSON configuration; updated the platformio configuration with a dedicated environment; introduced a new header defining FourLineDisplayUsermod with extensive display methods; streamlined the cpp implementation by removing numerous internal variables and methods.
usermods/usermod_v2_rotary_encoder_ui_ALT/library.json
usermods/usermod_v2_rotary_encoder_ui_ALT/platformio_override.sample.ini
usermods/usermod_v2_rotary_encoder_ui_ALT/readme.md
usermods/usermod_v2_rotary_encoder_ui_ALT/setup_deps.py
usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.cpp
Updated the library name (from "usermod_v2_rotary_encoder_ui_ALT" to "rotary_encoder_ui_ALT") and added an extraScript entry; restructured the platformio environment to include rotary_encoder_ui_ALT; removed deprecated usermod definitions from the readme; added a setup script for conditional CPPDEFINES; and conditionally included additional headers in the cpp file.
usermods/word-clock-matrix/word-clock-matrix.cpp Renamed variable seg to text_seg, simplified savePreset by removing the boolean parameter, and modified getId to return a hardcoded value of 500.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7db52d7 and 354a0ae.

📒 Files selected for processing (2)
  • usermods/BME68X_v2/BME68X_v2.cpp (1 hunks)
  • usermods/BME68X_v2/library.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • usermods/BME68X_v2/library.json
  • usermods/BME68X_v2/BME68X_v2.cpp
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: wled_build / Build Environments (usermods)

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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

@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: 6

🧹 Nitpick comments (10)
usermods/seven_segment_display_reloaded/setup_deps.py (1)

1-9: Good dependency management script

This script properly adds the necessary preprocessor definitions based on which usermods are enabled, allowing for conditional compilation and integration between modules.

Consider adding a comment explaining that Import and env are PlatformIO build script conventions. This would make the code more readable for developers unfamiliar with PlatformIO:

+# This is a PlatformIO build script. 'Import' and 'env' are provided by PlatformIO.
 Import('env')


 usermods = env.GetProjectOption("custom_usermods","").split()
🧰 Tools
🪛 Ruff (0.8.2)

1-1: Undefined name Import

(F821)


4-4: Undefined name env

(F821)


7-7: Undefined name env

(F821)


9-9: Undefined name env

(F821)

usermods/word-clock-matrix/word-clock-matrix.cpp (1)

39-40: Variable name improved for clarity.

The variable name seg has been changed to text_seg which better describes its purpose in processing text segments. This improves code readability without changing functionality.

usermods/BH1750_v2/BH1750_v2.h (1)

25-29: Consider making offset value a float for finer control.

Currently, USERMOD_BH1750_OFFSET_VALUE is an integer set to 1. If your BH1750 sensor needs more granular offset control (e.g., fractional lux differences), consider using a float for the offset to avoid ignoring small measurement variations.

-#ifndef USERMOD_BH1750_OFFSET_VALUE
-#define USERMOD_BH1750_OFFSET_VALUE 1
-#endif
+#ifndef USERMOD_BH1750_OFFSET_VALUE
+#define USERMOD_BH1750_OFFSET_VALUE 1.0f
+#endif
usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.cpp (1)

937-1069: Complex re-initialization logic after config reload.

Re-initializing SPI or I2C pins, applying u8x8_Setup, and calling startDisplay() is comprehensive. Consider extracting this into smaller helper methods for readability, but overall the logic is correct. The usage of overlays on reconfig is a nice user experience touch.

usermods/SN_Photoresistor/SN_Photoresistor.h (1)

4-33: Consider replacing #define with constexpr or static constants.
Using #define may cause namespace pollution and offers no type checking. Transitioning to constexpr or static constants within a namespace or class scope can enhance maintainability and type safety.

usermods/SN_Photoresistor/SN_Photoresistor.cpp (2)

9-12: Check floating-point comparisons in checkBoundSensor.
The function uses direct <= and >= for floating-point comparisons. While this is acceptable for a threshold-based bound, keep in mind potential floating-point precision issues. Consider ensuring maxDiff is suitably sized relative to expected measurement noise.


109-133: Ensure guard for invalid JSON types or missing fields.
readFromConfig gracefully falls back to defaults if any fields are missing, which is helpful. However, you might want additional checks for out-of-range values to avoid nonsensical configurations (e.g., negative intervals).

usermods/BH1750_v2/BH1750_v2.cpp (2)

11-14: Avoid equality checks on floating-point (newValue == 0.0).
While it’s valid to flag a “sensor stuck at zero” condition, consider an epsilon threshold to account for floating-point precision errors.


23-52: Use consistent naming for device classes and measurement units.
The _createMqttSensor method sets device_class = "Illuminance" and unit_of_measurement = " lx". Ensure you maintain these strings consistently if other sensor usermods also produce brightness data to avoid confusion across devices in Home Assistant.

usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display.h (1)

295-305: Persist all relevant user settings in config.
While addToConfig() and readFromConfig() are declared, it’s unclear which fields are stored or loaded. If you intend to preserve user settings for display flipping, clock mode, contrast, etc., ensure these methods fully implement saving and loading each relevant variable.

Do you want help generating code snippets that serialize or deserialize these fields?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e76e9a3 and 62d3e15.

📒 Files selected for processing (27)
  • usermods/BH1750_v2/BH1750_v2.cpp (1 hunks)
  • usermods/BH1750_v2/BH1750_v2.h (1 hunks)
  • usermods/BME68X_v2/BME68X_v2.cpp (12 hunks)
  • usermods/MAX17048_v2/MAX17048_v2.cpp (1 hunks)
  • usermods/MAX17048_v2/readme.md (1 hunks)
  • usermods/PWM_fan/setup_deps.py (1 hunks)
  • usermods/SN_Photoresistor/SN_Photoresistor.cpp (1 hunks)
  • usermods/SN_Photoresistor/SN_Photoresistor.h (1 hunks)
  • usermods/SN_Photoresistor/usermods_list.cpp (0 hunks)
  • usermods/seven_segment_display_reloaded/library.json (1 hunks)
  • usermods/seven_segment_display_reloaded/setup_deps.py (1 hunks)
  • usermods/seven_segment_display_reloaded/seven_segment_display_reloaded.cpp (1 hunks)
  • usermods/usermod_v2_HttpPullLightControl/usermod_v2_HttpPullLightControl.cpp (1 hunks)
  • usermods/usermod_v2_brightness_follow_sun/library.json (1 hunks)
  • usermods/usermod_v2_brightness_follow_sun/usermod_v2_brightness_follow_sun.cpp (1 hunks)
  • usermods/usermod_v2_four_line_display_ALT/4LD_wled_fonts.h (1 hunks)
  • usermods/usermod_v2_four_line_display_ALT/library.json (1 hunks)
  • usermods/usermod_v2_four_line_display_ALT/library.json.disabled (0 hunks)
  • usermods/usermod_v2_four_line_display_ALT/platformio_override.sample.ini (1 hunks)
  • usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display.h (1 hunks)
  • usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.cpp (2 hunks)
  • usermods/usermod_v2_rotary_encoder_ui_ALT/library.json (1 hunks)
  • usermods/usermod_v2_rotary_encoder_ui_ALT/platformio_override.sample.ini (1 hunks)
  • usermods/usermod_v2_rotary_encoder_ui_ALT/readme.md (0 hunks)
  • usermods/usermod_v2_rotary_encoder_ui_ALT/setup_deps.py (1 hunks)
  • usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.cpp (1 hunks)
  • usermods/word-clock-matrix/word-clock-matrix.cpp (3 hunks)
💤 Files with no reviewable changes (3)
  • usermods/usermod_v2_four_line_display_ALT/library.json.disabled
  • usermods/SN_Photoresistor/usermods_list.cpp
  • usermods/usermod_v2_rotary_encoder_ui_ALT/readme.md
🧰 Additional context used
🧬 Code Definitions (4)
usermods/SN_Photoresistor/SN_Photoresistor.cpp (2)
usermods/SN_Photoresistor/SN_Photoresistor.h (4)
  • lastLDRValue (69-72)
  • root (74-74)
  • root (84-84)
  • root (89-89)
usermods/BH1750_v2/BH1750_v2.h (1)
  • root (79-79)
usermods/BH1750_v2/BH1750_v2.h (2)
usermods/seven_segment_display_reloaded/seven_segment_display_reloaded.cpp (12)
  • root (357-378)
  • root (357-357)
  • root (452-468)
  • root (452-452)
  • root (474-480)
  • root (474-474)
  • root (486-497)
  • root (486-486)
  • root (540-542)
  • root (540-540)
  • root (544-574)
  • root (544-544)
usermods/SN_Photoresistor/SN_Photoresistor.h (3)
  • root (74-74)
  • root (84-84)
  • root (89-89)
usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display.h (1)
usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.cpp (3)
  • enabled (299-299)
  • root (350-350)
  • root (360-360)
usermods/BH1750_v2/BH1750_v2.cpp (4)
usermods/BH1750_v2/BH1750_v2.h (1)
  • name (70-70)
usermods/sensors_to_mqtt/sensors_to_mqtt.cpp (2)
  • name (69-97)
  • name (69-69)
usermods/BME280_v2/BME280_v2.cpp (4)
  • name (131-159)
  • name (131-131)
  • topic (161-168)
  • topic (161-161)
usermods/AHT10_v2/AHT10_v2.cpp (2)
  • name (85-113)
  • name (85-85)
🪛 Ruff (0.8.2)
usermods/usermod_v2_rotary_encoder_ui_ALT/setup_deps.py

1-1: Undefined name Import

(F821)


4-4: Undefined name env

(F821)


8-8: Undefined name env

(F821)

usermods/seven_segment_display_reloaded/setup_deps.py

1-1: Undefined name Import

(F821)


4-4: Undefined name env

(F821)


7-7: Undefined name env

(F821)


9-9: Undefined name env

(F821)

🪛 LanguageTool
usermods/MAX17048_v2/readme.md

[uncategorized] ~13-~13: This verb may not be in the correct form. Consider using a different form for this context.
Context: ...enable, compile with USERMOD_MAX17048 define in the build_flags (e.g. in `platformio...

(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: wled_build / Build Environments (esp32_wrover)
  • GitHub Check: wled_build / Build Environments (usermods)
  • GitHub Check: wled_build / Build Environments (esp32s3_4M_qspi)
  • GitHub Check: wled_build / Build Environments (esp32_eth)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_opi)
  • GitHub Check: wled_build / Build Environments (nodemcuv2)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_160)
🔇 Additional comments (44)
usermods/MAX17048_v2/readme.md (2)

12-12: Streamlined installation documentation.

The shift from explicit library dependencies to the custom_usermods mechanism simplifies the installation process and aligns with how other usermods are configured.


17-17: Updated example configuration to match installation instructions.

The example now properly demonstrates the use of custom_usermods directive, making it consistent with the instructions provided earlier in the document.

usermods/usermod_v2_four_line_display_ALT/4LD_wled_fonts.h (1)

2-2: Minor formatting improvement.

Removed unnecessary blank lines before the #pragma once directive, making the code cleaner.

usermods/seven_segment_display_reloaded/seven_segment_display_reloaded.cpp (4)

2-7: Enhanced modularity with conditional includes.

Added conditional inclusion of light sensor headers based on compile-time flags, improving modularity and reducing dependencies when these sensors are not needed.


99-108: Improved type safety with conditional pointer declarations.

Declared sensor-specific pointers for each supported light sensor type, with fallback to void pointers when the corresponding usermod is not enabled.


396-401: Added sensor lookup during setup.

Properly initializes sensor pointers by looking up corresponding usermods during setup, enabling cross-usermod interaction.


412-438: Implemented cross-usermod integration for automatic brightness.

Added support for two different light sensor usermods (SN_Photoresistor and BH1750) to enable automatic brightness adjustment. The BH1750 implementation includes additional debug logging.

Worth noting that both implementations share similar logic:

  1. Check if brightness is enabled and sufficient time has passed
  2. Retrieve light value from the respective sensor
  3. Map value to brightness range
  4. Update brightness if changed

This is a good example of code that leverages conditional compilation to support multiple sensor types while maintaining a clean implementation.

usermods/PWM_fan/setup_deps.py (1)

10-10: Improved error condition specificity.

The conditional has been modified from a general else to a specific elif, which explicitly checks for the presence of the PWM_fan usermod. This makes the error condition more targeted and clearer to understand.

usermods/usermod_v2_rotary_encoder_ui_ALT/setup_deps.py (1)

1-8: Well-structured dependency setup script.

This new file appropriately configures the dependency between the rotary encoder usermod and the four-line display. It checks for either naming convention of the display module and sets up the necessary preprocessor definition.

Don't worry about the static analysis warnings about undefined names (Import and env). These are false positives as these variables are provided by the PlatformIO build system.

🧰 Tools
🪛 Ruff (0.8.2)

1-1: Undefined name Import

(F821)


4-4: Undefined name env

(F821)


8-8: Undefined name env

(F821)

usermods/seven_segment_display_reloaded/library.json (1)

2-5: Fixed JSON syntax and added build configuration.

Two important improvements:

  1. Fixed the syntax error in the "name" field (removed the colon after the key)
  2. Added proper build configuration to include the setup_deps.py script during the build process

These changes ensure proper JSON formatting and provide the necessary build integration.

usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.cpp (1)

30-32: Added proper conditional compilation for four-line display integration.

The addition of conditional include for the four-line display header enhances modularity by making this dependency optional. This works in conjunction with the newly added setup_deps.py script, which defines the USERMOD_FOUR_LINE_DISPLAY macro when the display module is enabled.

usermods/usermod_v2_brightness_follow_sun/usermod_v2_brightness_follow_sun.cpp (1)

130-131: Proper usermod registration added

The addition of a static instance and registration of the UsermodBrightnessFollowSun class is essential for making this usermod available to the WLED system. This follows the standard WLED pattern for usermod registration.

usermods/usermod_v2_rotary_encoder_ui_ALT/library.json (1)

3-5: Good addition of build configuration

Adding the extraScript to handle dependencies is a good practice. This allows for conditional compilation based on which usermods are enabled.

usermods/usermod_v2_HttpPullLightControl/usermod_v2_HttpPullLightControl.cpp (1)

300-300:

❓ Verification inconclusive

JSON handling updated to use shared document pointer

The code has been updated to use a pointer to a document (pDoc) instead of a local document instance (doc). This change aligns with the buffer locking mechanism used earlier in the method.

Since we don't see the variable declaration for pDoc in this file, please verify that it's properly defined as a member variable in the header file:

Also applies to: 303-303


🏁 Script executed:

#!/bin/bash
# Check if pDoc is properly defined in the header file
cat usermods/usermod_v2_HttpPullLightControl/usermod_v2_HttpPullLightControl.h | grep -A 5 "pDoc"

Length of output: 97


Action Required: Manually Verify pDoc Declaration

The updated code now uses a shared document pointer (pDoc), aligning with the buffer locking mechanism. However, the initial script did not return any output when searching for pDoc in usermod_v2_HttpPullLightControl.h. Please manually verify that pDoc is properly declared as a member variable in the header file. This check also applies to the code at line 303.

  • Ensure that pDoc is declared in usermod_v2_HttpPullLightControl.h.
  • Confirm that its declaration aligns with the updated JSON deserialization approach.
usermods/BME68X_v2/BME68X_v2.cpp (3)

2-2: File header updated to match file content.

The file header has been correctly updated from "usermod_BMW68X.h" to "usermod_BMW68X.cpp" to match the actual file content, which improves documentation accuracy.


36-39: Debug message macro constants renamed for clarity.

Debug message macros have been renamed by adding the _MSG suffix to clearly indicate their purpose as message-related constants. This improves code readability and makes the codebase more maintainable.


331-331: Debug message references updated consistently.

All references to the renamed debug message macros have been consistently updated throughout the file. This ensures the code functions correctly with the new macro names.

Also applies to: 355-355, 567-567, 753-753, 834-834, 848-848, 851-851, 1029-1029, 1033-1033, 1044-1044, 1048-1048, 1053-1053, 1066-1066, 1071-1071, 1087-1087, 1094-1094

usermods/MAX17048_v2/MAX17048_v2.cpp (1)

38-39: Variable types changed from uint8_t to unsigned.

The variable types for VoltageDecimals and PercentDecimals have been changed from uint8_t to unsigned. This change is unlikely to affect functionality as the existing values (3 and 1) are well within both type ranges, but it might increase memory usage slightly.

The change may have been made for consistency with other parts of the code or to anticipate future needs for larger values.

usermods/word-clock-matrix/word-clock-matrix.cpp (1)

70-70:

✅ Verification successful

Method parameter removed from savePreset call.

The boolean parameter (false) has been removed from the savePreset(13) call. This suggests the method signature has been simplified elsewhere in the codebase, likely making false the default behavior.

To verify this change is correct, please check the implementation of the savePreset method to ensure it can now be called without the second parameter:


🏁 Script executed:

#!/bin/bash
# Search for the savePreset method implementation
rg "void +savePreset" -A 3

Length of output: 602


Action: Confirmed removal of unnecessary parameter in savePreset call

After reviewing the function signature in the repository (see wled00/fcn_declare.h and wled00/presets.cpp), it’s clear that savePreset now accepts a primary parameter (byte index) with the remaining parameters defaulted (const char* pname = nullptr and JsonObject saveobj = JsonObject()). The earlier boolean parameter has been intentionally removed, and calling savePreset(13) appropriately leverages the default values.

usermods/usermod_v2_rotary_encoder_ui_ALT/platformio_override.sample.ini (3)

2-2: Default environment changed to esp32dev_re.

The default environment has been updated to use a custom environment specifically for the rotary encoder module.


4-7: New custom environment created for the rotary encoder.

A new environment esp32dev_re has been created that extends the esp32dev_V4 environment and adds the rotary_encoder_ui_ALT usermod to the build. This provides a specialized build configuration for the rotary encoder functionality.


8-12:

✅ Verification successful

Build flags updated to use parent environment flags.

The build flags now reference the parent environment's flags (${env:esp32dev_V4.build_flags}) instead of the common ESP32 flags. The -D USERMOD_ROTARY_ENCODER_UI flag has been removed, which may have been moved to a different configuration location or is now included in the parent's flags.

Note that pins and GPIO configuration flags are still properly defined.

To verify that the USERMOD_ROTARY_ENCODER_UI flag is defined elsewhere:


🏁 Script executed:

#!/bin/bash
# Search for USERMOD_ROTARY_ENCODER_UI definition in other configuration files
rg "USERMOD_ROTARY_ENCODER_UI" --glob "*.ini"

Length of output: 109


Attention: Build Flags Update Verified – Parent Environment Flags in Use

The configuration now correctly references the parent environment flags via ${env:esp32dev_V4.build_flags}. The -D USERMOD_ROTARY_ENCODER_UI flag is no longer active and appears only as a commented-out line (as seen in the search output), which confirms the intended removal. The remaining pin and GPIO configuration flags are correctly defined.

  • The commented-out entry (; -D USERMOD_ROTARY_ENCODER_UI) in platformio_override.sample.ini confirms that the flag isn’t active and likely maintained only for historical reference.
  • All active definitions, including the build flags and pin settings, match the intended updates.
usermods/usermod_v2_four_line_display_ALT/platformio_override.sample.ini (1)

2-12: Confirm environment definitions and consistency with parent environment.

You changed default_envs to esp32dev_fld and set [env:esp32dev_fld] to extend env:esp32dev_V4, referencing its build flags and appending four_line_display_ALT to custom_usermods. Ensure:

  1. env:esp32dev_V4 is indeed defined in a relevant .ini or shared config.
  2. Removal of any previously listed library dependencies does not break the build if the usermod or environment still relies on them.

Would you like to run a quick check that verifies the existence of env:esp32dev_V4 and inspects library usage?

usermods/BH1750_v2/BH1750_v2.h (2)

2-8: MQTT dependency enforced.

This usermod explicitly errors out if MQTT is disabled, which is appropriate if MQTT-based functionality is essential. Just ensure users who disable MQTT are aware that they cannot build this usermod.


30-93: Class structure is clear.

The class has well-defined private members and public methods. The usage of lastLux as a float is appropriate for illuminance. Just verify that your loop logic in the corresponding .cpp carefully checks the difference against the integer offset in a float comparison context.

usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.cpp (4)

46-54: Direct hardware commands for contrast voltage level.

This method directly sends commands to the display for contrast tuning. It looks correct, but keep an eye on concurrency if this function is ever called from multiple contexts. Currently, the guard if (type == NONE || !enabled) return; is good for ensuring it only runs when appropriate.


215-261: Verify handling of user-specified pins.

Your setup() method deallocates pins if they are invalid (negative), then sets type = NONE. This is a good fallback. Just confirm you log or notify the user when the display type is set to NONE, so they can diagnose hardware pin misconfiguration.


400-466: Concurrency approach is solid.

Locking via lockRedraw and the while (drawing && millis()-now < 125) delay(1); approach helps avoid race conditions when updating brightness, speed, intensity, and status icons. This looks well-thought-out and should maintain display stability.


916-935: Persistent configuration writes look fine.

Storing and retrieving structured data into the cfg.json (top-level “um” object) is straightforward. The property naming is consistent (enabled, type, pin, etc.). The debug statement also helps confirm that config was saved.

usermods/SN_Photoresistor/SN_Photoresistor.h (2)

44-44: Verify potential overflow calculations for lastMeasurement.
The expression UINT32_MAX - (USERMOD_SN_PHOTORESISTOR_MEASUREMENT_INTERVAL - USERMOD_SN_PHOTORESISTOR_FIRST_MEASUREMENT_AT) is clever but can be error-prone. Consider verifying boundary conditions (e.g., if USERMOD_SN_PHOTORESISTOR_MEASUREMENT_INTERVAL < USERMOD_SN_PHOTORESISTOR_FIRST_MEASUREMENT_AT) to ensure no unintended overflow or negative values in the sub-expression.


34-91: General class design looks good.
The overall structure of the Usermod_SN_Photoresistor class is clear, with well-defined private members and public methods for sensor reading, JSON integration, and configuration. The approach to storing repeated string literals in PROGMEM helps reduce flash usage. No major issues found.

usermods/SN_Photoresistor/SN_Photoresistor.cpp (6)

14-25: Validate potential range for getLuminance.
The formula for lux uses an empirical factor (* 2.0) on microamps. Confirm that high-intensity light won't exceed 65535. Also ensure that zero or near-zero reads don’t cause unexpected behavior in the calling code.


33-37: Honor the disabled flag.
The check if (disabled || strip.isUpdating()) return; properly skips sensor routines while disabled or strip is refreshing. This helps avoid potential concurrency issues and ensures performance is not impacted unnecessarily.


40-46: Incremental reading logic.
The logic to skip measurements until enough time has passed is clear and avoids rapid sensor updates. Validate additional edge cases, such as when now < lastMeasurement due to timer wraparound (though unlikely in typical operation).


48-49: Smart usage of checkBoundSensor.
This helps prevent excessive MQTT messages when the change is within the user-defined offset. A well-structured approach to reduce data noise.


69-89: Clean JSON info addition for debugging.
Reporting the remaining time until the first reading (if not complete) is a nice user-friendly feature. The “Luminance” field is appropriately nested under "u".


92-107: Storing configuration with intuitive keys.
Using descriptive property names like "supplied-voltage", "read-interval-s", etc. helps keep the JSON structure discoverable. No issues found in addToConfig.

usermods/BH1750_v2/BH1750_v2.cpp (4)

16-22: MQTT initialization approach is sound.
Using _mqttInitialize() once upon first data publish avoids unnecessary overhead. The check for HomeAssistantDiscovery is properly placed.


61-102: loop logic effectively manages update timing.
The check for strip.isUpdating() and the schedule (minReadingInterval, maxReadingInterval) ensures it doesn’t flood MQTT. This is a best practice for sensor updates.


105-128: Proper JSON output debug.
Using a separate nested array for “Luminance” is consistent with other usermods. The code gracefully handles cases when the device is disabled or the sensor is not found.


130-173: Overall configuration handling.
Reading and writing config with fallback defaults is prudent. The usage of getJsonValue is consistent and robust. No major issues.

usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display.h (3)

7-9: Confirm concurrency handling for ESP32 threads.
Defining FLD_ESP32_USE_THREADS may lead to concurrency issues if the display update and other tasks share resources unsafely. Please verify that you have proper locking mechanisms in place (e.g., semaphores, mutexes) to avoid data races or inconsistent states when drawing to the display concurrently.

Would you like me to provide a script to scan for concurrency-related methods or references to confirm safe usage?


79-80: Verify creation and error handling of U8X8 pointer.
Although you’ve declared a pointer to U8X8, the provided snippet does not show error handling if the display allocation or initialization fails. Ensure that u8x8 is instantiated during setup() or startDisplay() and confirm that you gracefully handle failures (e.g., fallback or disabled state).


128-140: Confirm static string definitions in your .cpp implementation.
These static const char declarations (e.g., _enabled, _contrast, etc.) should have matching definitions in the corresponding .cpp file. If they are never defined, linking errors may occur.

Comment on lines +75 to +76
volatile bool drawing = false;
volatile bool lockRedraw = false;
Copy link

@coderabbitai coderabbitai bot Mar 29, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider more robust synchronization than volatile booleans.
Using volatile bool drawing and volatile bool lockRedraw alone may not be sufficient for multi-threaded scenarios if actions on these flags happen concurrently. In certain situations, atomic operations or mutex-based synchronization might be more reliable for preventing race conditions.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is outside the scope of this PR; the goal here is to get modules to compile, I don't intend to second-guess or refactor the original author's logic.

Copy link

Choose a reason for hiding this comment

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

@willmmiles Understood! You're right to keep the PR focused on getting modules to compile without changing the original author's implementation logic. I'll respect that scope limitation.

Comment on lines +180 to +201
// gets called once at boot. Do all initialization that doesn't depend on
// network here
void setup() override;

// gets called every time WiFi is (re-)connected. Initialize own network
// interfaces here
void connected() override;

/**
* Da loop.
*/
void loop() override;

//function to update lastredraw
inline void updateRedrawTime() { lastRedraw = millis(); }

/**
* Redraw the screen (but only if things have changed
* or if forceRedraw).
*/
void redraw(bool forceRedraw);

Copy link

@coderabbitai coderabbitai bot Mar 29, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure robust startup and redraw logic.
The setup(), connected(), and redraw() methods must integrate seamlessly. If u8x8 is not fully initialized by the time redraw() is called, you could encounter unexpected display states. Consider safeguards (e.g., if (!initDone) return;) in loop() or redraw().

Copy link
Member Author

Choose a reason for hiding this comment

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

This is outside the scope of this PR, as above

Copy link

Choose a reason for hiding this comment

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

@willmmiles Understood. I'll respect the scope boundaries of your PR. Thanks for the clarification.

willmmiles and others added 5 commits March 28, 2025 21:17
Fix incorrect module name in library.json

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Fix incorrect json

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Fix typo in json

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Must've been a bad search-and-replace on my part somewhere..
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