Skip to content

fix(underglow): avoid saving automatic state changes - #3463

Open
czstara12 wants to merge 1 commit into
zmkfirmware:mainfrom
czstara12:fix/underglow-auto-state-persistence
Open

fix(underglow): avoid saving automatic state changes#3463
czstara12 wants to merge 1 commit into
zmkfirmware:mainfrom
czstara12:fix/underglow-auto-state-persistence

Conversation

@czstara12

Copy link
Copy Markdown

Summary

  • Add internal non-persistent underglow on/off helpers.
  • Use those helpers for idle and USB automatic state changes.
  • Keep the public on/off APIs persistent for user-triggered changes.

Root cause

The automatic state handler called the public zmk_rgb_underglow_on() and
zmk_rgb_underglow_off() APIs. Both APIs schedule the complete underglow
state for storage, so an automatic idle transition persisted on=false as
if the user had explicitly disabled underglow.

This supersedes #1667 and follows the auto-state work in #2244 and #2284.

Validation

  • Ran the repository pre-commit hooks, including clang-format and gitlint.
  • Built hw75_dynamic@A and hw75_keyboard_f303cc@1.1 with the change.
  • Flashed and tested the change on an STM32F405RG-based HW75 Dynamic module.
  • Used J-Link breakpoints to confirm idle auto-off reached the internal off
    helper with underglow on and activity idle, without subsequently entering
    the underglow settings save work.
  • Read the FCB storage partition after auto-off and confirmed the latest
    rgb/underglow/state record remained on=true.
  • Confirmed the public on API still scheduled and persisted a state update.

PR check-list

  • Branch has a clean commit history.
  • Additional tests are included, if changing behavior/core code that is testable.
  • Proper copyright and license headers are present on applicable files.
  • Pre-commit was used to check formatting and the commit message.
  • No documentation changes are required.

Use non-persistent internal on/off helpers for idle and USB auto-off
transitions. User-triggered public APIs continue to save the underglow
state.
@czstara12
czstara12 marked this pull request as ready for review August 3, 2026 15:51
@czstara12
czstara12 requested a review from a team as a code owner August 3, 2026 15:51
Copilot AI review requested due to automatic review settings August 3, 2026 15:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Not ready to approve

The auto-off state machine still appears to mis-handle the case where both idle and USB auto-off are enabled, allowing one “wake” condition to restore underglow while the other condition still requires it to stay off.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR prevents automatic underglow state transitions (idle/USB auto-off) from being persisted to settings storage, while keeping user-invoked on/off actions persistent.

Changes:

  • Split underglow on/off into internal non-persistent “immediate” helpers and public persistent APIs.
  • Updated the idle/USB auto-state handler to use the non-persistent helpers to avoid saving automatic transitions.
File summaries
File Description
app/src/rgb_underglow.c Adds non-persistent on/off helpers and routes auto idle/USB transitions through them to avoid saving automatic state changes.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread app/src/rgb_underglow.c
Comment on lines 500 to 509
if (sleep_state.is_awake) {
if (sleep_state.rgb_state_before_sleeping) {
return zmk_rgb_underglow_on();
return zmk_rgb_underglow_on_immediate();
} else {
return zmk_rgb_underglow_off();
return zmk_rgb_underglow_off_immediate();
}
} else {
sleep_state.rgb_state_before_sleeping = state.on;
return zmk_rgb_underglow_off();
return zmk_rgb_underglow_off_immediate();
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for pointing this out. The interaction between the two auto-off conditions is valid, but it is a pre-existing issue and is outside the scope of this PR. The shared sleep_state logic and the mapping of idle/USB events to rgb_underglow_auto_state() are unchanged here; this PR only replaces the persistent public on/off calls with non-persistent internal helpers.

Correctly combining both options would require tracking the idle and USB inhibit conditions independently, which would be better handled in a separate issue/PR. With either option enabled on its own, this change preserves the existing auto-state behavior while preventing automatic transitions from being written to settings.

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.

2 participants