keymap.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. _CONTROL
  23. };
  24. // Tap Dance Declarations
  25. enum tap_dance { TD_TO_LED = 0, TD_TO_DEFAULT = 1 };
  26. qk_tap_dance_action_t tap_dance_actions[] = {
  27. // Tap once for standard key, twice to toggle to control layer
  28. [TD_TO_LED] = ACTION_TAP_DANCE_DUAL_ROLE(KC_P, _CONTROL),
  29. [TD_TO_DEFAULT] = ACTION_TAP_DANCE_DUAL_ROLE(KC_P, _BASE)};
  30. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  31. [_BASE] = LAYOUT( /* Base */
  32. KC_S, KC_V,
  33. KC_A, KC_B, KC_C, KC_D,
  34. KC_E, KC_F, KC_G, KC_H,
  35. KC_I, KC_J, KC_K, KC_L,
  36. KC_M, KC_N, KC_O, TD(TD_TO_LED)
  37. ),
  38. [_CONTROL] = LAYOUT( /* LED Control */
  39. KC_NO, KC_NO,
  40. _______, RGB_MOD, RGB_RMOD, RGB_TOG,
  41. RGB_VAD, RGB_VAI, RGB_HUD, RGB_HUI,
  42. RGB_SAD, RGB_SAI, _______, _______,
  43. _______, _______, RESET, TD(TD_TO_DEFAULT)
  44. ),
  45. };
  46. // Keyboard is setup to 'warp' the pressed key with F24,
  47. // allowing for easy differentiation from a real keyboard.
  48. void encoder_update_user(uint8_t index, bool clockwise) {
  49. if (index == 0) { /* Left Encoder */
  50. if (clockwise) {
  51. register_code(KC_WRAP);
  52. tap_code(KC_R);
  53. unregister_code(KC_WRAP);
  54. } else {
  55. register_code(KC_WRAP);
  56. tap_code(KC_Q);
  57. unregister_code(KC_WRAP);
  58. }
  59. } else if (index == 1) { /* Right Encoder */
  60. if (clockwise) {
  61. register_code(KC_WRAP);
  62. tap_code(KC_U);
  63. unregister_code(KC_WRAP);
  64. } else {
  65. register_code(KC_WRAP);
  66. tap_code(KC_T);
  67. unregister_code(KC_WRAP);
  68. }
  69. }
  70. }
  71. // Below stolen from TaranVH (https://github.com/TaranVH/2nd-keyboard/blob/master/HASU_USB/F24/keymap.c)
  72. // Shoutout to drashna on the QMK discord for basically writing this for me.... :P
  73. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  74. static uint8_t f24_tracker;
  75. switch (keycode) {
  76. case KC_A ... KC_F23:
  77. case KC_EXECUTE ... KC_EXSEL:
  78. if (record->event.pressed) {
  79. register_code(KC_WRAP);
  80. f24_tracker++;
  81. register_code(keycode);
  82. } else {
  83. unregister_code(keycode);
  84. f24_tracker--;
  85. if (!f24_tracker) {
  86. unregister_code(KC_WRAP);
  87. }
  88. }
  89. return false;
  90. break;
  91. }
  92. return true;
  93. }