Skip to content

Commit 9cf58ec

Browse files
authored
Elaborate on keyboard level encoder functionality (#19839)
1 parent e4c41b4 commit 9cf58ec

File tree

1 file changed

+21
-45
lines changed

1 file changed

+21
-45
lines changed

docs/feature_encoders.md

+21-45
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Encoders
22

3-
Basic encoders are supported by adding this to your `rules.mk`:
3+
Basic (EC11 compatible) encoders are supported by adding this to your `rules.mk`:
44

55
```make
66
ENCODER_ENABLE = yes
@@ -104,16 +104,13 @@ Using encoder mapping pumps events through the normal QMK keycode processing pip
104104
105105
When not using `ENCODER_MAP_ENABLE = yes`, the callback functions can be inserted into your `<keyboard>.c`:
106106
107-
```c
108-
bool encoder_update_kb(uint8_t index, bool clockwise) {
109-
return encoder_update_user(index, clockwise);
110-
}
111-
```
112-
113-
or `keymap.c`:
107+
?> Those who are adding new keyboard support where encoders are enabled at the keyboard level should include basic encoder functionality at the keyboard level (`<keyboard>.c`) using the `encoder_update_kb()` function, that way it works for QMK Configuator users and exists in general.
114108
115109
```c
116-
bool encoder_update_user(uint8_t index, bool clockwise) {
110+
bool encoder_update_kb(uint8_t index, bool clockwise) {
111+
if (!encoder_update_user(index, clockwise)) {
112+
return false; /* Don't process further events if user function exists and returns false */
113+
}
117114
if (index == 0) { /* First encoder */
118115
if (clockwise) {
119116
tap_code_delay(KC_VOLU, 10);
@@ -127,53 +124,32 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
127124
rgb_matrix_decrease_hue();
128125
}
129126
}
130-
return false;
127+
return true;
131128
}
132129
```
133130

134-
!> If you return `true`, it will allow the keyboard level code to run as well. Returning `false` will override the keyboard level code, depending on how the keyboard function is set up.
135-
136-
Layer conditions can also be used with the callback function like the following:
131+
or `keymap.c`:
137132

138133
```c
139134
bool encoder_update_user(uint8_t index, bool clockwise) {
140-
switch(get_highest_layer(layer_state|default_layer_state)) {
141-
case 0:
142-
if (index == 0) {
143-
if (clockwise) {
144-
tap_code(KC_PGDN);
145-
} else {
146-
tap_code(KC_PGUP);
147-
}
148-
} else if (index == 1) {
149-
if (clockwise) {
150-
rgb_matrix_increase_speed();
151-
} else {
152-
rgb_matrix_decrease_speed();
153-
}
154-
}
155-
break;
156-
case 1:
157-
if (index == 0) {
158-
if (clockwise) {
159-
tap_code(KC_WH_D);
160-
} else {
161-
tap_code(KC_WH_U);
162-
}
163-
} else if (index == 1) {
164-
if (clockwise) {
165-
tap_code_delay(KC_VOLU, 10);
166-
} else {
167-
tap_code_delay(KC_VOLD, 10);
168-
}
169-
}
170-
break;
135+
if (index == 0) { /* First encoder */
136+
if (clockwise) {
137+
tap_code_delay(KC_VOLU, 10);
138+
} else {
139+
tap_code_delay(KC_VOLD, 10);
140+
}
141+
} else if (index == 1) { /* Second encoder */
142+
if (clockwise) {
143+
rgb_matrix_increase_hue();
144+
} else {
145+
rgb_matrix_decrease_hue();
146+
}
171147
}
172148
return false;
173149
}
174150
```
175151
176-
?> Media and mouse countrol keycodes such as `KC_VOLU` and `KC_WH_D` requires `EXTRAKEY_ENABLE = yes` and `MOUSEKEY_ENABLE = yes` respectively in user's `rules.mk` if they are not enabled as default on keyboard level configuration.
152+
!> If you return `true` in the keymap level `_user` function, it will allow the keyboard level encoder code to run on top of your own. Returning `false` will override the keyboard level function, if setup correctly. This is generally the safest option to avoid confusion.
177153
178154
## Hardware
179155

0 commit comments

Comments
 (0)