Skip to content

Commit 9f929a9

Browse files
authored
feat(keymap): add support for sensor bindings
2 parents 5720579 + c73dc62 commit 9f929a9

File tree

2 files changed

+71
-9
lines changed

2 files changed

+71
-9
lines changed

pkg/keymap/parser.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type File struct {
1717

1818
Includes []*Include `parser:"@@+"`
1919
Defines []*Define `parser:"@@*"`
20-
Configs []*Config `parser:"@@"`
20+
Configs []*Config `parser:"@@*"`
2121
Device *Device `parser:"'/' '{' @@ '}'';'"`
2222
}
2323

@@ -51,7 +51,7 @@ type Value struct {
5151
type Device struct {
5252
Pos lexer.Position
5353

54-
Combos *Combos `parser:"'combos' '{' @@"`
54+
Combos *Combos `parser:"('combos' '{' @@)?"`
5555
Keymap *Keymap `parser:"'keymap' '{' @@"`
5656
}
5757

@@ -81,8 +81,10 @@ type Keymap struct {
8181
type Layer struct {
8282
Pos lexer.Position
8383

84-
Name string `parser:"@Ident '{'"`
85-
Bindings []*Behavior `parser:"'bindings' '=' '<'@@+'>'';' '}'';'"`
84+
Name string `parser:"@Ident '{'"`
85+
Bindings []*Behavior `parser:"'bindings' '=' '<'@@+'>'';'"`
86+
SensorBindings []*Behavior `parser:"('sensor''-''bindings' '=' '<'@@+'>'';')?"`
87+
EndBrace string `parser:" '}'';'"`
8688
}
8789

8890
type List struct {

pkg/keymap/parser_test.go

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66
)
77

8-
var keymapFile = `
8+
var cradioKeymapFile = `
99
#include <behaviors.dtsi>
1010
#include <dt-bindings/zmk/keys.h>
1111
#include <dt-bindings/zmk/bt.h>
@@ -104,10 +104,70 @@ var keymapFile = `
104104
};
105105
`
106106

107+
//nolint:lll // ignoring line length because of visual spacing
108+
var sofleKeymapFile = `/*
109+
* Copyright (c) 2020 The ZMK Contributors
110+
*
111+
* SPDX-License-Identifier: MIT
112+
*/
113+
114+
#include <behaviors.dtsi>
115+
#include <dt-bindings/zmk/keys.h>
116+
#include <dt-bindings/zmk/bt.h>
117+
118+
/ {
119+
keymap {
120+
compatible = "zmk,keymap";
121+
122+
default_layer {
123+
bindings = <
124+
&kp GRAVE &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp N8 &kp N9 &kp N0 &none
125+
&kp ESC &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp BSPC
126+
&kp TAB &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SEMI &kp SQT
127+
&kp LSHFT &kp Z &kp X &kp C &kp V &kp B &kp C_MUTE &none &kp N &kp M &kp COMMA &kp DOT &kp FSLH &kp RSHFT
128+
&kp LGUI &kp LALT &kp LCTRL &mo 1 &kp RET &kp SPACE &mo 2 &kp RCTRL &kp RALT &kp RGUI
129+
>;
130+
131+
sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN &inc_dec_kp PG_UP PG_DN>;
132+
};
133+
134+
lower_layer {
135+
bindings = <
136+
&trans &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp F8 &kp F9 &kp F10 &kp F11
137+
&kp GRAVE &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp N8 &kp N9 &kp N0 &kp F12
138+
&trans &kp EXCL &kp AT &kp HASH &kp DLLR &kp PRCNT &kp CARET &kp AMPS &kp KP_MULTIPLY &kp LPAR &kp RPAR &kp PIPE
139+
&trans &kp EQUAL &kp MINUS &kp KP_PLUS &kp LBRC &kp RBRC &trans &trans &kp LBKT &kp RBKT &kp SEMI &kp COLON &kp BSLH &trans
140+
&trans &trans &trans &trans &trans &trans &trans &trans &trans &trans
141+
>;
142+
143+
sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN &inc_dec_kp PG_UP PG_DN>;
144+
};
145+
146+
raise_layer {
147+
bindings = <
148+
&bt BT_CLR &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 &bt BT_SEL 4 &trans &trans &trans &trans &trans &trans
149+
&trans &kp INS &kp PSCRN &kp K_CMENU &trans &trans &kp PG_UP &trans &kp UP &trans &kp N0 &trans
150+
&trans &kp LALT &kp LCTRL &kp LSHFT &trans &kp CLCK &kp PG_DN &kp LEFT &kp DOWN &kp RIGHT &kp DEL &kp BSPC
151+
&trans &kp K_UNDO &kp K_CUT &kp K_COPY &kp K_PASTE &trans &trans &trans &trans &trans &trans &trans &trans &trans
152+
&trans &trans &trans &trans &trans &trans &trans &trans &trans &trans
153+
>;
154+
155+
sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN &inc_dec_kp PG_UP PG_DN>;
156+
};
157+
};
158+
};
159+
`
160+
107161
func Test(t *testing.T) {
108-
r := strings.NewReader(keymapFile)
109-
_, err := Parse(r)
110-
if err != nil {
111-
t.Fatal(err)
162+
cradioRaw := strings.NewReader(cradioKeymapFile)
163+
_, cradioErr := Parse(cradioRaw)
164+
if cradioErr != nil {
165+
t.Fatal(cradioErr)
166+
}
167+
168+
sofleRaw := strings.NewReader(sofleKeymapFile)
169+
_, sofleErr := Parse(sofleRaw)
170+
if sofleErr != nil {
171+
t.Fatal(sofleErr)
112172
}
113173
}

0 commit comments

Comments
 (0)