Merge f9699eb1bf
into 6d105f324b
This commit is contained in:
commit
3466a9001d
8 changed files with 97 additions and 6 deletions
|
@ -44,6 +44,7 @@ target_sources_ifdef(CONFIG_USB app PRIVATE src/events/usb_conn_state_changed.c)
|
|||
if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)
|
||||
target_sources(app PRIVATE src/behaviors/behavior_key_press.c)
|
||||
target_sources(app PRIVATE src/behaviors/behavior_reset.c)
|
||||
target_sources(app PRIVATE src/behaviors/behavior_sleep.c)
|
||||
target_sources(app PRIVATE src/behaviors/behavior_hold_tap.c)
|
||||
target_sources(app PRIVATE src/behaviors/behavior_sticky_key.c)
|
||||
target_sources(app PRIVATE src/behaviors/behavior_momentary_layer.c)
|
||||
|
|
|
@ -14,3 +14,4 @@
|
|||
#include <behaviors/bluetooth.dtsi>
|
||||
#include <behaviors/ext_power.dtsi>
|
||||
#include <behaviors/outputs.dtsi>
|
||||
#include <behaviors/sleep.dtsi>
|
||||
|
|
15
app/dts/behaviors/sleep.dtsi
Normal file
15
app/dts/behaviors/sleep.dtsi
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Copyright (c) 2020 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/ {
|
||||
behaviors {
|
||||
/omit-if-no-ref/ sleep: behavior_sleep {
|
||||
compatible = "zmk,behavior-sleep";
|
||||
label = "SLEEP";
|
||||
#binding-cells = <0>;
|
||||
};
|
||||
};
|
||||
};
|
8
app/dts/bindings/behaviors/zmk,behavior-sleep.yaml
Normal file
8
app/dts/bindings/behaviors/zmk,behavior-sleep.yaml
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Copyright (c) 2020 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
description: Sleep Binding Behavior
|
||||
|
||||
compatible: "zmk,behavior-sleep"
|
||||
|
||||
include: zero_param.yaml
|
|
@ -8,4 +8,5 @@
|
|||
|
||||
enum zmk_activity_state { ZMK_ACTIVITY_ACTIVE, ZMK_ACTIVITY_IDLE, ZMK_ACTIVITY_SLEEP };
|
||||
|
||||
enum zmk_activity_state zmk_activity_get_state();
|
||||
enum zmk_activity_state zmk_activity_get_state();
|
||||
int zmk_activity_set_state(enum zmk_activity_state state);
|
||||
|
|
|
@ -34,7 +34,8 @@ int raise_event() {
|
|||
(struct zmk_activity_state_changed){.state = activity_state}));
|
||||
}
|
||||
|
||||
int set_state(enum zmk_activity_state state) {
|
||||
int activity_set_state(enum zmk_activity_state state) {
|
||||
LOG_DBG("Setting activity state: %i", state);
|
||||
if (activity_state == state)
|
||||
return 0;
|
||||
|
||||
|
@ -47,19 +48,21 @@ enum zmk_activity_state zmk_activity_get_state() { return activity_state; }
|
|||
int activity_event_listener(const zmk_event_t *eh) {
|
||||
activity_last_uptime = k_uptime_get();
|
||||
|
||||
return set_state(ZMK_ACTIVITY_ACTIVE);
|
||||
return activity_set_state(ZMK_ACTIVITY_ACTIVE);
|
||||
}
|
||||
|
||||
void activity_work_handler(struct k_work *work) {
|
||||
int32_t current = k_uptime_get();
|
||||
int32_t inactive_time = current - activity_last_uptime;
|
||||
#if IS_ENABLED(CONFIG_ZMK_SLEEP)
|
||||
if (inactive_time > MAX_SLEEP_MS) {
|
||||
set_state(ZMK_ACTIVITY_SLEEP);
|
||||
// Second half of || statement is to ensure a user using &sleep doesn't lose sleep state when
|
||||
// the idle or sleep timers expire
|
||||
if (inactive_time > MAX_SLEEP_MS || activity_state == ZMK_ACTIVITY_SLEEP) {
|
||||
activity_set_state(ZMK_ACTIVITY_SLEEP);
|
||||
} else
|
||||
#endif /* IS_ENABLED(CONFIG_ZMK_SLEEP) */
|
||||
if (inactive_time > MAX_IDLE_MS) {
|
||||
set_state(ZMK_ACTIVITY_IDLE);
|
||||
activity_set_state(ZMK_ACTIVITY_IDLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
43
app/src/behaviors/behavior_sleep.c
Normal file
43
app/src/behaviors/behavior_sleep.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2020 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT zmk_behavior_sleep
|
||||
|
||||
#include <device.h>
|
||||
#include <drivers/behavior.h>
|
||||
#include <logging/log.h>
|
||||
|
||||
#include <zmk/behavior.h>
|
||||
#include <zmk/activity.h>
|
||||
|
||||
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)
|
||||
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
static int behavior_sleep_init(const struct device *dev) { return 0; };
|
||||
|
||||
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
|
||||
struct zmk_behavior_binding_event event) {
|
||||
#if IS_ENABLED(CONFIG_ZMK_SLEEP)
|
||||
return activity_set_state(ZMK_ACTIVITY_SLEEP);
|
||||
#endif
|
||||
return ZMK_BEHAVIOR_OPAQUE;
|
||||
}
|
||||
|
||||
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
|
||||
struct zmk_behavior_binding_event event) {
|
||||
return ZMK_BEHAVIOR_OPAQUE;
|
||||
}
|
||||
|
||||
static const struct behavior_driver_api behavior_sleep_driver_api = {
|
||||
.binding_released = on_keymap_binding_released,
|
||||
.binding_pressed = on_keymap_binding_pressed,
|
||||
};
|
||||
|
||||
DEVICE_AND_API_INIT(behavior_sleep, DT_INST_LABEL(0), behavior_sleep_init, NULL, NULL, APPLICATION,
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_sleep_driver_api);
|
||||
|
||||
#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */
|
|
@ -40,3 +40,22 @@ Example:
|
|||
```
|
||||
&none
|
||||
```
|
||||
|
||||
## Sleep
|
||||
|
||||
The sleep behavior simply puts your keyboard to sleep. This behavior has the same effect as letting the sleep timer expire.
|
||||
|
||||
:::note
|
||||
You'll need to enable `CONFIG_ZMK_SLEEP` in your boards config for this keycode to work.
|
||||
:::
|
||||
|
||||
### Behavior Binding
|
||||
|
||||
- Reference: `&sleep`
|
||||
- Parameters: None
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
&sleep
|
||||
```
|
||||
|
|
Loading…
Add table
Reference in a new issue