Fix brighness not being applied properly in nightlight mode#5625
Fix brighness not being applied properly in nightlight mode#5625DedeHai wants to merge 1 commit into
Conversation
WalkthroughThis PR refactors brightness finalization in LED state updates. The ChangesLED brightness finalization refactor
Sequence DiagramsequenceDiagram
participant stateUpdated as stateUpdated()
participant applyFinalBri as applyFinalBri()
participant strip as strip
participant handleNightlight as handleNightlight()
participant colorUpdated as colorUpdated()
stateUpdated->>strip: check getTransition()
rect rgba(100, 150, 200, 0.5)
Note over stateUpdated,applyFinalBri: No transition case
stateUpdated->>applyFinalBri: finalize brightness
applyFinalBri->>strip: trigger final update
end
handleNightlight->>colorUpdated: apply interpolated colors
rect rgba(150, 100, 200, 0.5)
Note over handleNightlight,applyFinalBri: Color fade case
handleNightlight->>applyFinalBri: finalize brightness after color update
applyFinalBri->>strip: trigger final update
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
wled00/led.cpp (1)
234-235: 💤 Low valueNightlight brightness fix is correct; minor optimization opportunity.
The
applyFinalBri()call successfully prevents transitions from blocking brightness updates during nightlight fade. This fixes the reported issue where repeatedcolorUpdated()calls every 100ms would restart transitions, preventingbrifrom changing.However, when
strip.getTransition() == 0,stateUpdated()(called bycolorUpdated()) already invokesapplyFinalBri()at line 128, so line 235 results in a redundant second call. While harmless, you could optimize by guarding the call:if (strip.getTransition() > 0) applyFinalBri();This ensures the bypass only happens when transitions are enabled. Given the 100ms rate limit and nightlight-only scope, the current unconditional approach is acceptable and keeps the fix simple.
♻️ Optional optimization to avoid redundant call
colorUpdated(CALL_MODE_NO_NOTIFY); -applyFinalBri(); // colorUpdated() re-starts transition (if enabled) every 100ms, preventing brightness from changing correctly (fix for `#5620`) +if (strip.getTransition() > 0) applyFinalBri(); // bypass transition restart to allow brightness updates (fix for `#5620`)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@wled00/led.cpp` around lines 234 - 235, colorUpdated() followed by an unconditional applyFinalBri() causes a redundant call when no transition is active because stateUpdated() already calls applyFinalBri(); update the code around colorUpdated(CALL_MODE_NO_NOTIFY) so you only call applyFinalBri() when a transition is enabled (check strip.getTransition() > 0) to avoid the duplicate call while preserving the nightlight fix; reference colorUpdated(), applyFinalBri(), strip.getTransition(), and stateUpdated() when locating the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@wled00/led.cpp`:
- Around line 234-235: colorUpdated() followed by an unconditional
applyFinalBri() causes a redundant call when no transition is active because
stateUpdated() already calls applyFinalBri(); update the code around
colorUpdated(CALL_MODE_NO_NOTIFY) so you only call applyFinalBri() when a
transition is enabled (check strip.getTransition() > 0) to avoid the duplicate
call while preserving the nightlight fix; reference colorUpdated(),
applyFinalBri(), strip.getTransition(), and stateUpdated() when locating the
change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 12f2b97d-bcac-40fd-922f-ae044ec9bc59
📒 Files selected for processing (1)
wled00/led.cpp
fix for #5620
Summary by CodeRabbit