feats: prevent sleep while active BT profile connected and allow sleep while USB power connected#3288
Open
newx-it wants to merge 7 commits intozmkfirmware:mainfrom
Open
Conversation
Adds a flag which, when enabled, allows users to prevent the device from sleeping when the chosen BT profile is connected/active.
Adds a flag which allows users to enable sleep even if USB power is present.
This was referenced Mar 19, 2026
fixed an error caused by an extra line of code that wasn't deleted
Not sure why pre-commit is having issues with the changes in activity.c, but attempted a fix there and fixed the final formatting issue in power.md
Removed stray backslash character
caksoylar
reviewed
Mar 22, 2026
Contributor
caksoylar
left a comment
There was a problem hiding this comment.
Implementation looks OK to me, but it is worth noting that the timeout does not reset while BLE is connected. So the part can immediately go to sleep once it disconnects, if it has been idle for a while. I think that's fine, but might be worth noting somewhere in the docs.
Also, pre-commit is failing and needs to be fixed. You can set it up locally to fix things for you when you push: https://zmk.dev/docs/development/local-toolchain/pre-commit
| int "Milliseconds of inactivity before entering deep sleep" | ||
| default 900000 | ||
|
|
||
| config ZMK_BLE_PREVENT_SLEEP_WHILE_ACTIVE_CONNECTED |
Contributor
There was a problem hiding this comment.
IMO these should be prefixed with ZMK_SLEEP, since they are all sub-options related to it.
Suggested change
| config ZMK_BLE_PREVENT_SLEEP_WHILE_ACTIVE_CONNECTED | |
| config ZMK_SLEEP_PREVENT_WHILE_BLE_CONNECTED |
| depends on ZMK_BLE | ||
| default n | ||
|
|
||
| config ZMK_USB_ALLOW_SLEEP_WHILE_POWERED |
Contributor
There was a problem hiding this comment.
Suggested change
| config ZMK_USB_ALLOW_SLEEP_WHILE_POWERED | |
| config ZMK_SLEEP_PREVENT_WHILE_USB_POWERED |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm closing my previous PR in favor of this one, which has some fixes applied and should have proper commit messages/clean commit history.
In short, I've added two flags:
CONFIG_ZMK_BLE_PREVENT_SLEEP_WHILE_ACTIVE_CONNECTEDandCONFIG_ZMK_USB_ALLOW_SLEEP_WHILE_POWEREDThe first allows the user to disable sleeping when the active BT profile is connected, related to issue 2198. The second arose naturally as I was testing my work on the first, but I believe it has merit as a means of increasing battery life for peripherals on devices that have the "main" device plugged in, whether it be a dongle or just a split.
pre-commit doesn't seem to like my formatting but I believe it's getting confused by the broken up lines, which are added for readability.
Like with my last PR, I am a new contributor (and new to open source as a whole) so any and all advice is appreciated!
PR check-list