feat: stay awake while BLE connected
This commit is contained in:
parent
2adaa00d10
commit
45606e7fdf
3 changed files with 22 additions and 6 deletions
|
@ -402,6 +402,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_AWAKE_WHILE_BLE_CONNECTED
|
||||||
|
bool "Whether to stay awake while BLE is connected"
|
||||||
|
depends on ZMK_BLE
|
||||||
|
|
||||||
#ZMK_SLEEP
|
#ZMK_SLEEP
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
|
@ -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_AWAKE_WHILE_BLE_CONNECTED)
|
||||||
|
#include <zmk/ble.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// Reimplement some of the device work from Zephyr PM to work with the new `sys_poweroff` API.
|
// Reimplement some of the device work from Zephyr PM to work with the new `sys_poweroff` API.
|
||||||
// TODO: Tweak this to smarter runtime PM of subsystems on sleep.
|
// TODO: Tweak this to smarter runtime PM of subsystems on sleep.
|
||||||
|
|
||||||
|
@ -126,7 +130,14 @@ 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()) {
|
if (inactive_time > MAX_SLEEP_MS &&
|
||||||
|
!is_usb_power_present()
|
||||||
|
#if IS_ENABLED(CONFIG_ZMK_AWAKE_WHILE_BLE_CONNECTED)
|
||||||
|
// if user inactive and no USB
|
||||||
|
// keyboard will sleep as soon as BLE is disconnected
|
||||||
|
&& !zmk_ble_active_profile_is_connected()
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
// 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);
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,11 @@ 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_AWAKE_WHILE_BLE_CONNECTED` | bool | Whether to stay awake while BLE is connected | n |
|
||||||
|
|
||||||
## External Power Control
|
## External Power Control
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue