keymap.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* Copyright 2020 Reid Sox-Harris
  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. enum layer_names {
  18. _BASE,
  19. _MACRO,
  20. _MOD
  21. };
  22. enum custom_keycodes {
  23. M801 = SAFE_RANGE,
  24. M802,
  25. M803,
  26. M804,
  27. M805,
  28. M806,
  29. };
  30. // tapdance keycodes
  31. enum td_keycodes {
  32. LAY
  33. };
  34. // define a type containing as many tapdance states as you need
  35. typedef enum {
  36. SINGLE_TAP,
  37. SINGLE_HOLD,
  38. } td_state_t;
  39. // create a global instance of the tapdance state type
  40. static td_state_t td_state;
  41. // declare your tapdance functions:
  42. // function to determine the current tapdance state
  43. int cur_dance (qk_tap_dance_state_t *state);
  44. // `finished` and `reset` functions for each tapdance keycode
  45. void altlp_finished (qk_tap_dance_state_t *state, void *user_data);
  46. void altlp_reset (qk_tap_dance_state_t *state, void *user_data);
  47. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  48. switch (keycode) {
  49. case M801:
  50. if (record->event.pressed) {
  51. SEND_STRING("M801" SS_TAP(X_ENTER));
  52. }
  53. break;
  54. case M802:
  55. if (record->event.pressed) {
  56. SEND_STRING("M802" SS_TAP(X_ENTER));
  57. }
  58. break;
  59. case M803:
  60. if (record->event.pressed) {
  61. SEND_STRING("M803" SS_TAP(X_ENTER));
  62. }
  63. break;
  64. case M804:
  65. if (record->event.pressed) {
  66. SEND_STRING("M804" SS_TAP(X_ENTER));
  67. }
  68. break;
  69. case M805:
  70. if (record->event.pressed) {
  71. SEND_STRING("M805" SS_TAP(X_ENTER));
  72. }
  73. break;
  74. case M806:
  75. if (record->event.pressed) {
  76. SEND_STRING("M806" SS_TAP(X_ENTER));
  77. }
  78. break;
  79. }
  80. return true;
  81. };
  82. #define EX_ARR LCTL(LSFT(KC_ENTER))
  83. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  84. [_BASE] = LAYOUT(
  85. // ┌────────┬────────┬────────┐
  86. KC_MUTE, KC_UP, TD(LAY),
  87. // ├────────┼────────┼────────┤
  88. KC_LEFT, KC_DOWN, KC_RGHT,
  89. // ├────────┼────────┼────────┤
  90. KC_MRWD, KC_MPLY, KC_MFFD
  91. // └────────┴────────┴────────┘
  92. ),
  93. [_MACRO] = LAYOUT(
  94. // ┌────────┬────────┬────────┐
  95. _______, KC_SPC, TG(_MACRO),
  96. // ├────────┼────────┼────────┤
  97. M801, M802, M803,
  98. // ├────────┼────────┼────────┤
  99. KC_NO, KC_NO, EX_ARR
  100. // └────────┴────────┴────────┘
  101. ),
  102. [_MOD] = LAYOUT(
  103. // ┌────────┬────────┬────────┐
  104. _______, BL_STEP,TG(_MOD),
  105. // ├────────┼────────┼────────┤
  106. RGB_TOG, RGB_HUI, RGB_SAI,
  107. // ├────────┼────────┼────────┤
  108. RGB_MOD, RGB_HUD, RGB_SAD
  109. // └────────┴────────┴────────┘
  110. )
  111. };
  112. bool encoder_update_user(uint8_t index, bool clockwise) {
  113. if (index == 0) {
  114. if (clockwise) {
  115. tap_code(KC_VOLD);
  116. } else {
  117. tap_code(KC_VOLU);
  118. }
  119. }
  120. return true;
  121. }
  122. // Tapdance! Hold to use as a modifier to the _MOD layout, tap to change it between _BASE and _MACRO
  123. // determine the tapdance state to return
  124. int cur_dance (qk_tap_dance_state_t *state) {
  125. if (state->count == 1) {
  126. if (state->interrupted || !state->pressed) { return SINGLE_TAP; }
  127. else { return SINGLE_HOLD; }
  128. } else { return 3; } // any number higher than the maximum state value you return above
  129. }
  130. // handle the possible states for each tapdance keycode you define:
  131. void altlp_finished (qk_tap_dance_state_t *state, void *user_data) {
  132. td_state = cur_dance(state);
  133. switch (td_state) {
  134. case SINGLE_TAP:
  135. layer_on(_MACRO);
  136. break;
  137. case SINGLE_HOLD:
  138. layer_on(_MOD);
  139. break;
  140. }
  141. }
  142. void altlp_reset (qk_tap_dance_state_t *state, void *user_data) {
  143. switch (td_state) {
  144. case SINGLE_TAP:
  145. break;
  146. case SINGLE_HOLD:
  147. layer_off(_MOD);
  148. break;
  149. }
  150. }
  151. // define `ACTION_TAP_DANCE_FN_ADVANCED()` for each tapdance keycode, passing in `finished` and `reset` functions
  152. qk_tap_dance_action_t tap_dance_actions[] = {
  153. [LAY] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, altlp_finished, altlp_reset)
  154. };