keymap.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* Copyright 2017 REPLACE_WITH_YOUR_NAME
  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 "woodpad.h"
  17. #include "drashna.h"
  18. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  19. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  20. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  21. // entirely and just use numbers.
  22. // Fillers to make layering more clear
  23. #define _______ KC_TRNS
  24. #define XXXXXXX KC_NO
  25. //define layer change stuff for underglow indicator
  26. bool skip_leds = false;
  27. #ifdef TAP_DANCE_ENABLE
  28. //define diablo macro timer variables
  29. static uint16_t diablo_timer[4];
  30. static uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 };
  31. static uint8_t diablo_key_time[4];
  32. bool check_dtimer(uint8_t dtimer) {
  33. // has the correct number of seconds elapsed (as defined by diablo_times)
  34. return (timer_elapsed(diablo_timer[dtimer]) < (diablo_key_time[dtimer] * 1000)) ? false : true;
  35. };
  36. #endif
  37. #ifdef TAP_DANCE_ENABLE
  38. enum {
  39. TD_D3_1 = 0,
  40. TD_D3_2,
  41. TD_D3_3,
  42. TD_D3_4
  43. };
  44. // Cycle through the times for the macro, starting at 0, for disabled.
  45. // Max of six values, so don't exceed
  46. void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data, uint8_t diablo_key) {
  47. if (state->count >= 7) {
  48. diablo_key_time[diablo_key] = diablo_times[0];
  49. reset_tap_dance(state);
  50. }
  51. else {
  52. diablo_key_time[diablo_key] = diablo_times[state->count - 1];
  53. }
  54. }
  55. // Would rather have one function for all of this, but no idea how to do that...
  56. void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) {
  57. diablo_tapdance_master(state, user_data, 0);
  58. }
  59. void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) {
  60. diablo_tapdance_master(state, user_data, 1);
  61. }
  62. void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) {
  63. diablo_tapdance_master(state, user_data, 2);
  64. }
  65. void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) {
  66. diablo_tapdance_master(state, user_data, 3);
  67. }
  68. //Tap Dance Definitions
  69. qk_tap_dance_action_t tap_dance_actions[] = {
  70. // tap once to disable, and more to enable timed micros
  71. [TD_D3_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1),
  72. [TD_D3_2] = ACTION_TAP_DANCE_FN(diablo_tapdance2),
  73. [TD_D3_3] = ACTION_TAP_DANCE_FN(diablo_tapdance3),
  74. [TD_D3_4] = ACTION_TAP_DANCE_FN(diablo_tapdance4),
  75. };
  76. #endif
  77. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  78. [_NUMLOCK] = KEYMAP( /* Base */
  79. TG(_NAV), TG(_DIABLO), TG(_MACROS), KC_PSLS,\
  80. KC_P7, KC_P8, KC_P9, KC_PAST, \
  81. KC_P4, KC_P5, KC_P6, KC_PMNS, \
  82. KC_P1, KC_P2, KC_P3, KC_PPLS, \
  83. LT(_MEDIA,KC_P0), KC_PDOT, KC_COLN, KC_PENT \
  84. ),
  85. [_NAV] = KEYMAP( /* Base */
  86. _______, _______, _______, _______,\
  87. KC_HOME, KC_UP, KC_PGUP, _______, \
  88. KC_LEFT, XXXXXXX, KC_RIGHT, _______, \
  89. KC_END, KC_DOWN, KC_PGDN, _______, \
  90. KC_INS, KC_DEL, _______, _______ \
  91. ),
  92. #ifdef TAP_DANCE_ENABLE
  93. [_DIABLO] = KEYMAP( /* Base */
  94. KC_ESC, _______, _______, _______,\
  95. KC_S, KC_F, KC_I, KC_M, \
  96. KC_1, KC_2, KC_3, KC_4, \
  97. TD(TD_D3_1), TD(TD_D3_2), TD(TD_D3_3), TD(TD_D3_4), \
  98. _______, KC_DIABLO_CLEAR, KC_Q, SFT_T(KC_SPACE) \
  99. ),
  100. #else
  101. [_DIABLO] = KEYMAP( /* Base */
  102. KC_ESC, _______, _______, _______,\
  103. KC_S, KC_F, KC_I, KC_M, \
  104. KC_1, KC_2, KC_3, KC_4, \
  105. XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
  106. _______, KC_DIABLO_CLEAR, KC_Q, SFT_T(KC_SPACE) \
  107. ),
  108. #endif
  109. [_MACROS] = KEYMAP( /* Base */
  110. KC_OVERWATCH, _______, _______, XXXXXXX,\
  111. XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
  112. XXXXXXX, XXXXXXX, XXXXXXX, KC_JUSTGAME, \
  113. KC_SYMM, KC_TORB, XXXXXXX, KC_GOODGAME, \
  114. KC_SALT, KC_MORESALT, KC_SALTHARD, KC_GLHF \
  115. ),
  116. [_MEDIA] = KEYMAP( /* Base */
  117. KC_RESET, KC_MUTE, KC_VOLD, KC_VOLU,\
  118. KC_MAKE, _______, RGB_HUI, RGB_HUD, \
  119. KC_MPLY, KC_MSTP, KC_MPRV, KC_MNXT, \
  120. RGB_TOG, RGB_MOD, RGB_SAI, RGB_VAI, \
  121. _______, _______, RGB_SAD, RGB_VAD \
  122. ),
  123. };
  124. void numlock_led_on(void) {
  125. PORTF |= (1 << 7);
  126. }
  127. void numlock_led_off(void) {
  128. PORTF &= ~(1 << 7);
  129. }
  130. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  131. switch (keycode) {
  132. #ifdef TAP_DANCE_ENABLE
  133. case KC_DIABLO_CLEAR: // reset all Diable timers, disabling them
  134. if (record->event.pressed) {
  135. uint8_t dtime;
  136. for (dtime = 0; dtime < 4; dtime++) {
  137. diablo_key_time[dtime] = diablo_times[0];
  138. }
  139. }
  140. return false;
  141. break;
  142. #endif
  143. }
  144. return true;
  145. }
  146. #ifdef TAP_DANCE_ENABLE
  147. // Sends the key press to system, but only if on the Diablo layer
  148. void send_diablo_keystroke(uint8_t diablo_key) {
  149. if (biton32(layer_state) == _DIABLO) {
  150. switch (diablo_key) {
  151. case 0:
  152. SEND_STRING("1");
  153. break;
  154. case 1:
  155. SEND_STRING("2");
  156. break;
  157. case 2:
  158. SEND_STRING("3");
  159. break;
  160. case 3:
  161. SEND_STRING("4");
  162. break;
  163. }
  164. }
  165. }
  166. // Checks each of the 4 timers/keys to see if enough time has elapsed
  167. // Runs the "send string" command if enough time has passed, and resets the timer.
  168. void run_diablo_macro_check(void) {
  169. uint8_t dtime;
  170. for (dtime = 0; dtime < 4; dtime++) {
  171. if (check_dtimer(dtime) && diablo_key_time[dtime]) {
  172. diablo_timer[dtime] = timer_read();
  173. send_diablo_keystroke(dtime);
  174. }
  175. }
  176. }
  177. #endif
  178. void matrix_init_keymap(void) {
  179. // set Numlock LED to output and low
  180. DDRF |= (1 << 7);
  181. PORTF &= ~(1 << 7);
  182. if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) {
  183. register_code(KC_NUMLOCK);
  184. unregister_code(KC_NUMLOCK);
  185. }
  186. }
  187. void matrix_scan_keymap(void) {
  188. numlock_led_off();
  189. if ((is_overwatch && biton32(layer_state) == _MACROS) || (biton32(layer_state) == _NAV)) {
  190. numlock_led_on();
  191. }
  192. // Run Diablo 3 macro checking code.
  193. #ifdef TAP_DANCE_ENABLE
  194. run_diablo_macro_check();
  195. #endif
  196. }