Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Encoder callbacks to be boolean functions #12805

Merged
merged 8 commits into from
May 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 6 additions & 3 deletions docs/feature_encoders.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ If you are using different pinouts for the encoders on each half of a split keyb
The callback functions can be inserted into your `<keyboard>.c`:

```c
void encoder_update_kb(uint8_t index, bool clockwise) {
encoder_update_user(index, clockwise);
bool encoder_update_kb(uint8_t index, bool clockwise) {
return encoder_update_user(index, clockwise);
}
```

or `keymap.c`:

```c
void encoder_update_user(uint8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) { /* First encoder */
if (clockwise) {
tap_code(KC_PGDN);
Expand All @@ -75,9 +75,12 @@ void encoder_update_user(uint8_t index, bool clockwise) {
tap_code(KC_UP);
}
}
return true;
}
```

!> 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.

## Hardware

The A an B lines of the encoders should be wired directly to the MCU, and the C/common lines should be wired to ground.
Expand Down
3 changes: 2 additions & 1 deletion keyboards/0xcb/1337/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

/* rotary encoder (SW3) - add more else if blocks for more granular layer control */
#ifdef ENCODER_ENABLE
void encoder_update_user(uint8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (IS_LAYER_ON(_RGB)) {
#ifdef RGBLIGHT_ENABLE
if (clockwise) {
Expand All @@ -72,6 +72,7 @@ void encoder_update_user(uint8_t index, bool clockwise) {
tap_code(KC_VOLD);
}
}
return true;
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion keyboards/0xcb/1337/keymaps/jakob/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

/* rotary encoder (SW3) - add more else if blocks for more granular layer control */
#ifdef ENCODER_ENABLE
void encoder_update_user(uint8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (IS_LAYER_ON(_RGB)) {
#ifdef RGBLIGHT_ENABLE
if (clockwise) {
Expand All @@ -72,6 +72,7 @@ void encoder_update_user(uint8_t index, bool clockwise) {
tap_code16(C(A(KC_DOWN)));
}
}
return true;
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion keyboards/0xcb/1337/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

/* rotary encoder (SW3) - add more else if blocks for more granular layer control */
#ifdef ENCODER_ENABLE
void encoder_update_user(uint8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (IS_LAYER_ON(_RGB)) {
#ifdef RGBLIGHT_ENABLE
if (clockwise) {
Expand All @@ -72,6 +72,7 @@ void encoder_update_user(uint8_t index, bool clockwise) {
tap_code(KC_VOLD);
}
}
return true;
}
#endif

Expand Down
13 changes: 7 additions & 6 deletions keyboards/10bleoledhub/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/
/* Keymap _0: (Base Layer) Default Layer

* .-----.
* |PGUP |
* |PGUP |
* |-----------------.
* | 7 | 8 | 9 |
* |-----|-----|-----|
Expand All @@ -37,12 +37,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/

#include QMK_KEYBOARD_H
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
[0] = LAYOUT(
KC_PGUP,
KC_KP_7, KC_KP_8, MO(1),
KC_KP_7, KC_KP_8, MO(1),
KC_P4, KC_P5, KC_P6,
KC_P1, KC_P2, KC_P3),
[1] = LAYOUT(
[1] = LAYOUT(
KC_NUMLOCK,
RGB_TOG, RGB_MOD, RGB_M_K,
RGB_SAI, RGB_SAD, RGB_HUI,
Expand All @@ -58,14 +58,15 @@ static void render_logo(void) {
void oled_task_user(void) { render_logo(); }
#endif

void encoder_update_user(uint8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) { /* First encoder */
if (clockwise) {
tap_code(KC_PGDN);
} else {
tap_code(KC_PGUP);
}
}
}
return true;
}


Expand Down
15 changes: 8 additions & 7 deletions keyboards/10bleoledhub/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.*/
along with this program. If not, see <http://www.gnu.org/licenses/>.*/
/* Keymap _0: (Base Layer) Default Layer

* .-----.
* |PGUP |
* |PGUP |
* |-----------------.
* | 7 | 8 | 9 |
* |-----|-----|-----|
Expand All @@ -37,12 +37,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/

#include QMK_KEYBOARD_H
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
[0] = LAYOUT(
KC_PGUP,
KC_KP_7, KC_KP_8, MO(1),
KC_KP_7, KC_KP_8, MO(1),
KC_P4, KC_P5, KC_P6,
KC_P1, KC_P2, KC_P3),
[1] = LAYOUT(
[1] = LAYOUT(
KC_NUMLOCK,
RGB_TOG, RGB_MOD, RGB_M_K,
RGB_SAI, RGB_SAD, RGB_HUI,
Expand All @@ -58,14 +58,15 @@ static void render_logo(void) {
void oled_task_user(void) { render_logo(); }
#endif

void encoder_update_user(uint8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) { /* First encoder */
if (clockwise) {
tap_code(KC_PGDN);
} else {
tap_code(KC_PGUP);
}
}
}
return true;
}


Expand Down
3 changes: 2 additions & 1 deletion keyboards/1upkeyboards/sweet16/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {

#ifdef ENCODER_ENABLE
#include "encoder.h"
void encoder_update_user(int8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) { /* First encoder */
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
}
return true;
}
#endif
4 changes: 2 additions & 2 deletions keyboards/1upkeyboards/sweet16/v2/promicro/promicro.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "encoder.h"

#ifdef ENCODER_ENABLED
void encoder_update_kb(int8_t index, bool clockwise) {
encoder_update_user(index, clockwise);
bool encoder_update_kb(uint8_t index, bool clockwise) {
return encoder_update_user(index, clockwise);
}
#endif
4 changes: 2 additions & 2 deletions keyboards/2key2crawl/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ void matrix_init_user(void) {



void encoder_update_user(int8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) {
if (clockwise) {
tap_code(KC_PGUP);
} else {
tap_code(KC_PGDN);
}
}
return true;
}

4 changes: 2 additions & 2 deletions keyboards/2key2crawl/keymaps/tabs/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ void matrix_init_user(void) {
debug_config.enable = 1;
}

void encoder_update_user(int8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) {
if (clockwise) {
tap_code16(C(KC_T));
} else {
tap_code16(C(KC_W));
}
}
return true;
}

3 changes: 2 additions & 1 deletion keyboards/2key2crawl/keymaps/vol/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ void matrix_init_user(void) {
debug_config.enable = 1;
}

void encoder_update_user(int8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) {
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
}
return true;
}
35 changes: 18 additions & 17 deletions keyboards/45_ats/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
/*
Copyright 2020 Alec Penland
Copyright 2020 Garret Gartner
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include QMK_KEYBOARD_H

Expand All @@ -31,7 +31,7 @@ enum ats_layers{
#define RS_SLS RSFT_T(KC_SLSH)

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Default QWERTY layer
/* Default QWERTY layer
* ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ ┌───┐
* │Esc│ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │Del│BkS│ │PgU│
* ├───┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴───┤ ├───┤
Expand Down Expand Up @@ -96,12 +96,13 @@ layer_state_t layer_state_set_user(layer_state_t state) {
return state;
}

void encoder_update_user(uint8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) {
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
}
return true;
}
35 changes: 18 additions & 17 deletions keyboards/45_ats/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
/*
Copyright 2020 Alec Penland
Copyright 2020 Garret Gartner
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include QMK_KEYBOARD_H

Expand All @@ -31,7 +31,7 @@ enum ats_layers{
#define RS_SLS RSFT_T(KC_SLSH)

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Default QWERTY layer
/* Default QWERTY layer
* ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ ┌───┐
* │Esc│ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │Del│BkS│ │PgU│
* ├───┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴───┤ ├───┤
Expand Down Expand Up @@ -96,12 +96,13 @@ layer_state_t layer_state_set_user(layer_state_t state) {
return state;
}

void encoder_update_user(uint8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) {
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
}
return true;
}
5 changes: 3 additions & 2 deletions keyboards/7c8/framework/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};

void encoder_update_user(uint8_t index, bool clockwise) {
bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) {
switch (get_highest_layer(layer_state)) {
case _BASE:
Expand All @@ -93,7 +93,7 @@ void encoder_update_user(uint8_t index, bool clockwise) {
break;

case _RAISE:
if (clockwise) {
if (clockwise) {
tap_code16(LCTL(KC_RGHT));
} else {
tap_code16(LCTL(KC_LEFT));
Expand All @@ -120,6 +120,7 @@ void encoder_update_user(uint8_t index, bool clockwise) {
break;
}
}
return true;
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
Expand Down