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

Multifix #4568

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

Multifix #4568

wants to merge 19 commits into from

Conversation

blazoncek
Copy link
Collaborator

@blazoncek blazoncek commented Feb 19, 2025

Plethora of fixes and tunings.

Some of the commits may be backported/cherry-picked to 0_15_x branch.

Summary by CodeRabbit

  • New Features

    • Introduced enhanced LED segment controls with new effects for clear and smooth fade transitions.
    • Added support for nested playlists and improved preset management for a more flexible scheduling experience.
    • Added new methods for segment color manipulation, including clearing and fading to secondary colors.
  • Improvements

    • Refined color adjustment handling for more consistent brightness and smoother transitions.
    • Enhanced XML response for color values, ensuring accurate output for primary colors.
    • Optimized interface responsiveness and reliable handling of playlist updates and settings display.

Copy link

coderabbitai bot commented Feb 19, 2025

Walkthrough

This pull request primarily standardizes color handling across various modules by replacing the legacy col array with the more specific colPri array. It introduces new methods for segment manipulation (such as clear() and fadeToSecondaryBy()), refactors color blending and palette functions, and adjusts playlist and JSON deserialization logic. Additionally, several JavaScript and settings files receive updates for improved robustness and readability. Minor changes to MQTT, XML responses, and overall system initialization further refine control flow and state management.

Changes

File(s) Change Summary
usermods/.../usermod_rotary_brightness_color.h
usermods/.../usermod_v2_rotary_encoder_ui_ALT.h
Replaced references from col to colPri for color adjustments in rotary encoder operations; updated brightness, hue, and saturation handling.
wled00/FX.h
wled00/FX_2Dfcn.cpp
wled00/FX_fcn.cpp
Added new methods (clear(), fadeToSecondaryBy()), updated palette blending (e.g., changing from NOBLEND to LINEARBLEND_NOWRAP) and adjusted internal logic for segment color manipulation.
wled00/led.cpp
wled00/mqtt.cpp
wled00/wled.h
wled00/xml.cpp
Renamed color variable from col to colPri for primary color management; refined time handling, MQTT message processing, and XML output, including const-correct bus pointer checks.
wled00/json.cpp
wled00/playlist.cpp
Introduced additional boolean flags (e.g., selected, reverse, mirror, etc.) in JSON deserialization; made playlist-related globals static and improved nested playlist state management.
wled00/data/index.js
wled00/data/settings_leds.htm
wled00/set.cpp
Updated playlist function parameters and checks; refactored character conversion logic to use a new chrID(x) function and replaced integer literals with character literals for ASCII conversion.
wled00/presets.cpp
wled00/fcn_declare.h
Added a new function presetNeedsSaving() to check preset status; updated comments regarding playlist repeat and state management.
wled00/wled.cpp Altered control flow in loop() to conditionally handle playlist processing based on preset-saving state; updated mDNS setup and color initialization to use colPri.

Possibly related PRs

  • intermediate fix for PS transition speedup #4562: The changes in the main PR, which involve updating color handling from col to colPri in the RotaryEncoderBrightnessColor class, are related to similar updates in the RotaryEncoderUIUsermod class in the retrieved PR, where col is also replaced with colPri for color processing.

📜 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 d22fe92 and 29beee3.

📒 Files selected for processing (1)
  • wled00/hue.cpp (1 hunks)
🔇 Additional comments (1)
wled00/hue.cpp (1)

198-200: LGTM! Consistent color handling standardization.

The replacement of col with colPri in all three color conversion functions aligns with the broader effort to standardize color handling across the codebase. The change is applied consistently while preserving the existing logic for conditional color conversions.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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. (Beta)
  • @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

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

🧹 Nitpick comments (8)
wled00/playlist.cpp (5)

13-15: Consider encapsulating global states into a dedicated structure or class.
While making them static limits their visibility to this translation unit, relying on multiple global variables for managing playlist states can make the code less modular and harder to maintain.


17-20: Use RAII or container-based approaches for dynamic arrays.
Replacing raw pointers with a container like std::vector (or a smart pointer) can improve safety and clarity by handling memory management automatically.


23-25: Group parent playlist fields into a single struct.
Merging parentPlaylistIndex, parentPlaylistRepeat, and parentPlaylistPresetId into a dedicated struct could improve readability and maintainability.


57-61: Provide user feedback for blocked nested playlists.
The current check correctly aborts if already within a nested playlist, but consider logging or notifying the user when this occurs to aid debugging.


159-162: Asynchronous preset application may cause brief visual artifacts.
When calling applyPresetFromPlaylist() after unloading, be aware of potential flicker or a short transition if user interactions occur at the same time.

wled00/FX_fcn.cpp (2)

1162-1181: Consider partial clearing
The new clear() method resets and restores geometry states before filling with black. For certain transitions, partial resets or preserving effect data might be more desirable for a smoother user experience.


1554-1584: Consider refactoring blending style logic
This switch block on blendingStyle has numerous cases and nested transitions. Moving these into helper functions or a more structured table-driven approach could improve maintainability.

wled00/json.cpp (1)

397-428: LGTM! Enhanced thread safety and performance.

The changes improve thread safety by ensuring segment modifications don't occur during effect execution. The batch deletion optimization for segments is a good performance improvement.

Consider adding a timeout to the wait loop to prevent potential deadlocks in case the strip servicing takes too long.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a2de3d3 and d22fe92.

📒 Files selected for processing (19)
  • usermods/usermod_rotary_brightness_color/usermod_rotary_brightness_color.h (4 hunks)
  • usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h (3 hunks)
  • wled00/FX.h (1 hunks)
  • wled00/FX_2Dfcn.cpp (1 hunks)
  • wled00/FX_fcn.cpp (13 hunks)
  • wled00/button.cpp (2 hunks)
  • wled00/colors.cpp (5 hunks)
  • wled00/data/index.js (13 hunks)
  • wled00/data/settings_leds.htm (9 hunks)
  • wled00/fcn_declare.h (1 hunks)
  • wled00/json.cpp (3 hunks)
  • wled00/led.cpp (7 hunks)
  • wled00/mqtt.cpp (2 hunks)
  • wled00/playlist.cpp (7 hunks)
  • wled00/presets.cpp (2 hunks)
  • wled00/set.cpp (5 hunks)
  • wled00/wled.cpp (3 hunks)
  • wled00/wled.h (1 hunks)
  • wled00/xml.cpp (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • wled00/wled.h
🧰 Additional context used
🪛 Biome (1.9.4)
wled00/data/index.js

[error] 412-412: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 413-413: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1913-1913: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments (48)
wled00/set.cpp (3)

147-147: Great improvement in readability!

Using character literals ('0' and 'A') instead of magic numbers (48 and 55) makes the code more maintainable and self-documenting.


260-260: Consistent improvement in readability!

The same improvement of using character literals is consistently applied here, maintaining a uniform coding style.


1194-1194: Documentation kept in sync with code changes!

The comment update correctly reflects the change from col[] to colPri[], maintaining accurate documentation.

wled00/playlist.cpp (4)

88-88: Confirm the max value for dur.
constrain(dur, 0, 65530) might be intentional to prevent overflow, but double-check whether 65530 is the correct upper bound or if 65535 should be used.


126-137: Double-check nested playlist transition logic.
This approach to resetting or preserving parent playlist data looks good. However, confirm that an endless parent playlist scenario doesn’t prevent reloading or cleanup.


149-149: Good safeguard against overflow.
Using playlistEntryDur < UINT16_MAX in the timing check helps prevent overflow in the millis() - presetCycledTime > 100 * playlistEntryDur expression.


172-172: Correct use of a sentinel for entry duration.
Setting playlistEntryDur to UINT16_MAX for zero durations avoids undefined handling in the subsequent time checks.

wled00/FX_fcn.cpp (4)

273-291: Refine transitional data checks
The new transitional data logic looks good, but consider adding explicit checks for _t to avoid potential null pointer references in edge cases.


1209-1229: Potential rounding issues during fade
Using (256-rate) >> 1 alongside integer math may introduce rounding artifacts at lower fade rates. If precise or smoother transitions are needed, consider alternative calculations or floating-point logic.


1231-1241: Fade to secondary color
This new fadeToSecondaryBy() method effectively transitions pixels toward colors[1]. The overall approach seems solid.


1322-1336: Use of palette blending logic
Leveraging strip.paletteBlend to select the blending type is appropriate. If paletteBlend can go out of anticipated bounds, consider adding boundary checks for robustness.

usermods/usermod_rotary_brightness_color/usermod_rotary_brightness_color.h (4)

98-100: Consistency of color references
Replacing col[...] with colPri[...] aligns with the broader move to the colPri array, ensuring code consistency.


109-111: Direct color assignment
Pulling FastLED components back into colPri ensures that changes persist and update the main color data correctly.


123-125: Mirroring color read
Re-acquiring colPri values here guarantees that the new hue adjustments are consistently applied to all color references.


134-136: Color variable rename
Using colPri rather than the more generic col clarifies that these fields represent the primary color array for the system.

wled00/mqtt.cpp (2)

106-106: Utilizing colPri for MQTT color updates
Switching to colPri aligns MQTT color commands with the primary color array used throughout the rest of the code.


172-172: MQTT color formatting
Publishing the color with colPri ensures consistency with the newly standardized primary color storage across modules.

wled00/led.cpp (5)

12-15: LGTM! Consistent color array naming.

The change from col to colPri is consistent with the PR objectives to standardize color handling.


42-42: LGTM! Consistent color array usage.

The change from col to colPri maintains consistency in color handling.


115-119: LGTM! Improved time handling.

Using a local variable now for current time ensures consistent timing calculations within the function.


154-154: LGTM! Improved code clarity.

Using CALL_MODE_INIT constant instead of a magic number improves code readability.


215-215: LGTM! Consistent color array usage in nightlight handling.

The change from col to colPri maintains consistency in color handling for nightlight functionality.

wled00/presets.cpp (2)

25-27: LGTM! Good addition of a utility function.

The new presetNeedsSaving function follows single responsibility principle and improves code modularity.


276-276: LGTM! Improved documentation.

The updated comment provides clearer information about playlist behavior, specifically about repeat counter increment and randomization.

wled00/button.cpp (2)

43-43: LGTM! Consistent color array usage in button handling.

The change from col to colPri maintains consistency in color handling for button actions.


233-233: LGTM! Consistent color array usage in analog handling.

The change from col to colPri maintains consistency in color handling for analog input processing.

wled00/colors.cpp (3)

13-20: LGTM! Improved code clarity in color blending.

The introduction of the mask constant and its consistent usage improves code readability and maintainability.


32-34: LGTM! Improved code clarity in color addition.

The introduction of the mask constant and its consistent usage improves code readability and maintainability.


82-85: LGTM! Improved code clarity in color fading.

The introduction of the mask constant and its consistent usage improves code readability and maintainability.

wled00/fcn_declare.h (1)

328-328: LGTM! Well-placed function declaration.

The new function presetNeedsSaving() is appropriately placed in the presets.cpp section and has a clear, descriptive name that indicates its purpose.

wled00/FX_2Dfcn.cpp (1)

687-687: Improved color blending for character rendering.

The change from ColorFromPaletteWLED to ColorFromPalette with LINEARBLEND_NOWRAP provides smoother color transitions when rendering characters.

wled00/xml.cpp (1)

14-14: Consistent use of primary color array.

The changes from col to colPri maintain consistency with the new color handling approach across the codebase.

Also applies to: 23-23

wled00/wled.cpp (3)

119-122: Improved state management for playlists.

Checking presetNeedsSaving() before handling playlists ensures that presets are saved before playlist changes, preventing potential state conflicts.


470-470: Better maintainability with constant usage.

Using DEFAULT_MDNS_NAME instead of a hardcoded string improves code maintainability and self-documentation.


553-553: Enhanced color initialization.

The changes improve color state initialization by:

  1. Using colPri consistently with the new color handling approach
  2. Ensuring proper color state initialization with colorUpdated(CALL_MODE_INIT)

Also applies to: 559-559

wled00/data/settings_leds.htm (1)

27-27: LGTM! Good refactoring.

The new chrID(x) function centralizes the character conversion logic that was previously duplicated across multiple functions. This improves code maintainability and reduces the risk of inconsistencies.

usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h (1)

521-521: LGTM! Consistent color handling.

The changes from col to colPri align with the project's transition in color handling, ensuring consistency across the codebase.

Also applies to: 923-924, 953-954, 958-959, 962-963

wled00/json.cpp (2)

94-107: LGTM! Improved variable declarations.

The new boolean variables improve code readability and maintainability by clearly separating segment properties.


209-219: LGTM! Improved property assignments.

The property assignments are now more organized and consistent, with proper constraints being handled in the appropriate functions.

wled00/FX.h (2)

679-679: LGTM! Clear and concise method name.

The clear() method follows good naming conventions and has a clear purpose of resetting the segment's state.


682-682: LGTM! Well-named method with clear functionality.

The fadeToSecondaryBy() method follows good naming conventions and has a clear purpose of fading to the secondary color by a specified amount.

wled00/data/index.js (7)

412-414: LGTM! Improved playlist type checking

The function now properly handles both numeric preset IDs and preset objects, making it more robust.

🧰 Tools
🪛 Biome (1.9.4)

[error] 412-412: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 413-413: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


1910-1920: LGTM! Enhanced playlist selection UI

The changes improve the user experience by:

  1. Visually indicating playlists with a play icon (▶)
  2. Preventing infinite recursion by skipping endless playlists and self-references
🧰 Tools
🪛 Biome (1.9.4)

[error] 1913-1913: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


1947-1950: LGTM! Improved playlist entry handling

The changes ensure that duration and transition arrays stay synchronized when adding new playlist entries.


1957-1960: LGTM! Improved playlist entry deletion

The changes ensure that duration and transition arrays stay synchronized when removing playlist entries, while preventing deletion of the last entry.


1977-1983: LGTM! Improved playlist transition validation

The changes ensure that transition durations cannot exceed playlist durations, preventing invalid states.


2003-2013: LGTM! Added manual playlist advancement

The new function properly handles manual playlist advancement by:

  1. Setting duration to 0 for manual mode and 10s for automatic mode
  2. Making duration inputs read-only in manual mode

2693-2698: LGTM! Improved color slot handling

The changes ensure that color slot data and UI are properly updated when RGB values change.

Comment on lines +513 to +520
if (stop && (spc > 0 || m12 != map1D2D)) clear();
/*
if (boundsUnchanged
&& (!grp || (grouping == grp && spacing == spc))
&& (ofs == UINT16_MAX || ofs == offset)
&& (m12 == map1D2D)
) return;

*/
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid clearing segment data unexpectedly
Calling clear() on geometry changes can be surprising for some use cases. Ensure there's no scenario where an unrelated parameter change inadvertently discards segment content.

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.

Reversing segment with spacing will not clear skipped LEDs Playlist duration time < 0.2 second needed
1 participant