logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

snatchpad.c (1736B)


  1. // Copyright 2022 xia0 (@xia0)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "quantum.h"
  4. #ifdef ENCODER_ENABLE
  5. bool encoder_update_kb(uint8_t index, bool clockwise) {
  6. if (!encoder_update_user(index, clockwise)) {
  7. return false;
  8. }
  9. uint8_t layer = get_highest_layer(layer_state);
  10. if (index == 0) { /* First encoder */
  11. switch (layer) {
  12. case 0:
  13. if (clockwise) {
  14. tap_code_delay(KC_VOLU, 10);
  15. } else {
  16. tap_code_delay(KC_VOLD, 10);
  17. }
  18. break;
  19. case 2:
  20. if (clockwise) {
  21. tap_code16(LCTL(KC_MINUS));
  22. } else {
  23. tap_code16(LCTL(KC_EQUAL));
  24. }
  25. break;
  26. default:
  27. if (clockwise) {
  28. tap_code(KC_MS_L);
  29. } else {
  30. tap_code(KC_MS_R);
  31. }
  32. break;
  33. }
  34. } else if (index == 1) { /* Second encoder */
  35. switch (layer) {
  36. case 0:
  37. if (clockwise) {
  38. tap_code(KC_MFFD);
  39. } else {
  40. tap_code(KC_MRWD);
  41. }
  42. break;
  43. case 2:
  44. if (clockwise) {
  45. tap_code16(LCTL(KC_Y));
  46. } else {
  47. tap_code16(LCTL(KC_Z));
  48. }
  49. break;
  50. default:
  51. if (clockwise) {
  52. tap_code(KC_MS_D);
  53. } else {
  54. tap_code(KC_MS_U);
  55. }
  56. break;
  57. }
  58. }
  59. return true;
  60. }
  61. #endif