Merge branch 'behaviors/macros-take-two' of https://github.com/petejohanson/zmk into petejohanson_behaviors/macros-take-two
This commit is contained in:
commit
503f8ea237
17 changed files with 176 additions and 38 deletions
|
@ -414,7 +414,7 @@ menu "Behavior Options"
|
|||
|
||||
config ZMK_BEHAVIORS_QUEUE_SIZE
|
||||
int "Maximum number of behaviors to allow queueing from a macro or other complex behavior"
|
||||
default 20
|
||||
default 64
|
||||
|
||||
endmenu
|
||||
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#define ZMK_MACRO_STRINGIFY(x) #x
|
||||
#define ZMK_MACRO(name,...) \
|
||||
name: name { \
|
||||
label = ZMK_MACRO_STRINGIFY(ZM_ ## name); \
|
||||
compatible = "zmk,behavior-macro"; \
|
||||
#binding-cells = <0>; \
|
||||
__VA_ARGS__ \
|
||||
};
|
||||
|
||||
/ {
|
||||
behaviors {
|
||||
macro_tap: macro_control_mode_tap {
|
||||
|
|
|
@ -26,7 +26,6 @@ static K_DELAYED_WORK_DEFINE(queue_work, behavior_queue_process_next);
|
|||
|
||||
static void behavior_queue_process_next(struct k_work *work) {
|
||||
struct q_item item = {.wait = 0};
|
||||
int ret;
|
||||
|
||||
while (k_msgq_get(&zmk_behavior_queue_msgq, &item, K_NO_WAIT) == 0) {
|
||||
LOG_DBG("Invoking %s: 0x%02x 0x%02x", log_strdup(item.binding.behavior_dev),
|
||||
|
@ -53,17 +52,14 @@ static void behavior_queue_process_next(struct k_work *work) {
|
|||
int zmk_behavior_queue_add(uint32_t position, const struct zmk_behavior_binding binding, bool press,
|
||||
uint32_t wait) {
|
||||
struct q_item item = {.press = press, .binding = binding, .wait = wait};
|
||||
int ret;
|
||||
|
||||
LOG_DBG("");
|
||||
|
||||
ret = k_msgq_put(&zmk_behavior_queue_msgq, &item, K_NO_WAIT);
|
||||
const int ret = k_msgq_put(&zmk_behavior_queue_msgq, &item, K_NO_WAIT);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!k_delayed_work_pending(&queue_work)) {
|
||||
k_delayed_work_submit(&queue_work, K_NO_WAIT);
|
||||
behavior_queue_process_next(&queue_work);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -98,7 +98,7 @@ static int behavior_macro_init(const struct device *dev) {
|
|||
// Updated state used for initial state on release.
|
||||
} else if (IS_PAUSE(cfg->bindings[i].behavior_dev)) {
|
||||
state->release_state.start_index = i + 1;
|
||||
state->release_state.count = cfg->count - i - 1;
|
||||
state->release_state.count = cfg->count - state->release_state.start_index;
|
||||
state->press_bindings_count = i;
|
||||
LOG_DBG("Release will resume at %d", state->release_state.start_index);
|
||||
break;
|
||||
|
@ -112,7 +112,7 @@ static int behavior_macro_init(const struct device *dev) {
|
|||
|
||||
static void queue_macro(uint32_t position, const struct zmk_behavior_binding bindings[],
|
||||
struct behavior_macro_trigger_state state) {
|
||||
LOG_DBG("Iterating macro bindings from %d-%d", state.start_index, state.count);
|
||||
LOG_DBG("Iterating macro bindings - starting: %d, count: %d", state.start_index, state.count);
|
||||
for (int i = state.start_index; i < state.start_index + state.count; i++) {
|
||||
if (!handle_control_binding(&state, &bindings[i])) {
|
||||
switch (state.mode) {
|
||||
|
@ -174,8 +174,8 @@ static const struct behavior_driver_api behavior_macro_driver_api = {
|
|||
#define MACRO_INST(n) \
|
||||
static struct behavior_macro_state behavior_macro_state_##n = {}; \
|
||||
static struct behavior_macro_config behavior_macro_config_##n = { \
|
||||
.default_wait_ms = DT_INST_PROP_OR(drv_inst, wait_ms, 100), \
|
||||
.default_tap_ms = DT_INST_PROP_OR(drv_inst, tap_ms, 100), \
|
||||
.default_wait_ms = DT_INST_PROP_OR(n, wait_ms, 100), \
|
||||
.default_tap_ms = DT_INST_PROP_OR(n, tap_ms, 100), \
|
||||
.count = DT_INST_PROP_LEN(n, bindings), \
|
||||
.bindings = TRANSFORMED_BEHAVIORS(n)}; \
|
||||
DEVICE_DT_INST_DEFINE(n, behavior_macro_init, device_pm_control_nop, \
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
s/.*hid_listener_keycode/kp/p
|
||||
s/.*behavior_queue_process_next/queue_process_next/p
|
|
@ -1,6 +1,18 @@
|
|||
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 50ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 10ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 50ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 10ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 50ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 10ms
|
||||
|
|
|
@ -10,42 +10,37 @@
|
|||
|
||||
/ {
|
||||
macros {
|
||||
abc_macro: abc_macro {
|
||||
label = "ABCs";
|
||||
compatible = "zmk,behavior-macro";
|
||||
#binding-cells = <0>;
|
||||
ZMK_MACRO(
|
||||
abc_macro,
|
||||
wait-ms = <10>;
|
||||
tap-ms = <50>;
|
||||
bindings = <&kp A &kp B &kp C>;
|
||||
};
|
||||
)
|
||||
|
||||
hold_shift_macro: hold_shift_macro {
|
||||
label = "HOLD_SHFT";
|
||||
compatible = "zmk,behavior-macro";
|
||||
#binding-cells = <0>;
|
||||
ZMK_MACRO(
|
||||
hold_shift_macro,
|
||||
bindings
|
||||
= <¯o_press &kp LSHFT>
|
||||
, <¯o_tap>
|
||||
, <&kp D &kp O &kp G>
|
||||
, <¯o_release &kp LSHFT>
|
||||
;
|
||||
};
|
||||
)
|
||||
|
||||
custom_timing: custom_timing_macro {
|
||||
label = "ABC_TIMING";
|
||||
compatible = "zmk,behavior-macro";
|
||||
#binding-cells = <0>;
|
||||
ZMK_MACRO(
|
||||
custom_timing,
|
||||
bindings
|
||||
= <¯o_wait_time 50>
|
||||
, <&kp A>
|
||||
, <¯o_tap_time 20>
|
||||
, <&kp B &kp C>
|
||||
;
|
||||
};
|
||||
)
|
||||
|
||||
dual_sequence_macro: dual_sequence_macro {
|
||||
label = "DUAL_SEQ";
|
||||
compatible = "zmk,behavior-macro";
|
||||
#binding-cells = <0>;
|
||||
ZMK_MACRO(
|
||||
dual_sequence_macro,
|
||||
wait-ms = <10>;
|
||||
tap-ms = <40>;
|
||||
bindings
|
||||
= <¯o_press &kp LALT>
|
||||
, <¯o_tap>
|
||||
|
@ -53,7 +48,7 @@
|
|||
, <¯o_pause_for_release>
|
||||
, <¯o_release &kp LALT>
|
||||
;
|
||||
};
|
||||
)
|
||||
};
|
||||
|
||||
keymap {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
s/.*hid_listener_keycode/kp/p
|
|
@ -0,0 +1,4 @@
|
|||
kp_pressed: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/kscan_mock.h>
|
||||
|
||||
/ {
|
||||
macros {
|
||||
ZMK_MACRO(
|
||||
mo_mod_macro,
|
||||
wait-ms = <0>;
|
||||
tap-ms = <20>;
|
||||
bindings
|
||||
= <¯o_press &mo 1 &kp LSHFT>
|
||||
, <¯o_pause_for_release>
|
||||
, <¯o_release &mo 1 &kp LSHFT>;
|
||||
)
|
||||
};
|
||||
|
||||
behaviors {
|
||||
mth: macro_tap_hold {
|
||||
compatible = "zmk,behavior-hold-tap";
|
||||
label = "MACRO_TAP_HOLD";
|
||||
#binding-cells = <2>;
|
||||
flavor = "tap-unless-interrupted";
|
||||
tapping-term-ms = <200>;
|
||||
bindings = <&mo_mod_macro>, <&kp>;
|
||||
};
|
||||
};
|
||||
|
||||
keymap {
|
||||
compatible = "zmk,keymap";
|
||||
label ="Default keymap";
|
||||
|
||||
default_layer {
|
||||
bindings = <
|
||||
&mth 0 TAB &kp A
|
||||
&kp B &kp C>;
|
||||
};
|
||||
|
||||
extra_layer {
|
||||
bindings = <
|
||||
&kp D &kp E
|
||||
&kp F &kp G>;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
&kscan {
|
||||
events = <ZMK_MOCK_PRESS(0,0,20) ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_RELEASE(0,1,10) ZMK_MOCK_RELEASE(0,0,1000)>;
|
||||
};
|
1
app/tests/macros/mo-plus-modifier-macro/events.patterns
Normal file
1
app/tests/macros/mo-plus-modifier-macro/events.patterns
Normal file
|
@ -0,0 +1 @@
|
|||
s/.*hid_listener_keycode/kp/p
|
|
@ -0,0 +1,4 @@
|
|||
kp_pressed: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00
|
46
app/tests/macros/mo-plus-modifier-macro/native_posix.keymap
Normal file
46
app/tests/macros/mo-plus-modifier-macro/native_posix.keymap
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/kscan_mock.h>
|
||||
|
||||
/ {
|
||||
macros {
|
||||
ZMK_MACRO(
|
||||
mo_mod_macro,
|
||||
wait-ms = <0>;
|
||||
tap-ms = <20>;
|
||||
bindings
|
||||
= <¯o_press &mo 1 &kp LSHFT>
|
||||
, <¯o_pause_for_release>
|
||||
, <¯o_release &mo 1 &kp LSHFT>;
|
||||
)
|
||||
};
|
||||
|
||||
keymap {
|
||||
compatible = "zmk,keymap";
|
||||
label ="Default keymap";
|
||||
|
||||
default_layer {
|
||||
bindings = <
|
||||
&mo_mod_macro &kp A
|
||||
&kp B &kp C>;
|
||||
};
|
||||
|
||||
extra_layer {
|
||||
bindings = <
|
||||
&kp D &kp E
|
||||
&kp F &kp G>;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
&kscan {
|
||||
events = <ZMK_MOCK_PRESS(0,0,20) ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_RELEASE(0,1,10) ZMK_MOCK_RELEASE(0,0,1000)>;
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
pos_state: layer: 0 position: 0, binding name: ABCs
|
||||
pos_state: layer: 0 position: 0, binding name: ZM_abc_macro
|
||||
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
pos_state: layer: 0 position: 0, binding name: ABCs
|
||||
pos_state: layer: 0 position: 0, binding name: ZM_abc_macro
|
||||
pos_state: layer: 0 position: 1, binding name: MO
|
||||
pos_state: layer: 0 position: 1, binding name: MO
|
||||
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
s/.*hid_listener_keycode/kp/p
|
||||
s/.*behavior_queue_process_next/queue_process_next/p
|
||||
s/.*queue_macro/qm/p
|
|
@ -1,6 +1,16 @@
|
|||
qm: Iterating macro bindings - starting: 0, count: 4
|
||||
queue_process_next: Invoking KEY_PRESS: 0x700e2 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0xe2 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 10ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x7002b 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 40ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x7002b 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 10ms
|
||||
kp_pressed: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
|
||||
qm: Iterating macro bindings - starting: 5, count: 2
|
||||
queue_process_next: Invoking KEY_PRESS: 0x700e2 0x00
|
||||
kp_released: usage_page 0x07 keycode 0xe2 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 0ms
|
||||
|
|
|
@ -100,7 +100,7 @@ To pause the macro until release, use `¯o_pause_for_release`, like in this e
|
|||
```
|
||||
bindings
|
||||
= <¯o_press &mo 1 &kp LSHFT>
|
||||
, <¯o_wait_for_release>
|
||||
, <¯o_pause_for_release>
|
||||
, <¯o_release &mo 1 &kp LSHFT>
|
||||
;
|
||||
```
|
||||
|
|
Loading…
Add table
Reference in a new issue