encoder.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Copyright 2020 ninjonas
  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 "ninjonas.h"
  17. #ifdef ENCODER_ENABLE
  18. void encoder_update_user(uint8_t index, bool clockwise) {
  19. if (index == 0) {
  20. switch (get_highest_layer(layer_state)) {
  21. case _LOWER:
  22. if (clockwise) {
  23. tap_code16(SGUI(KC_TAB));
  24. } else {
  25. tap_code16(LGUI(KC_TAB));
  26. }
  27. break;
  28. case _RAISE:
  29. if (clockwise) {
  30. tap_code(KC_PGUP);
  31. } else {
  32. tap_code(KC_PGDN);
  33. }
  34. break;
  35. case _ADJUST:
  36. if (clockwise) {
  37. rgblight_increase_hue();
  38. } else {
  39. rgblight_decrease_hue();
  40. }
  41. break;
  42. default:
  43. if (clockwise) {
  44. tap_code(KC_BRIU);
  45. } else {
  46. tap_code(KC_BRID);
  47. }
  48. break;
  49. }
  50. } else if (index == 1) {
  51. switch (get_highest_layer(layer_state)) {
  52. case _LOWER:
  53. if (clockwise) {
  54. tap_code(KC_UP);
  55. } else {
  56. tap_code(KC_DOWN);
  57. }
  58. break;
  59. case _RAISE:
  60. if (clockwise) {
  61. tap_code16(LCTL(KC_TAB));
  62. } else {
  63. tap_code16(LCTL(LSFT(KC_TAB)));
  64. }
  65. break;
  66. case _ADJUST:
  67. if (clockwise) {
  68. rgblight_increase_val();
  69. } else {
  70. rgblight_decrease_val();
  71. }
  72. break;
  73. default:
  74. if (clockwise) {
  75. tap_code(KC_VOLU);
  76. } else {
  77. tap_code(KC_VOLD);
  78. }
  79. break;
  80. }
  81. }
  82. }
  83. #endif