Skip to content

Add TwinkleFadeIn effect #4728

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

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

Add TwinkleFadeIn effect #4728

wants to merge 7 commits into from

Conversation

benjamw
Copy link

@benjamw benjamw commented Jun 12, 2025

This adds a new effect which is the reverse of Twinklecat: Twinklefadein (See Issue #3738)

Twinklecat instantly turns on random lights and then slowly fades them out. This effect slowly fades in random lights, and then instantly turns them off.

It is a very simple and small change, but has not been tested.

The only questions I had were about the FX numbering scheme:

  1. Should new effects be placed at the bottom of the list regardless of where they naturally sort?
  2. Should new effects be placed in the list where they naturally sort, but keep the numbering the same?
  3. Should new effects be placed in the list where they naturally sort, and renumber the list to keep the numbering sequential?

I opted for option #1, but can easily adjust it if needed.

Thanks

Summary by CodeRabbit

  • New Features
    • Introduced a "Reverse" option for the Twinklecat effect, allowing users to choose between LEDs fading on or fading off.
  • Improvements
    • Updated the Twinklecat effect settings to include a new checkbox for reversing the twinkle behavior.

Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

Walkthrough

The twinklefox_one_twinkle function in wled00/FX.cpp was modified to adjust the brightness behavior based on the segment's check2 flag, introducing a "Reverse" twinkle variant. The metadata string for the "Twinklecat" effect mode was also updated to reflect this new option.

Changes

Files Change Summary
wled00/FX.cpp Modified twinklefox_one_twinkle to add brightness logic based on check2 flag; updated effect metadata string for "Twinklecat" to include "Reverse" option.

Suggested reviewers

  • blazoncek

📜 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 eb77df9 and e468fb8.

📒 Files selected for processing (1)
  • wled00/FX.cpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • wled00/FX.cpp
✨ Finishing Touches
  • 📝 Generate Docstrings

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

🧹 Nitpick comments (3)
wled00/FX.cpp (3)

2537-2540: Prefer an enum over multiple booleans for effect variants

twinklefox_one_twinkle() now accepts two feature flags (cat, instantOff).
The possible combinations are implicitly:

  1. vanilla – false,false
  2. twinklecat – true,false
  3. twinklefadein – false,true
  4. undefined / nonsense – true,true

Using two independent booleans makes the (4)-case possible and obscures intent at the call-site.
Consider replacing them with a single typed enum:

-enum class TwinkleKind : uint8_t { Vanilla, Cat, FadeIn };
-
-static CRGB twinklefox_one_twinkle(uint32_t ms,
-                                   uint8_t  salt,
-                                   TwinkleKind kind = TwinkleKind::Vanilla);
+// callers read much clearer:  twinklefox_one_twinkle(ms, salt, TwinkleKind::FadeIn)

This eliminates invalid states and improves readability.


2598-2601: twinklefox_base signature drift

The new instantOff parameter is forwarded correctly, but the function comment block still documents only the cat variant.
Update the comment to avoid future confusion and include a short description of the new behaviour.


2672-2676: Mode registration string does not mention “Fade-in” behaviour

_data_FX_MODE_TWINKLEFADEIN currently copies the metadata from the other modes.
To help end-users recognise the difference in the UI, append a short hint (e.g. “fade-in”) in the effect name segment:

-static const char _data_FX_MODE_TWINKLEFADEIN[] PROGMEM = "Twinklefadein@!,Twinkle rate,,,,Cool;!,!;!";
+static const char _data_FX_MODE_TWINKLEFADEIN[] PROGMEM = "Twinklefadein (fade-in)@!,Twinkle rate,,,,Cool;!,!;!";
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 05f0630 and 54efb72.

📒 Files selected for processing (2)
  • wled00/FX.cpp (6 hunks)
  • wled00/FX.h (1 hunks)
🔇 Additional comments (3)
wled00/FX.h (1)

376-376:

✅ Verification successful

New FX mode identifier appended
You’ve added FX_MODE_TWINKLEFADEIN at ID 218 as per the chosen scheme. Ensure this new mode is actually registered in setupEffectData() within FX.cpp so it’s available at runtime.


🏁 Script executed:

#!/bin/bash
# Verify the new mode is registered in FX.cpp
grep -R "addEffect( *FX_MODE_TWINKLEFADEIN" -n wled00/FX.cpp

Length of output: 154


New FX mode identifier appended and registered
The added FX_MODE_TWINKLEFADEIN at ID 218 is properly registered in setupEffectData() in wled00/FX.cpp (line 10674). No further changes required—ready to merge.

wled00/FX.cpp (2)

2558-2562: Brightness curve for instantOff is only half implemented

For the fade-in / instant-off branch you set
bright = ph; – a strictly rising linear ramp.
When ph resets to 0 on the next cycle the LED will indeed turn off instantly, but:

  • The ramp peaks at 255 only at the very end of the 0-255 phase, so the LED spends most of its cycle very dim.
  • The visual result is noticeably dull compared to the other variants that use a steeper attack.

You likely want a faster rise (e.g. bright = ph * 3 for 0-85) and an immediate drop to 0 afterwards, mirroring the twinklecat decay shape:

-} else if (instantOff) { //fade in, instant off
-  bright = ph;
+} else if (instantOff) { //fade in, instant off
+  if (ph < 86) {
+    bright = ph * 3;            // rapid fade-in
+  } else {
+    bright = 0;                 // instant off for the rest of the cycle
+  }

Please verify the visual behaviour on hardware – the current linear ramp may look under-powered.


10671-10675: Verify mode ID and MODE_COUNT update

addEffect(FX_MODE_TWINKLEFADEIN, …) assumes that FX_MODE_TWINKLEFADEIN is unique and that MODE_COUNT has been bumped correspondingly in FX.h.
Please double-check for collisions with recently added modes (218/219 are getting crowded).
If multiple PRs land out of order an ID clash will cause subtle runtime issues.

@benjamw benjamw changed the title Add TwinkleFadeIn effect (#3738) Add TwinkleFadeIn effect Jun 12, 2025
@blazoncek
Copy link
Collaborator

If it is a small and simple change, why not update existing effect with one of the custom checkboxes?

@willmmiles
Copy link
Member

To expand: FX ids are at somewhat of a premium these days. I also think it'd be better to add an "invert" checkbox to TwinkleCat vs giving it a new name.

Copy link
Member

@netmindz netmindz left a comment

Choose a reason for hiding this comment

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

Please use a checkbox to toggle this behavior rather than making a new effect

@benjamw
Copy link
Author

benjamw commented Jun 19, 2025

Thank you for the feedback. That makes a lot more sense to use a checkbox instead of a whole new effect. (Which also implies that "TwinkleCat" itself could have been a checkbox. But that's a whole other issue.)

I've converted the function param to be a checkbox called "Reverse" and committed that.

Note: I did use AI (cursor) to assist me, as I am unfamiliar with the PROGMEM mode string syntax, so please let me know if that is incorrect.

wled00/FX.h Outdated
@@ -373,6 +373,7 @@ extern byte realtimeMode; // used in getMappedPixelIndex()
#define FX_MODE_PS1DSONICBOOM 215
#define FX_MODE_PS1DSPRINGY 216
#define FX_MODE_PARTICLEGALAXY 217

Copy link
Collaborator

Choose a reason for hiding this comment

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

revert

wled00/FX.cpp Outdated
@@ -2665,7 +2667,7 @@ uint16_t mode_twinklecat()
{
return twinklefox_base(true);
}
static const char _data_FX_MODE_TWINKLECAT[] PROGMEM = "Twinklecat@!,Twinkle rate,,,,Cool;!,!;!";
static const char _data_FX_MODE_TWINKLECAT[] PROGMEM = "Twinklecat@!,Twinkle rate,,,,Cool;!,!;!,Reverse";
Copy link
Collaborator

Choose a reason for hiding this comment

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

check2 is after cooling checkbox:
"Twinklecat@!,Twinkle rate,,,,Cool,Reverse;!,!;!";

please make sure to test your code so it does what you want it to.

Copy link
Author

Choose a reason for hiding this comment

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

I plan on testing it. Thanks for the updates.

revert extra line
@benjamw
Copy link
Author

benjamw commented Jun 20, 2025

I just compiled and tested, and it's working as expected.

For future reference, is there a way to edit the icons used for the checkboxes?

@DedeHai
Copy link
Collaborator

DedeHai commented Jun 20, 2025

I just compiled and tested, and it's working as expected.

For future reference, is there a way to edit the icons used for the checkboxes?

the icons are fixed but you can choose the checkmark number

@netmindz
Copy link
Member

Not had chance to test, but the code changes are looking much more compact :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants