aboutsummaryrefslogtreecommitdiff
path: root/keyboards/atlantis/encoder_actions.c
diff options
context:
space:
mode:
authorfOmey <pauly.galea@gmail.com>2022-01-14 05:59:16 +1100
committerGitHub <noreply@github.com>2022-01-13 10:59:16 -0800
commit8a6da095d22d66c0ba36ce8731c9d821ca4262e9 (patch)
tree8b114aba7ee61982cd7e841199abe27490191df6 /keyboards/atlantis/encoder_actions.c
parent6770f77270d028a3d72f28e7891bb5213fdbae24 (diff)
downloadqmk_firmware-8a6da095d22d66c0ba36ce8731c9d821ca4262e9.tar.gz
qmk_firmware-8a6da095d22d66c0ba36ce8731c9d821ca4262e9.zip
[Keyboard] Atlantis AK81_VE support (#15392)
Diffstat (limited to 'keyboards/atlantis/encoder_actions.c')
-rw-r--r--keyboards/atlantis/encoder_actions.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/keyboards/atlantis/encoder_actions.c b/keyboards/atlantis/encoder_actions.c
new file mode 100644
index 000000000..b41a248a8
--- /dev/null
+++ b/keyboards/atlantis/encoder_actions.c
@@ -0,0 +1,68 @@
1/* Copyright 2020 Neil Brian Ramirez
2 * Copyright 2021 drashna jael're (@drashna)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "encoder_actions.h"
19
20#if defined(VIA_ENABLE) && defined(ENCODER_ENABLE)
21
22# ifdef ENCODERS
23static uint8_t encoder_state[ENCODERS] = {0};
24static keypos_t encoder_cw[ENCODERS] = ENCODERS_CW_KEY;
25static keypos_t encoder_ccw[ENCODERS] = ENCODERS_CCW_KEY;
26# endif
27
28void encoder_action_unregister(void) {
29# ifdef ENCODERS
30 for (int index = 0; index < ENCODERS; ++index) {
31 if (encoder_state[index]) {
32 keyevent_t encoder_event = (keyevent_t) {
33 .key = encoder_state[index] >> 1 ? encoder_cw[index] : encoder_ccw[index],
34 .pressed = false,
35 .time = (timer_read() | 1)
36 };
37 encoder_state[index] = 0;
38 action_exec(encoder_event);
39 }
40 }
41# endif
42}
43
44void encoder_action_register(uint8_t index, bool clockwise) {
45# ifdef ENCODERS
46 keyevent_t encoder_event = (keyevent_t) {
47 .key = clockwise ? encoder_cw[index] : encoder_ccw[index],
48 .pressed = true,
49 .time = (timer_read() | 1)
50 };
51 encoder_state[index] = (clockwise ^ 1) | (clockwise << 1);
52 action_exec(encoder_event);
53# endif
54}
55
56void matrix_scan_kb(void) {
57 encoder_action_unregister();
58 matrix_scan_user();
59}
60
61bool encoder_update_kb(uint8_t index, bool clockwise) {
62 encoder_action_register(index, clockwise);
63 // don't return user actions, because they are in the keymap
64 // encoder_update_user(index, clockwise);
65 return true;
66};
67
68#endif