encoder.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 left_encoder_cw(void) {
  19. switch (get_highest_layer(layer_state)) {
  20. case _LOWER:
  21. tap_code16(LGUI(KC_TAB));
  22. break;
  23. case _RAISE:
  24. tap_code(KC_PGDN);
  25. break;
  26. case _ADJUST:
  27. rgblight_decrease_hue();
  28. break;
  29. default:
  30. tap_code(KC_BRID);
  31. break;
  32. }
  33. }
  34. void left_encoder_acw(void) {
  35. switch (get_highest_layer(layer_state)) {
  36. case _LOWER:
  37. tap_code16(SGUI(KC_TAB));
  38. break;
  39. case _RAISE:
  40. tap_code(KC_PGUP);
  41. break;
  42. case _ADJUST:
  43. rgblight_increase_hue();
  44. break;
  45. default:
  46. tap_code(KC_BRIU);
  47. break;
  48. }
  49. }
  50. void right_encoder_cw(void) {
  51. switch (get_highest_layer(layer_state)) {
  52. case _LOWER:
  53. tap_code(KC_DOWN);
  54. break;
  55. case _RAISE:
  56. tap_code16(LCTL(LSFT(KC_TAB)));
  57. break;
  58. case _ADJUST:
  59. rgblight_decrease_val();
  60. break;
  61. default:
  62. tap_code(KC_VOLD);
  63. break;
  64. }
  65. }
  66. void right_encoder_acw(void) {
  67. switch (get_highest_layer(layer_state)) {
  68. case _LOWER:
  69. tap_code(KC_UP);
  70. break;
  71. case _RAISE:
  72. tap_code16(LCTL(KC_TAB));
  73. break;
  74. case _ADJUST:
  75. rgblight_increase_val();
  76. break;
  77. default:
  78. tap_code(KC_VOLU);
  79. break;
  80. }
  81. }
  82. bool encoder_update_user(uint8_t index, bool clockwise) {
  83. encoder_rotated_timer = timer_read();
  84. if (index == 0) {
  85. left_encoder_rotated = true;
  86. if (clockwise) {
  87. left_encoder_cw();
  88. } else {
  89. left_encoder_acw();
  90. }
  91. }
  92. else if (index == 1) {
  93. right_encoder_rotated = true;
  94. if (clockwise) {
  95. right_encoder_cw();
  96. } else {
  97. right_encoder_acw();
  98. }
  99. }
  100. return true;
  101. }
  102. #endif