Skip to content

Commit 92a287e

Browse files
caksoylarJon Sharp
authored andcommitted
fix(behaviors): Correct macro release state for parametrized macros (zmkfirmware#2942)
test(behaviors): Add parametrized macro test that fails fix(behaviors): Correct macro release state for parametrized
1 parent 733a536 commit 92a287e

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

app/src/behaviors/behavior_macro.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ static int behavior_macro_init(const struct device *dev) {
129129
LOG_DBG("Release will resume at %d", state->release_state.start_index);
130130
break;
131131
} else {
132-
// Ignore regular invokable bindings
132+
// Mostly ignore regular invokable bindings, except they will consume macro parameters
133+
state->release_state.param1_source = PARAM_SOURCE_BINDING;
134+
state->release_state.param2_source = PARAM_SOURCE_BINDING;
133135
}
134136
}
135137

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
s/.*hid_listener_keycode/kp/p
2+
s/.*mo_keymap_binding/mo/p
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
2+
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
3+
mo_pressed: position 0 layer 1
4+
kp_pressed: usage_page 0x07 keycode 0x1C implicit_mods 0x00 explicit_mods 0x00
5+
kp_released: usage_page 0x07 keycode 0x1C implicit_mods 0x00 explicit_mods 0x00
6+
mo_released: position 0 layer 1
7+
kp_pressed: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
8+
kp_released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <dt-bindings/zmk/keys.h>
2+
#include <behaviors.dtsi>
3+
#include <dt-bindings/zmk/kscan_mock.h>
4+
5+
/ {
6+
macros {
7+
kp_l1: kp_l1 {
8+
compatible = "zmk,behavior-macro-one-param";
9+
#binding-cells = <1>;
10+
wait-ms = <5>;
11+
tap-ms = <5>;
12+
bindings
13+
= <&macro_param_1to1>
14+
, <&macro_tap &kp MACRO_PLACEHOLDER>
15+
, <&macro_press &mo 1>
16+
, <&macro_pause_for_release>
17+
, <&macro_release &mo 1>;
18+
};
19+
};
20+
21+
keymap {
22+
compatible = "zmk,keymap";
23+
24+
default_layer {
25+
bindings = <
26+
&kp_l1 A &kp B
27+
&kp C &none>;
28+
};
29+
30+
other_layer {
31+
bindings = <
32+
&kp X &kp Y
33+
&kp Z &none>;
34+
};
35+
};
36+
};
37+
38+
&kscan {
39+
events = <
40+
ZMK_MOCK_PRESS(0,0,20) // press macro (taps A)
41+
ZMK_MOCK_PRESS(0,1,20) // press Y
42+
ZMK_MOCK_RELEASE(0,1,20) // release Y
43+
ZMK_MOCK_RELEASE(0,0,20) // release macro
44+
ZMK_MOCK_PRESS(1,0,10) // press C
45+
ZMK_MOCK_RELEASE(1,0,10) // release C
46+
>;
47+
};

0 commit comments

Comments
 (0)