Skip to content

Conversation

@DedeHai
Copy link
Collaborator

@DedeHai DedeHai commented Jan 24, 2026

Fixes #5312

Summary by CodeRabbit

  • Bug Fixes
    • Improved button input handling to ensure proper power-on behavior and timing alignment for initial activation events.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 24, 2026

Walkthrough

The change modifies the handleIO() function to ensure BusManager and related I/O are powered on during initial boot when brightness is on by checking if lastOnTime equals 0, and moves the lastOnTime assignment after state changes to align timestamp updates with actual state modifications.

Changes

Cohort / File(s) Summary
Button I/O Control
wled00/button.cpp
Modified on-state handling in handleIO() to include lastOnTime == 0 condition for triggering BusManager power-on; relocated lastOnTime assignment to after the on/off state block to ensure proper initialization timing

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: ensuring the relay turns on during the first handleIO() call when LEDs are on, directly addressing the boot-up relay issue.
Linked Issues check ✅ Passed The code changes implement the fix for issue #5312 by adding lastOnTime == 0 condition to power on BusManager when LEDs are on at startup, resolving the relay not switching on at boot-up.
Out of Scope Changes check ✅ Passed All changes in button.cpp are directly related to fixing the relay boot-up issue described in #5312; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
wled00/button.cpp (1)

370-381: Guard against millis() wrap retriggering relay-on.

Using lastOnTime == 0 as the boot sentinel will become true after millis() wraps, causing an extra relay reassert and a 50 ms delay once every ~49 days. Consider a dedicated “first-on” flag instead.

Suggested fix
 void handleIO()
 {
+  static bool initialOnHandled = false;
   handleButton();
@@
   if (strip.getBrightness()) {
-    if (offMode || lastOnTime == 0) {
+    if (offMode || !initialOnHandled) {
       BusManager::on();
       if (rlyPin>=0) {
         pinMode(rlyPin, rlyOpenDrain ? OUTPUT_OPEN_DRAIN : OUTPUT);
         digitalWrite(rlyPin, rlyMde);
         delay(50); // wait for relay to switch and power to stabilize
       }
       offMode = false;
+      initialOnHandled = true;
     }
     lastOnTime = millis();

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.

Relay not switching on at power-up with boot-preset

1 participant