keymap.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* Copyright 2021 yfuku
  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 QMK_KEYBOARD_H
  17. // Defines names for use in layer keycodes and the keymap
  18. enum layer_names {
  19. _BASE,
  20. _FN1,
  21. _FN2,
  22. _FN3
  23. };
  24. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  25. [_BASE] = LAYOUT(
  26. KC_NO, KC_NO, KC_NO, KC_NO, // for encoders
  27. KC_NO, KC_NO, KC_NO, KC_NO, // for ext keys
  28. MO(1), KC_BSPC, KC_SPC, KC_ENT,
  29. KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  30. ),
  31. [_FN1] = LAYOUT(
  32. KC_NO, KC_NO, KC_NO, KC_NO,
  33. KC_NO, KC_NO, KC_NO, KC_NO,
  34. KC_1, KC_2, KC_3, KC_4,
  35. KC_5, KC_6, KC_7, KC_8
  36. ),
  37. [_FN2] = LAYOUT(
  38. KC_NO, KC_NO, KC_NO, KC_NO,
  39. KC_NO, KC_NO, KC_NO, KC_NO,
  40. KC_1, KC_2, KC_3, KC_4,
  41. KC_5, KC_6, KC_7, KC_8
  42. ),
  43. [_FN3] = LAYOUT(
  44. KC_NO, KC_NO, KC_NO, KC_NO,
  45. KC_NO, KC_NO, KC_NO, KC_NO,
  46. KC_1, KC_2, KC_3, KC_4,
  47. KC_5, KC_6, KC_7, KC_8
  48. )
  49. };
  50. keyevent_t encoder1_ccw = {
  51. .key = (keypos_t){.row = 3, .col = 1},
  52. .pressed = false
  53. };
  54. keyevent_t encoder1_cw = {
  55. .key = (keypos_t){.row = 3, .col = 0},
  56. .pressed = false
  57. };
  58. keyevent_t encoder2_ccw = {
  59. .key = (keypos_t){.row = 3, .col = 3},
  60. .pressed = false
  61. };
  62. keyevent_t encoder2_cw = {
  63. .key = (keypos_t){.row = 3, .col = 2},
  64. .pressed = false
  65. };
  66. void matrix_scan_user(void) {
  67. if (IS_PRESSED(encoder1_ccw)) {
  68. encoder1_ccw.pressed = false;
  69. encoder1_ccw.time = (timer_read() | 1);
  70. action_exec(encoder1_ccw);
  71. }
  72. if (IS_PRESSED(encoder1_cw)) {
  73. encoder1_cw.pressed = false;
  74. encoder1_cw.time = (timer_read() | 1);
  75. action_exec(encoder1_cw);
  76. }
  77. if (IS_PRESSED(encoder2_ccw)) {
  78. encoder2_ccw.pressed = false;
  79. encoder2_ccw.time = (timer_read() | 1);
  80. action_exec(encoder2_ccw);
  81. }
  82. if (IS_PRESSED(encoder2_cw)) {
  83. encoder2_cw.pressed = false;
  84. encoder2_cw.time = (timer_read() | 1);
  85. action_exec(encoder2_cw);
  86. }
  87. }
  88. bool encoder_update_user(uint8_t index, bool clockwise) {
  89. if (index == 0) { /* First encoder */
  90. if (clockwise) {
  91. encoder1_cw.pressed = true;
  92. encoder1_cw.time = (timer_read() | 1);
  93. action_exec(encoder1_cw);
  94. } else {
  95. encoder1_ccw.pressed = true;
  96. encoder1_ccw.time = (timer_read() | 1);
  97. action_exec(encoder1_ccw);
  98. }
  99. } else if (index == 1) {
  100. if (clockwise) {
  101. encoder2_cw.pressed = true;
  102. encoder2_cw.time = (timer_read() | 1);
  103. action_exec(encoder2_cw);
  104. } else {
  105. encoder2_ccw.pressed = true;
  106. encoder2_ccw.time = (timer_read() | 1);
  107. action_exec(encoder2_ccw);
  108. }
  109. }
  110. return true;
  111. }