diff options
author | jack <0x6A73@pm.me> | 2023-04-03 10:18:17 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 10:18:17 -0600 |
commit | 36ab0c0aaa613fe0946e10133315b071c0d87012 (patch) | |
tree | ac87fe394264e2b265ad3db376bb88a91d084898 | |
parent | 7e48a4e80f4c3975cf0aae68986c7ead2576dcf3 (diff) |
Add core/fallback encoder behaviour (#20320)
107 files changed, 30 insertions, 1759 deletions
diff --git a/docs/feature_encoders.md b/docs/feature_encoders.md index 1c521a4eff..74857c265d 100644 --- a/docs/feature_encoders.md +++ b/docs/feature_encoders.md @@ -102,9 +102,9 @@ Using encoder mapping pumps events through the normal QMK keycode processing pip ## Callbacks -When not using `ENCODER_MAP_ENABLE = yes`, the callback functions can be inserted into your `<keyboard>.c`: +?> [**Default Behaviour**](https://github.com/qmk/qmk_firmware/blob/master/quantum/encoder.c#L79-#L98): all encoders installed will function as volume up (`KC_VOLU`) on clockwise rotation and volume down (`KC_VOLD`) on counter-clockwise rotation. If you do not wish to override this, no further configuration is necessary. -?> 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. +If you would like the alter the default behaviour, and are not using `ENCODER_MAP_ENABLE = yes`, the callback functions can be inserted into your `<keyboard>.c`: ```c bool encoder_update_kb(uint8_t index, bool clockwise) { @@ -113,9 +113,9 @@ bool encoder_update_kb(uint8_t index, bool clockwise) { } if (index == 0) { /* First encoder */ if (clockwise) { - tap_code_delay(KC_VOLU, 10); + tap_code(KC_PGDN); } else { - tap_code_delay(KC_VOLD, 10); + tap_code(KC_PGUP); } } else if (index == 1) { /* Second encoder */ if (clockwise) { @@ -134,9 +134,9 @@ or `keymap.c`: bool encoder_update_user(uint8_t index, bool clockwise) { if (index == 0) { /* First encoder */ if (clockwise) { - tap_code_delay(KC_VOLU, 10); + tap_code(KC_PGDN); } else { - tap_code_delay(KC_VOLD, 10); + tap_code(KC_PGUP); } } else if (index == 1) { /* Second encoder */ if (clockwise) { @@ -149,7 +149,7 @@ bool encoder_update_user(uint8_t index, bool clockwise) { } ``` -!> 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. +!> If you return `true` in the keymap level `_user` function, it will allow the keyboard/core 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. ## Hardware diff --git a/keyboards/acheron/shark/beta/beta.c b/keyboards/acheron/shark/beta/beta.c index 06fd36f797..5592353ad7 100644 --- a/keyboards/acheron/shark/beta/beta.c +++ b/keyboards/acheron/shark/beta/beta.c @@ -20,14 +20,3 @@ void board_init(void) { setPinInput(B6); setPinInput(B7); } - -#ifdef ENCODER_ENABLE -bool encoder_update_kb(uint8_t index, bool clockwise) { - if(!encoder_update_user(index, clockwise)) return false; - if (index == 0) { - if (clockwise) tap_code_delay(KC_VOLU, 10); - else tap_code_delay(KC_VOLD, 10); - } - return true; -} -#endif diff --git a/keyboards/adafruit/macropad/macropad.c b/keyboards/adafruit/macropad/macropad.c index 5cffdc6c97..819b5067d8 100644 --- a/keyboards/adafruit/macropad/macropad.c +++ b/keyboards/adafruit/macropad/macropad.c @@ -40,17 +40,3 @@ led_config_t g_led_config = { { } }; #endif - -#ifdef ENCODER_ENABLE -bool encoder_update_kb(uint8_t index, bool clockwise) { - if (!encoder_update_user(index, clockwise)) { return false; } - if (index == 0) { - if (clockwise) { - tap_code_delay(KC_VOLU, 10); - } else { - tap_code_delay(KC_VOLD, 10); - } - } - return true; -} -#endif diff --git a/keyboards/aidansmithdotdev/fine40/fine40.c b/keyboards/aidansmithdotdev/fine40/fine40.c index 0bd190321a..2e60e7c921 100644 --- a/keyboards/aidansmithdotdev/fine40/fine40.c +++ b/keyboards/aidansmithdotdev/fine40/fine40.c @@ -68,18 +68,3 @@ bool oled_task_kb(void) { return(true); } #endif - -#ifdef ENCODER_ENABLE -bool encoder_update_kb(uint8_t index, bool clockwise) { - if (!encoder_update_user(index, clockwise)) { - return false; - } - // Volume control - if (clockwise) { - tap_code(KC_VOLU); - } else { - tap_code(KC_VOLD); - } - return true; -} -#endif
\ No newline at end of file diff --git a/keyboards/anavi/knob1/knob1.c b/keyboards/anavi/knob1/knob1.c index c1ed7b7726..bb6f1e38bf 100644 --- a/keyboards/anavi/knob1/knob1.c +++ b/keyboards/anavi/knob1/knob1.c @@ -14,18 +14,6 @@ void keyboard_post_init_kb(void) { keyboard_post_init_user(); } -#ifdef ENCODER_ENABLE -bool encoder_update_kb(uint8_t index, bool clockwise) { - if (!encoder_update_user(index, clockwise)) { return false; } - if (clockwise) { - tap_code(KC_VOLU); - } else { - tap_code(KC_VOLD); - } - return true; -} -#endif - #ifdef OLED_ENABLE bool oled_task_kb(void) { diff --git a/keyboards/anavi/macropad10/macropad10.c b/keyboards/anavi/macropad10/macropad10.c deleted file mode 100644 index bebefd0da9..0000000000 --- a/keyboards/anavi/macropad10/macropad10.c +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2022 Leon Anavi <leon@anavi.org> -// SPDX-License-Identifier: GPL-2.0-or-later -#include "encoder.h" - -#ifdef ENCODER_ENABLE -bool encoder_update_kb(uint8_t index, bool clockwise) { - if (!encoder_update_user(index, clockwise)) { return false; } - if (clockwise) { - tap_code(KC_VOLU); - } else { - tap_code(KC_VOLD); - } - return true; -} -#endif - diff --git a/keyboards/ano/ano.c b/keyboards/ano/ano.c index 0b6926deaf..925a24fbf6 100644 --- a/keyboards/ano/ano.c +++ b/keyboards/ano/ano.c @@ -15,27 +15,3 @@ */ #include "ano.h" - -/* The encoder_update_user is a function. - * It'll be called by QMK every time you turn the encoder. - * - * The index parameter tells you which encoder was turned. If you only have - * one encoder, the index will always be zero. - * - * The clockwise parameter tells you the direction of the encoder. It'll be - * true when you turned the encoder clockwise, and false otherwise. - */ - -#ifdef ENCODER_ENABLE -bool encoder_update_kb(uint8_t index, bool clockwise) { - if (!encoder_update_user(index, clockwise)) { return false; } - if (index == 0) { - if (clockwise) { - tap_code(KC_AUDIO_VOL_UP); - } else { - tap_code(KC_AUDIO_VOL_DOWN); - } - } - return true; -} -#endif
\ No newline at end of file diff --git a/keyboards/atlantis/ps17/ps17.c b/keyboards/atlantis/ps17/ps17.c index ccac1ce923..d660bdee6a 100644 --- a/keyboards/atlantis/ps17/ps17.c +++ b/keyboards/atlantis/ps17/ps17.c @@ -19,23 +19,6 @@ void keyboard_pre_init_kb(void) { keyboard_pre_init_user(); } -#if defined(ENCODER_ENABLE) -bool encoder_update_kb(uint8_t index, bool clockwise) { - if (!encoder_update_user(index, clockwise)) { - /* Don't process further events if user function exists and returns false */ - return false; - } - - /* Ignore index - only one encoder on this board */ - if (clockwise) { - tap_code_delay(KC_VOLU, 10); - } else { - tap_code_delay(KC_VOLD, 10); - } - return false; -} -#endif - #ifdef RGB_MATRIX_ENABLE void suspend_power_down_kb(void) { /* Disable indicator LEDs when going to sleep */ diff --git a/keyboards/bolsa/damapad/damapad.c b/keyboards/bolsa/damapad/damapad.c index d57a60c |