keymap.c 3.7 KB

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