diff options
Diffstat (limited to 'docs/feature_encoders.md')
-rw-r--r-- | docs/feature_encoders.md | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/docs/feature_encoders.md b/docs/feature_encoders.md index 8e854c1e58..6a1a3750a6 100644 --- a/docs/feature_encoders.md +++ b/docs/feature_encoders.md @@ -70,22 +70,61 @@ or `keymap.c`: bool encoder_update_user(uint8_t index, bool clockwise) { if (index == 0) { /* First encoder */ if (clockwise) { - tap_code(KC_PGDN); + tap_code_delay(KC_VOLU, 10); } else { - tap_code(KC_PGUP); + tap_code_delay(KC_VOLD, 10); } } else if (index == 1) { /* Second encoder */ if (clockwise) { - tap_code(KC_DOWN); + rgb_matrix_increase_hue(); } else { - tap_code(KC_UP); + rgb_matrix_decrease_hue(); } } return false; } ``` -!> 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. +!> 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. + +Layer conditions can also be used with the callback function like the following: + +```c +bool encoder_update_user(uint8_t index, bool clockwise) { + if (get_highest_layer(layer_state|default_layer_state) > 0) { + if (index == 0) { + if (clockwise) { + tap_code(KC_WH_D); + } else { + tap_code(KC_WH_U); + } + } else if (index == 1) { + if (clockwise) { + tap_code_delay(KC_VOLU, 10); + } else { + tap_code_delay(KC_VOLD, 10); + } + } + } else { /* Layer 0 */ + if (index == 0) { + if (clockwise) { + tap_code(KC_PGDN); + } else { + tap_code(KC_PGUP); + } + } else if (index == 1) { + if (clockwise) { + rgb_matrix_increase_speed(); + } else { + rgb_matrix_decrease_speed(); + } + } + } + return false; +} +``` + +?> 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. ## Hardware @@ -93,7 +132,10 @@ The A an B lines of the encoders should be wired directly to the MCU, and the C/ ## Multiple Encoders -Multiple encoders may share pins so long as each encoder has a distinct pair of pins. +Multiple encoders may share pins so long as each encoder has a distinct pair of pins when the following conditions are met: +- using detent encoders +- pads must be high at the detent stability point which is called 'default position' in QMK +- no more than two encoders sharing a pin can be turned at the same time For example you can support two encoders using only 3 pins like this ``` |