aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_haptic.c
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-07-26 03:14:58 +0100
committerGitHub <noreply@github.com>2021-07-25 19:14:58 -0700
commitf945c352e7db3fedb16c90f9f176b3df6e0b62ae (patch)
tree8b2cd252ad036b5199603c9c755c01be5cb326a2 /quantum/process_keycode/process_haptic.c
parent4bb595f94b5c77e7a961ff69d2b4d9c53a9094fc (diff)
downloadqmk_firmware-f945c352e7db3fedb16c90f9f176b3df6e0b62ae.tar.gz
qmk_firmware-f945c352e7db3fedb16c90f9f176b3df6e0b62ae.zip
Haptic: driver-> feature (#13713)
Diffstat (limited to 'quantum/process_keycode/process_haptic.c')
-rw-r--r--quantum/process_keycode/process_haptic.c147
1 files changed, 147 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_haptic.c b/quantum/process_keycode/process_haptic.c
new file mode 100644
index 000000000..29a4ffd10
--- /dev/null
+++ b/quantum/process_keycode/process_haptic.c
@@ -0,0 +1,147 @@
1/* Copyright 2021 QMK
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#include "haptic.h"
17#include "process_haptic.h"
18#include "quantum_keycodes.h"
19
20__attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) {
21 switch (keycode) {
22#ifdef NO_HAPTIC_MOD
23 case QK_MOD_TAP ... QK_MOD_TAP_MAX:
24 if (record->tap.count == 0) return false;
25 break;
26 case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
27 if (record->tap.count != TAPPING_TOGGLE) return false;
28 break;
29 case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
30 if (record->tap.count == 0) return false;
31 break;
32 case KC_LCTRL ... KC_RGUI:
33 case QK_MOMENTARY ... QK_MOMENTARY_MAX:
34#endif
35#ifdef NO_HAPTIC_FN
36 case KC_FN0 ... KC_FN31:
37#endif
38#ifdef NO_HAPTIC_ALPHA
39 case KC_A ... KC_Z:
40#endif
41#ifdef NO_HAPTIC_PUNCTUATION
42 case KC_ENTER:
43 case KC_ESCAPE:
44 case KC_BSPACE:
45 case KC_SPACE:
46 case KC_MINUS:
47 case KC_EQUAL:
48 case KC_LBRACKET:
49 case KC_RBRACKET:
50 case KC_BSLASH:
51 case KC_NONUS_HASH:
52 case KC_SCOLON:
53 case KC_QUOTE:
54 case KC_GRAVE:
55 case KC_COMMA:
56 case KC_SLASH:
57 case KC_DOT:
58 case KC_NONUS_BSLASH:
59#endif
60#ifdef NO_HAPTIC_LOCKKEYS
61 case KC_CAPSLOCK:
62 case KC_SCROLLLOCK:
63 case KC_NUMLOCK:
64#endif
65#ifdef NO_HAPTIC_NAV
66 case KC_PSCREEN:
67 case KC_PAUSE:
68 case KC_INSERT:
69 case KC_DELETE:
70 case KC_PGDOWN:
71 case KC_PGUP:
72 case KC_LEFT:
73 case KC_UP:
74 case KC_RIGHT:
75 case KC_DOWN:
76 case KC_END:
77 case KC_HOME:
78#endif
79#ifdef NO_HAPTIC_NUMERIC
80 case KC_1 ... KC_0:
81#endif
82 return false;
83 }
84 return true;
85}
86
87bool process_haptic(uint16_t keycode, keyrecord_t *record) {
88 if (record->event.pressed) {
89 switch (keycode) {
90 case HPT_ON:
91 haptic_enable();
92 break;
93 case HPT_OFF:
94 haptic_disable();
95 break;
96 case HPT_TOG:
97 haptic_toggle();
98 break;
99 case HPT_RST:
100 haptic_reset();
101 break;
102 case HPT_FBK:
103 haptic_feedback_toggle();
104 break;
105 case HPT_BUZ:
106 haptic_buzz_toggle();
107 break;
108 case HPT_MODI:
109 haptic_mode_increase();
110 break;
111 case HPT_MODD:
112 haptic_mode_decrease();
113 break;
114 case HPT_DWLI:
115 haptic_dwell_increase();
116 break;
117 case HPT_DWLD:
118 haptic_dwell_decrease();
119 break;
120 case HPT_CONT:
121 haptic_toggle_continuous();
122 break;
123 case HPT_CONI:
124 haptic_cont_increase();
125 break;
126 case HPT_COND:
127 haptic_cont_decrease();
128 break;
129 }
130 }
131
132 if (haptic_get_enable()) {
133 if (record->event.pressed) {
134 // keypress
135 if (haptic_get_feedback() < 2 && get_haptic_enabled_key(keycode, record)) {
136 haptic_play();
137 }
138 } else {
139 // keyrelease
140 if (haptic_get_feedback() > 0 && get_haptic_enabled_key(keycode, record)) {
141 haptic_play();
142 }
143 }
144 }
145
146 return true;
147}