This commit is contained in:
Pablo Martínez 2024-09-02 23:57:52 +08:00 committed by GitHub
commit 170680eef3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 6 deletions

View file

@ -425,6 +425,10 @@ config ZMK_IDLE_SLEEP_TIMEOUT
int "Milliseconds of inactivity before entering deep sleep" int "Milliseconds of inactivity before entering deep sleep"
default 900000 default 900000
config ZMK_NO_SLEEP_WHILE_BLE_CONNECTED
bool "Prevent deep sleep while BLE is connected"
depends on ZMK_BLE
#ZMK_SLEEP #ZMK_SLEEP
endif endif

View file

@ -26,6 +26,10 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/usb.h> #include <zmk/usb.h>
#endif #endif
#if IS_ENABLED(CONFIG_ZMK_NO_SLEEP_WHILE_BLE_CONNECTED)
#include <zmk/ble.h>
#endif
bool is_usb_power_present(void) { bool is_usb_power_present(void) {
#if IS_ENABLED(CONFIG_USB_DEVICE_STACK) #if IS_ENABLED(CONFIG_USB_DEVICE_STACK)
return zmk_usb_is_powered(); return zmk_usb_is_powered();
@ -68,8 +72,21 @@ int activity_event_listener(const zmk_event_t *eh) {
void activity_work_handler(struct k_work *work) { void activity_work_handler(struct k_work *work) {
int32_t current = k_uptime_get(); int32_t current = k_uptime_get();
int32_t inactive_time = current - activity_last_uptime; int32_t inactive_time = current - activity_last_uptime;
#if IS_ENABLED(CONFIG_ZMK_SLEEP) #if IS_ENABLED(CONFIG_ZMK_SLEEP)
if (inactive_time > MAX_SLEEP_MS && !is_usb_power_present()) { bool prevent_sleep = is_usb_power_present();
#if IS_ENABLED(CONFIG_ZMK_NO_SLEEP_WHILE_BLE_CONNECTED)
/* if user inactive and USB is not connected,
* keyboard will sleep as soon as BLE is disconnected
*/
#if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
prevent_sleep = prevent_sleep || zmk_ble_active_profile_is_connected();
#else
prevent_sleep = prevent_sleep || zmk_split_bt_peripheral_is_connected();
#endif
#endif
if (inactive_time > MAX_SLEEP_MS && !prevent_sleep) {
// Put devices in suspend power mode before sleeping // Put devices in suspend power mode before sleeping
set_state(ZMK_ACTIVITY_SLEEP); set_state(ZMK_ACTIVITY_SLEEP);

View file

@ -18,11 +18,12 @@ In the deep sleep state, the keyboard additionally disconnects from Bluetooth an
Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/Kconfig) Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/Kconfig)
| Config | Type | Description | Default | | Config | Type | Description | Default |
| ------------------------------- | ---- | ----------------------------------------------------- | ------- | | ----------------------------------------- | ---- | ------------------------------------------------------------------------------------------------ | ------- |
| `CONFIG_ZMK_IDLE_TIMEOUT` | int | Milliseconds of inactivity before entering idle state | 30000 | | `CONFIG_ZMK_IDLE_TIMEOUT` | int | Milliseconds of inactivity before entering idle state | 30000 |
| `CONFIG_ZMK_SLEEP` | bool | Enable deep sleep support | n | | `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_IDLE_SLEEP_TIMEOUT` | int | Milliseconds of inactivity before entering deep sleep | 900000 |
| `CONFIG_ZMK_NO_SLEEP_WHILE_BLE_CONNECTED` | bool | Prevent deep sleep while BLE is connected (active profile on central, split comms on peripheral) | n |
## Soft Off ## Soft Off