summaryrefslogtreecommitdiff
path: root/keyboards/handwired/snatchpad/snatchpad.c
diff options
context:
space:
mode:
authorxiao <307671+xia0@users.noreply.github.com>2022-02-21 19:40:11 +1100
committerGitHub <noreply@github.com>2022-02-21 00:40:11 -0800
commit18490537a5a2c050ecfa1ee2209229eba6b8b342 (patch)
tree89777cc3cba6d5f9a3d3a77bce6c30408f4dca0d /keyboards/handwired/snatchpad/snatchpad.c
parent2d1f2810a41b8a93c21035b14afacb717ef7c822 (diff)
[Keyboard] Add Snatchpad keyboard (#16330)
Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: Ryan <fauxpark@gmail.com> Co-authored-by: xia0 <xiao@morgan.net.au>
Diffstat (limited to 'keyboards/handwired/snatchpad/snatchpad.c')
-rw-r--r--keyboards/handwired/snatchpad/snatchpad.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/keyboards/handwired/snatchpad/snatchpad.c b/keyboards/handwired/snatchpad/snatchpad.c
new file mode 100644
index 0000000000..621ba11123
--- /dev/null
+++ b/keyboards/handwired/snatchpad/snatchpad.c
@@ -0,0 +1,66 @@
+// Copyright 2022 xia0 (@xia0)
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "snatchpad.h"
+
+#ifdef ENCODER_ENABLE
+bool encoder_update_kb(uint8_t index, bool clockwise) {
+ if (!encoder_update_user(index, clockwise)) {
+ return false;
+ }
+
+ uint8_t layer = get_highest_layer(layer_state);
+
+ if (index == 0) { /* First encoder */
+ switch (layer) {
+ case 0:
+ if (clockwise) {
+ tap_code_delay(KC_VOLU, 10);
+ } else {
+ tap_code_delay(KC_VOLD, 10);
+ }
+ break;
+ case 2:
+ if (clockwise) {
+ tap_code16(LCTL(KC_MINUS));
+ } else {
+ tap_code16(LCTL(KC_EQUAL));
+ }
+ break;
+ default:
+ if (clockwise) {
+ tap_code(KC_MS_L);
+ } else {
+ tap_code(KC_MS_R);
+ }
+ break;
+ }
+
+ } else if (index == 1) { /* Second encoder */
+ switch (layer) {
+ case 0:
+ if (clockwise) {
+ tap_code(KC_MFFD);
+ } else {
+ tap_code(KC_MRWD);
+ }
+ break;
+ case 2:
+ if (clockwise) {
+ tap_code16(LCTL(KC_Y));
+ } else {
+ tap_code16(LCTL(KC_Z));
+ }
+ break;
+ default:
+ if (clockwise) {
+ tap_code(KC_MS_D);
+ } else {
+ tap_code(KC_MS_U);
+ }
+ break;
+ }
+ }
+ return true;
+}
+#endif