keymap.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Copyright 2019 Josh Johnson
  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. // Function key we are 'wrapping' usual key presses in
  18. #define KC_WRAP KC_F24
  19. // Keyboard Layers
  20. enum keyboard_layers{
  21. _BASE = 0,
  22. _CTRL
  23. };
  24. // Tap Dance Declarations
  25. void td_ctrl (qk_tap_dance_state_t *state, void *user_data);
  26. enum tap_dance { CTRL = 0, BASE = 1 };
  27. qk_tap_dance_action_t tap_dance_actions[] = {
  28. // Tap once for standard key on base layer, twice to toggle to control layer
  29. [CTRL] = ACTION_TAP_DANCE_FN(td_ctrl),
  30. [BASE] = ACTION_TAP_DANCE_LAYER_MOVE(_______, _BASE)};
  31. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  32. [_BASE] = LAYOUT( /* Base */
  33. KC_S, KC_V,
  34. KC_A, KC_B, KC_C, KC_D,
  35. KC_E, KC_F, KC_G, KC_H,
  36. KC_I, KC_J, KC_K, KC_L,
  37. KC_M, KC_N, KC_O, TD(CTRL)
  38. ),
  39. [_CTRL] = LAYOUT( /* Control */
  40. KC_NO, KC_NO,
  41. _______, RGB_MOD, RGB_RMOD, RGB_TOG,
  42. RGB_VAD, RGB_VAI, RGB_HUD, RGB_HUI,
  43. RGB_SAD, RGB_SAI, _______, _______,
  44. _______, _______, RESET, TD(BASE)
  45. ),
  46. };
  47. // Keyboard is setup to 'wrap' the pressed key with an unused Fxx key,
  48. // allowing for easy differentiation from a real keyboard.
  49. bool encoder_update_user(uint8_t index, bool clockwise) {
  50. if (index == 0) { /* Left Encoder */
  51. if (clockwise) {
  52. register_code(KC_WRAP);
  53. tap_code(KC_R);
  54. unregister_code(KC_WRAP);
  55. } else {
  56. register_code(KC_WRAP);
  57. tap_code(KC_Q);
  58. unregister_code(KC_WRAP);
  59. }
  60. } else if (index == 1) { /* Right Encoder */
  61. if (clockwise) {
  62. register_code(KC_WRAP);
  63. tap_code(KC_U);
  64. unregister_code(KC_WRAP);
  65. } else {
  66. register_code(KC_WRAP);
  67. tap_code(KC_T);
  68. unregister_code(KC_WRAP);
  69. }
  70. }
  71. return true;
  72. }
  73. // Below stolen from TaranVH (https://github.com/TaranVH/2nd-keyboard/blob/master/HASU_USB/F24/keymap.c)
  74. // Shoutout to drashna on the QMK discord for basically writing this for me.... :P
  75. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  76. static uint8_t f24_tracker;
  77. switch (keycode) {
  78. case KC_A ... KC_F23:
  79. case KC_EXECUTE ... KC_EXSEL:
  80. if (record->event.pressed) {
  81. register_code(KC_WRAP);
  82. f24_tracker++;
  83. register_code(keycode);
  84. } else {
  85. unregister_code(keycode);
  86. f24_tracker--;
  87. if (!f24_tracker) {
  88. unregister_code(KC_WRAP);
  89. }
  90. }
  91. return false;
  92. break;
  93. }
  94. return true;
  95. }
  96. // Below works around TD() not running key press through process_record_user.
  97. // Fixes bug of CTRL layer move key not being wrapped in by modifier on single tap
  98. void td_ctrl (qk_tap_dance_state_t *state, void *user_data) {
  99. if (state->count == 1) {
  100. register_code(KC_WRAP);
  101. tap_code(KC_P);
  102. unregister_code(KC_WRAP);
  103. } else if (state->count == 2) {
  104. layer_move(_CTRL);
  105. }
  106. }