Skip to content

Feat: BLE prevent sleep while active connected and Feat: allow sleep while USB powered#3286

Closed
newx-it wants to merge 8 commits intozmkfirmware:mainfrom
newx-it:feat-ble-prevent-sleep-while-active-connected
Closed

Feat: BLE prevent sleep while active connected and Feat: allow sleep while USB powered#3286
newx-it wants to merge 8 commits intozmkfirmware:mainfrom
newx-it:feat-ble-prevent-sleep-while-active-connected

Conversation

@newx-it
Copy link
Copy Markdown

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

A solution for issue 2198, wherein I changed the activity.c loop that checks for sleep to watch for the status of the active BT connection. When the flag is enabled and the active BT profile is connected, the check does not let the device sleep. If the flag is not enabled, the device acts the same as it would before this PR.

While I was working on testing the flag, I decided to add a flag to allow the device to sleep while USB power is present. This was primarily so i could test over USB debugging, but for users who are willing to allow their device to sleep while USB is powered (like split or dongle users) this should have non-negligible effects on battery life (from the zmk power profiler) for the peripherals, which may not be plugged in.

First time contributor so any and all advice is welcome and encouraged!

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.

Copy link
Copy Markdown
Contributor

@snoyer snoyer left a comment

Choose a reason for hiding this comment

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

I'm not a maintainer and I don't speak with any authority but here's a few comments for your consideration.

Also you have pushed some of your IDE's files which should not be in the PR. And eventually you'll want to have run the pre-commit checks for formatting and whatnot

Comment thread app/src/activity.c
Comment on lines +84 to +89
prevent_sleep = prevent_sleep ||
#if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
zmk_ble_active_profile_is_connected();
#else
zmk_split_bt_peripheral_is_connected();
#endif
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
prevent_sleep = prevent_sleep ||
#if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
zmk_ble_active_profile_is_connected();
#else
zmk_split_bt_peripheral_is_connected();
#endif
#if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
prevent_sleep |= zmk_ble_active_profile_is_connected();
#else
prevent_sleep |= zmk_split_bt_peripheral_is_connected();
#endif

maybe clearer to not split statements across preproc directives?

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.

Definitely more readable, I like it.

Comment thread app/Kconfig
default 900000

config ZMK_BLE_PREVENT_SLEEP_WHILE_ACTIVE_CONNECTED
bool "Enable keep awake for active profile"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

phrase in terms of preventing/allowing sleep instead of keeping awake?

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.

Also a great catch, I think I spotted this one and forgot it unfortunately.

@newx-it
Copy link
Copy Markdown
Author

newx-it commented Mar 19, 2026

I'm closing this pr in favor of another with cleaned up commit history and fixes applied, it's here: PR 3288

@newx-it newx-it closed this Mar 19, 2026
@snoyer
Copy link
Copy Markdown
Contributor

snoyer commented Mar 19, 2026

You shouldn't keep opening new PRs for minor changes, it makes the review process harder and spams the PR list. You can rewrite the commit history in the same PR if you need to.

@newx-it
Copy link
Copy Markdown
Author

newx-it commented Mar 19, 2026

Noted, thanks for the info! Won't happen again 😎

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