Skip to content

Commit

Permalink
Add core/fallback encoder behaviour (#20320)
Browse files Browse the repository at this point in the history
  • Loading branch information
waffle87 committed Apr 3, 2023
1 parent 7e48a4e commit 36ab0c0
Show file tree
Hide file tree
Showing 107 changed files with 30 additions and 1,759 deletions.
14 changes: 7 additions & 7 deletions docs/feature_encoders.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand Down
11 changes: 0 additions & 11 deletions keyboards/acheron/shark/beta/beta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 0 additions & 14 deletions keyboards/adafruit/macropad/macropad.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 0 additions & 15 deletions keyboards/aidansmithdotdev/fine40/fine40.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 0 additions & 12 deletions keyboards/anavi/knob1/knob1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 0 additions & 16 deletions keyboards/anavi/macropad10/macropad10.c

This file was deleted.

24 changes: 0 additions & 24 deletions keyboards/ano/ano.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 0 additions & 17 deletions keyboards/atlantis/ps17/ps17.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
14 changes: 0 additions & 14 deletions keyboards/bolsa/damapad/damapad.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,3 @@ oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
return OLED_ROTATION_180;
}
#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
10 changes: 0 additions & 10 deletions keyboards/cannonkeys/balance/balance.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,3 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http:https://www.gnu.org/licenses/>.
*/
#include "balance.h"

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;
}
14 changes: 0 additions & 14 deletions keyboards/cannonkeys/ortho60v2/ortho60v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,3 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http:https://www.gnu.org/licenses/>.
*/
#include "ortho60v2.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_delay(KC_VOLU, 10);
} else {
tap_code_delay(KC_VOLD, 10);
}
return true;
}
#endif
29 changes: 0 additions & 29 deletions keyboards/checkerboards/phoenix45_ortho/phoenix45_ortho.c

This file was deleted.

29 changes: 0 additions & 29 deletions keyboards/checkerboards/quark/quark.c

This file was deleted.

12 changes: 0 additions & 12 deletions keyboards/checkerboards/quark_squared/quark_squared.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,3 @@
*/

#include "quark_squared.h"

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_VOLD, 10);
} else {
tap_code_delay(KC_VOLU, 10);
}
}
return true;
}
16 changes: 0 additions & 16 deletions keyboards/chocofly/chocofly.c

This file was deleted.

12 changes: 0 additions & 12 deletions keyboards/ck60i/ck60i.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,3 @@ along with this program. If not, see <http:https://www.gnu.org/licenses/>.
*/

#include "ck60i.h"

bool encoder_update_kb(uint8_t index, bool clockwise) {
if (!encoder_update_user(index, clockwise)) return false;
if (index == 0) { /* First encoder */
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
}
return true;
}
29 changes: 0 additions & 29 deletions keyboards/coban/pad3a/pad3a.c

This file was deleted.

Loading

0 comments on commit 36ab0c0

Please sign in to comment.