Skip to content

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
newx-it:feat-ble-prevent-sleep-feat-usb-allow-sleep
Open

feats: prevent sleep while active BT profile connected and allow sleep while USB power connected#3288
newx-it wants to merge 7 commits intozmkfirmware:mainfrom
newx-it:feat-ble-prevent-sleep-feat-usb-allow-sleep

Conversation

@newx-it
Copy link

@newx-it newx-it commented Mar 19, 2026

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_CONNECTED and CONFIG_ZMK_USB_ALLOW_SLEEP_WHILE_POWERED
The 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

  • Branch has a clean commit history
  • Additional tests are included, if changing behaviors/core code that is testable.
  • Proper Copyright + License headers added to applicable files (Generally, we stick to "The ZMK Contributors" for copyrights to help avoid churn when files get edited)
  • Pre-commit used to check formatting of files, commit messages, etc.
  • Includes any necessary documentation changes.

newx-it added 4 commits March 19, 2026 08:18
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.
newx-it and others added 3 commits March 19, 2026 08:49
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
Copy link
Contributor

@caksoylar caksoylar left a comment

Choose a reason for hiding this comment

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

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
Copy link
Contributor

Choose a reason for hiding this comment

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

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
config ZMK_USB_ALLOW_SLEEP_WHILE_POWERED
config ZMK_SLEEP_PREVENT_WHILE_USB_POWERED

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