aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAlbert Y <76888457+filterpaper@users.noreply.github.com>2021-12-27 18:16:19 +0800
committerGitHub <noreply@github.com>2021-12-27 21:16:19 +1100
commit067d94f0b6c957c4e1c0ae1d680b420651fb3766 (patch)
tree60f26de5f3ffe6c66c99ff9ccc872711da293513 /docs
parentdad7424becdb10d1dc3ad70a456fc40513255e71 (diff)
downloadqmk_firmware-067d94f0b6c957c4e1c0ae1d680b420651fb3766.tar.gz
qmk_firmware-067d94f0b6c957c4e1c0ae1d680b420651fb3766.zip
Add layer condition example to encoder callback function (#15490)
Co-authored-by: filterpaper <filterpaper@localhost>
Diffstat (limited to 'docs')
-rw-r--r--docs/feature_encoders.md37
1 files changed, 37 insertions, 0 deletions
diff --git a/docs/feature_encoders.md b/docs/feature_encoders.md
index 8e854c1e5..8ab5ca9c4 100644
--- a/docs/feature_encoders.md
+++ b/docs/feature_encoders.md
@@ -87,6 +87,43 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
87 87
88!> If you return `true`, this will allow the keyboard level code to run, as well. Returning `false` will override the keyboard level code. Depending on how the keyboard level function is set up. 88!> If you return `true`, this will allow the keyboard level code to run, as well. Returning `false` will override the keyboard level code. Depending on how the keyboard level function is set up.
89 89
90Layer conditions can also be used with the callback function like the following:
91
92```c
93bool encoder_update_user(uint8_t index, bool clockwise) {
94 if (get_highest_layer(layer_state|default_layer_state) > 0) {
95 if (index == 0) {
96 if (clockwise) {
97 tap_code(KC_WH_D);
98 } else {
99 tap_code(KC_WH_U);
100 }
101 } else if (index == 1) {
102 if (clockwise) {
103 tap_code(KC_VOLU);
104 } else {
105 tap_code(KC_VOLD);
106 }
107 }
108 } else { /* Layer 0 */
109 if (index == 0) {
110 if (clockwise) {
111 tap_code(KC_PGDN);
112 } else {
113 tap_code(KC_PGUP);
114 }
115 } else if (index == 1) {
116 if (clockwise) {
117 tap_code(KC_DOWN);
118 } else {
119 tap_code(KC_UP);
120 }
121 }
122 }
123 return false;
124}
125```
126
90## Hardware 127## Hardware
91 128
92The A an B lines of the encoders should be wired directly to the MCU, and the C/common lines should be wired to ground. 129The A an B lines of the encoders should be wired directly to the MCU, and the C/common lines should be wired to ground.