diff options
Diffstat (limited to 'keyboards/wekey/we27/encoder_actions.c')
| -rw-r--r-- | keyboards/wekey/we27/encoder_actions.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/keyboards/wekey/we27/encoder_actions.c b/keyboards/wekey/we27/encoder_actions.c new file mode 100644 index 000000000..0f32ac272 --- /dev/null +++ b/keyboards/wekey/we27/encoder_actions.c | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | /* Copyright 2020 Neil Brian Ramirez | ||
| 2 | * Copyright 2021 drashna jael're (@drashna) | ||
| 3 | * Copyright 2021 uybv | ||
| 4 | * | ||
| 5 | * This program is free software: you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation, either version 3 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "encoder_actions.h" | ||
| 20 | |||
| 21 | #ifdef ENCODER_ENABLE | ||
| 22 | |||
| 23 | # ifdef ENCODERS | ||
| 24 | static uint8_t encoder_state[ENCODERS] = {0}; | ||
| 25 | static keypos_t encoder_cw[ENCODERS] = ENCODERS_CW_KEY; | ||
| 26 | static keypos_t encoder_ccw[ENCODERS] = ENCODERS_CCW_KEY; | ||
| 27 | # endif | ||
| 28 | |||
| 29 | void encoder_action_unregister(void) { | ||
| 30 | # ifdef ENCODERS | ||
| 31 | for (int index = 0; index < ENCODERS; ++index) { | ||
| 32 | if (encoder_state[index]) { | ||
| 33 | keyevent_t encoder_event = (keyevent_t) { | ||
| 34 | .key = encoder_state[index] >> 1 ? encoder_cw[index] : encoder_ccw[index], | ||
| 35 | .pressed = false, | ||
| 36 | .time = (timer_read() | 1) | ||
| 37 | }; | ||
| 38 | encoder_state[index] = 0; | ||
| 39 | action_exec(encoder_event); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | # endif | ||
| 43 | } | ||
| 44 | |||
| 45 | void encoder_action_register(uint8_t index, bool clockwise) { | ||
| 46 | # ifdef ENCODERS | ||
| 47 | keyevent_t encoder_event = (keyevent_t) { | ||
| 48 | .key = clockwise ? encoder_cw[index] : encoder_ccw[index], | ||
| 49 | .pressed = true, | ||
| 50 | .time = (timer_read() | 1) | ||
| 51 | }; | ||
| 52 | encoder_state[index] = (clockwise ^ 1) | (clockwise << 1); | ||
| 53 | action_exec(encoder_event); | ||
| 54 | # endif | ||
| 55 | } | ||
| 56 | |||
| 57 | #endif | ||
