feats: prevent sleep while active BT profile connected and allow sleep while USB power connected#3288
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.
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
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 |
There was a problem hiding this comment.
IMO these should be prefixed with ZMK_SLEEP, since they are all sub-options related to it.
| 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 |
There was a problem hiding this comment.
| config ZMK_USB_ALLOW_SLEEP_WHILE_POWERED | |
| config ZMK_SLEEP_PREVENT_WHILE_USB_POWERED |
Renamed both config flags, slightly changed syntax to support the swap from "allow" to "prevent" for the USB power flag.
fix formatting according to pre-commit's preferences
|
Pushed a couple changes but I'm having trouble phrasing the doc changes for the lack of BLE timeout. any suggestions? |
Added documentation for the interaction between BT connection keeping the device awake and the sleep timer. When the device loses connection after the sleep timer has elapsed, it will immediately sleep.
|
Alright, docs should be fixed. I'm conflicted about whether I should just reset the timer for a more intuitive sleep timer instead though, or even add a third flag to allow either behavior. Any opinions? |
| | `CONFIG_ZMK_SLEEP` | bool | Enable deep sleep support | n | | ||
| | `CONFIG_ZMK_IDLE_SLEEP_TIMEOUT` | int | Milliseconds of inactivity before entering deep sleep | 900000 | | ||
| | `CONFIG_ZMK_PM_SOFT_OFF` | bool | Enable soft off functionality from the keymap or dedicated hardware | n | | ||
| | `CONFIG_ZMK_BLE_PREVENT_SLEEP_WHILE_ACTIVE_CONNECTED` | bool | Prevent sleeping while the active BT profile is connected. If the device loses connection after the sleep timer, it will sleep immediately | n | |
There was a problem hiding this comment.
| | `CONFIG_ZMK_BLE_PREVENT_SLEEP_WHILE_ACTIVE_CONNECTED` | bool | Prevent sleeping while the active BT profile is connected. If the device loses connection after the sleep timer, it will sleep immediately | n | | |
| | `CONFIG_ZMK_SLEEP_PREVENT_WHILE_BLE_CONNECTED` | bool | Prevent sleeping while the active BT profile is connected. If the device loses connection after the sleep timer, it will sleep immediately | n | |
mismatching the Kconfig file; also will need a prettier pass to fix table formatting
| | `CONFIG_ZMK_IDLE_SLEEP_TIMEOUT` | int | Milliseconds of inactivity before entering deep sleep | 900000 | | ||
| | `CONFIG_ZMK_PM_SOFT_OFF` | bool | Enable soft off functionality from the keymap or dedicated hardware | n | | ||
| | `CONFIG_ZMK_BLE_PREVENT_SLEEP_WHILE_ACTIVE_CONNECTED` | bool | Prevent sleeping while the active BT profile is connected. If the device loses connection after the sleep timer, it will sleep immediately | n | | ||
| | `CONFIG_ZMK_USB_PREVENT_SLEEP_WHILE_POWERED` | bool | Prevent sleeping while USB power is connected | y | |
There was a problem hiding this comment.
| | `CONFIG_ZMK_USB_PREVENT_SLEEP_WHILE_POWERED` | bool | Prevent sleeping while USB power is connected | y | | |
| | `CONFIG_ZMK_SLEEP_PREVENT_WHILE_USB_POWERED` | bool | Prevent sleeping while USB power is connected | y | |
renamed flag names in docs to match previous changes
| config ZMK_SLEEP_PREVENT_WHILE_BLE_CONNECTED | ||
| bool "Prevent sleeping while the active BT profile is connected" | ||
| depends on ZMK_BLE | ||
| default n |
There was a problem hiding this comment.
| default n |
removed the redundante Kconfig "default n" value from the ZMK_SLEEP_PREVENT_WHILE_BLE_CONNECTED flag
|
Been using this for a couple days now. Amazing feature and works great! Quite huge battery savings as well as the keyboard won't stay in "search" mode when the computer has already been turned off and waiting for the sleep timeout. |
) Adds CONFIG_ZMK_SLEEP_PREVENT_WHILE_BLE_CONNECTED to prevent deep sleep while the active BT profile is connected. Avoids Issue zmkfirmware#3207 (Central fails to wake from deep sleep). Based on zmkfirmware#3288 by @jkosh44
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