2
0

keymap.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  18. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  19. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  20. // entirely and just use numbers.
  21. #define _NUMLOCK 0
  22. #define _NAV 1
  23. #define _DIABLO 2
  24. #define _MACROS 3
  25. #define _MEDIA 4
  26. // Fillers to make layering more clear
  27. #define _______ KC_TRNS
  28. #define XXXXXXX KC_NO
  29. #ifdef RGBLIGHT_ENABLE
  30. #define rgblight_set_blue rgblight_sethsv (0xFF, 0xFF, 0xFF);
  31. #define rgblight_set_red rgblight_sethsv (0x00, 0xFF, 0xFF);
  32. #define rgblight_set_green rgblight_sethsv (0x78, 0xFF, 0xFF);
  33. #define rgblight_set_orange rgblight_sethsv (0x1E, 0xFF, 0xFF);
  34. #define rgblight_set_teal rgblight_sethsv (0xC3, 0xFF, 0xFF);
  35. #define rgblight_set_magenta rgblight_sethsv (0x12C, 0xFF, 0xFF);
  36. #define rgblight_set_yellow rgblight_sethsv (0x3C, 0xFF, 0xFF);
  37. #define rgblight_set_purple rgblight_sethsv (0x10E, 0xFF, 0xFF);
  38. #endif
  39. //define layer change stuff for underglow indicator
  40. bool skip_leds = false;
  41. bool is_overwatch = false;
  42. #ifdef TAP_DANCE_ENABLE
  43. //define diablo macro timer variables
  44. static uint16_t diablo_timer[4];
  45. static uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 };
  46. static uint8_t diablo_key_time[4];
  47. bool check_dtimer(uint8_t dtimer) {
  48. // has the correct number of seconds elapsed (as defined by diablo_times)
  49. return (timer_elapsed(diablo_timer[dtimer]) < (diablo_key_time[dtimer] * 1000)) ? false : true;
  50. };
  51. #endif
  52. enum custom_keycodes {
  53. PLACEHOLDER = SAFE_RANGE, // can always be here
  54. KC_DIABLO_CLEAR,
  55. KC_OVERWATCH,
  56. KC_SALT,
  57. KC_MORESALT,
  58. KC_SALTHARD,
  59. KC_GOODGAME,
  60. KC_SYMM,
  61. KC_DOOMFIST,
  62. KC_JUSTGAME,
  63. KC_GLHF,
  64. KC_TORB,
  65. KC_MAKE
  66. };
  67. #ifdef TAP_DANCE_ENABLE
  68. enum {
  69. TD_DIABLO_1 = 0,
  70. TD_DIABLO_2,
  71. TD_DIABLO_3,
  72. TD_DIABLO_4
  73. };
  74. // Cycle through the times for the macro, starting at 0, for disabled.
  75. // Max of six values, so don't exceed
  76. void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data, uint8_t diablo_key) {
  77. if (state->count >= 7) {
  78. diablo_key_time[diablo_key] = diablo_times[0];
  79. reset_tap_dance(state);
  80. }
  81. else {
  82. diablo_key_time[diablo_key] = diablo_times[state->count - 1];
  83. }
  84. }
  85. // Would rather have one function for all of this, but no idea how to do that...
  86. void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) {
  87. diablo_tapdance_master(state, user_data, 0);
  88. }
  89. void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) {
  90. diablo_tapdance_master(state, user_data, 1);
  91. }
  92. void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) {
  93. diablo_tapdance_master(state, user_data, 2);
  94. }
  95. void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) {
  96. diablo_tapdance_master(state, user_data, 3);
  97. }
  98. //Tap Dance Definitions
  99. qk_tap_dance_action_t tap_dance_actions[] = {
  100. // tap once to disable, and more to enable timed micros
  101. [TD_DIABLO_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1),
  102. [TD_DIABLO_2] = ACTION_TAP_DANCE_FN(diablo_tapdance2),
  103. [TD_DIABLO_3] = ACTION_TAP_DANCE_FN(diablo_tapdance3),
  104. [TD_DIABLO_4] = ACTION_TAP_DANCE_FN(diablo_tapdance4),
  105. };
  106. #endif
  107. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  108. [_NUMLOCK] = KEYMAP( /* Base */
  109. TG(_NAV), TG(_DIABLO), TG(_MACROS), KC_PSLS,\
  110. KC_P7, KC_P8, KC_P9, KC_PAST, \
  111. KC_P4, KC_P5, KC_P6, KC_PMNS, \
  112. KC_P1, KC_P2, KC_P3, KC_PPLS, \
  113. LT(_MEDIA,KC_P0), KC_PDOT, KC_COLN, KC_PENT \
  114. ),
  115. [_NAV] = KEYMAP( /* Base */
  116. _______, _______, _______, _______,\
  117. KC_HOME, KC_UP, KC_PGUP, _______, \
  118. KC_LEFT, XXXXXXX, KC_RIGHT, _______, \
  119. KC_END, KC_DOWN, KC_PGDN, _______, \
  120. KC_INS, KC_DEL, _______, _______ \
  121. ),
  122. #ifdef TAP_DANCE_ENABLE
  123. [_DIABLO] = KEYMAP( /* Base */
  124. KC_ESC, _______, _______, _______,\
  125. KC_S, KC_F, KC_I, KC_M, \
  126. KC_1, KC_2, KC_3, KC_4, \
  127. TD(TD_DIABLO_1), TD(TD_DIABLO_2), TD(TD_DIABLO_3), TD(TD_DIABLO_4), \
  128. _______, KC_DIABLO_CLEAR, KC_Q, SFT_T(KC_SPACE) \
  129. ),
  130. #else
  131. [_DIABLO] = KEYMAP( /* Base */
  132. KC_ESC, _______, _______, _______,\
  133. KC_S, KC_F, KC_I, KC_M, \
  134. KC_1, KC_2, KC_3, KC_4, \
  135. XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
  136. _______, KC_DIABLO_CLEAR, KC_Q, SFT_T(KC_SPACE) \
  137. ),
  138. #endif
  139. [_MACROS] = KEYMAP( /* Base */
  140. KC_OVERWATCH, _______, _______, XXXXXXX,\
  141. XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
  142. XXXXXXX, XXXXXXX, XXXXXXX, KC_JUSTGAME, \
  143. KC_SYMM, KC_DOOMFIST, KC_TORB, KC_GOODGAME, \
  144. KC_SALT, KC_MORESALT, KC_SALTHARD, KC_GLHF \
  145. ),
  146. [_MEDIA] = KEYMAP( /* Base */
  147. RESET, KC_MUTE, KC_VOLD, KC_VOLU,\
  148. KC_MAKE, _______, RGB_HUI, RGB_HUD, \
  149. KC_MPLY, KC_MSTP, KC_MPRV, KC_MNXT, \
  150. RGB_TOG, RGB_MOD, RGB_SAI, RGB_VAI, \
  151. _______, _______, RGB_SAD, RGB_VAD \
  152. ),
  153. };
  154. void numlock_led_on(void) {
  155. PORTF |= (1<<7);
  156. }
  157. void numlock_led_off(void) {
  158. PORTF &= ~(1<<7);
  159. }
  160. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  161. uint16_t kc;
  162. if (is_overwatch) {
  163. kc = KC_BSPC;
  164. } else {
  165. kc = KC_ENTER;
  166. }
  167. switch (keycode) {
  168. #ifdef TAP_DANCE_ENABLE
  169. case KC_DIABLO_CLEAR: // reset all Diable timers, disabling them
  170. if (record->event.pressed) {
  171. uint8_t dtime;
  172. for (dtime = 0; dtime < 4; dtime++) {
  173. diablo_key_time[dtime] = diablo_times[0];
  174. }
  175. }
  176. return false;
  177. break;
  178. #endif
  179. case KC_OVERWATCH:
  180. if (record->event.pressed) {
  181. is_overwatch = !is_overwatch;
  182. }
  183. #ifdef RGBLIGHT_ENABLE
  184. is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
  185. #endif
  186. return false;
  187. break;
  188. case KC_SALT:
  189. if (!record->event.pressed) {
  190. register_code(kc);
  191. unregister_code(kc);
  192. _delay_ms(50);
  193. SEND_STRING("Salt, salt, salt...");
  194. register_code(KC_ENTER);
  195. unregister_code(KC_ENTER);
  196. }
  197. return false;
  198. break;
  199. case KC_MORESALT:
  200. if (!record->event.pressed) {
  201. register_code(kc);
  202. unregister_code(kc);
  203. _delay_ms(50);
  204. SEND_STRING("Please sir, can I have some more salt?!");
  205. register_code(KC_ENTER);
  206. unregister_code(KC_ENTER);
  207. }
  208. return false;
  209. break;
  210. case KC_SALTHARD:
  211. if (!record->event.pressed) {
  212. register_code(kc);
  213. unregister_code(kc);
  214. _delay_ms(50);
  215. SEND_STRING("Your salt only makes my penis that much harder, and even more aggressive!");
  216. register_code(KC_ENTER);
  217. unregister_code(KC_ENTER);
  218. }
  219. return false;
  220. break;
  221. case KC_GOODGAME:
  222. if (!record->event.pressed) {
  223. register_code(kc);
  224. unregister_code(kc);
  225. _delay_ms(50);
  226. SEND_STRING("Good game, everyone!");
  227. register_code(KC_ENTER);
  228. unregister_code(KC_ENTER);
  229. }
  230. return false;
  231. break;
  232. case KC_GLHF:
  233. if (!record->event.pressed) {
  234. register_code(kc);
  235. unregister_code(kc);
  236. _delay_ms(50);
  237. SEND_STRING("Good luck, have fun!!!");
  238. register_code(KC_ENTER);
  239. unregister_code(KC_ENTER);
  240. }
  241. return false;
  242. break;
  243. case KC_SYMM:
  244. if (!record->event.pressed) {
  245. register_code(kc);
  246. unregister_code(kc);
  247. _delay_ms(50);
  248. SEND_STRING("Left click to win!");
  249. register_code(KC_ENTER);
  250. unregister_code(KC_ENTER);
  251. }
  252. return false;
  253. break;
  254. case KC_DOOMFIST:
  255. if (!record->event.pressed) {
  256. register_code(kc);
  257. unregister_code(kc);
  258. _delay_ms(50);
  259. SEND_STRING("Hey, look at me. I'm Doomfist, and I'm overpowered! All I do is spam punches all day! I'm DPS, tank and defense, rolled into one! All I need is team healing to be complete!");
  260. register_code(KC_ENTER);
  261. unregister_code(KC_ENTER);
  262. }
  263. return false;
  264. break;
  265. case KC_JUSTGAME:
  266. if (!record->event.pressed) {
  267. register_code(kc);
  268. unregister_code(kc);
  269. _delay_ms(50);
  270. SEND_STRING("It may be a game, but if you don't want to actually try, please go play AI, so that people that actually want to take the game seriously and \"get good\" have a place to do so without trolls like you throwing games.");
  271. register_code(KC_ENTER);
  272. unregister_code(KC_ENTER);
  273. }
  274. return false;
  275. break;
  276. case KC_TORB:
  277. if (!record->event.pressed) {
  278. register_code(kc);
  279. unregister_code(kc);
  280. _delay_ms(50);
  281. SEND_STRING("That was positively riveting!");
  282. register_code(KC_ENTER);
  283. unregister_code(KC_ENTER);
  284. }
  285. return false;
  286. break;
  287. case KC_MAKE:
  288. if (!record->event.pressed) {
  289. SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP SS_TAP(X_ENTER));
  290. }
  291. return false;
  292. break;
  293. }
  294. return true;
  295. }
  296. #ifdef TAP_DANCE_ENABLE
  297. // Sends the key press to system, but only if on the Diablo layer
  298. void send_diablo_keystroke(uint8_t diablo_key) {
  299. if (biton32(layer_state) == _DIABLO) {
  300. switch (diablo_key) {
  301. case 0:
  302. SEND_STRING("1");
  303. break;
  304. case 1:
  305. SEND_STRING("2");
  306. break;
  307. case 2:
  308. SEND_STRING("3");
  309. break;
  310. case 3:
  311. SEND_STRING("4");
  312. break;
  313. }
  314. }
  315. }
  316. // Checks each of the 4 timers/keys to see if enough time has elapsed
  317. // Runs the "send string" command if enough time has passed, and resets the timer.
  318. void run_diablo_macro_check(void) {
  319. uint8_t dtime;
  320. for (dtime = 0; dtime < 4; dtime++) {
  321. if (check_dtimer(dtime) && diablo_key_time[dtime]) {
  322. diablo_timer[dtime] = timer_read();
  323. send_diablo_keystroke(dtime);
  324. }
  325. }
  326. }
  327. #endif
  328. void matrix_init_user(void) {
  329. // set Numlock LED to output and low
  330. DDRF |= (1<<7);
  331. PORTF &= ~(1<<7);
  332. #ifdef RGBLIGHT_ENABLE
  333. rgblight_enable();
  334. rgblight_set_teal;
  335. rgblight_mode(1);
  336. #endif
  337. if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) ){
  338. register_code(KC_NUMLOCK);
  339. unregister_code(KC_NUMLOCK);
  340. }
  341. }
  342. void matrix_scan_user(void) {
  343. numlock_led_off();
  344. if (is_overwatch && biton32(layer_state) == _MACROS) {
  345. numlock_led_on();
  346. }
  347. // Run Diablo 3 macro checking code.
  348. #ifdef TAP_DANCE_ENABLE
  349. run_diablo_macro_check();
  350. #endif
  351. }
  352. uint32_t layer_state_set_kb(uint32_t state) {
  353. #ifdef RGBLIGHT_ENABLE
  354. // Check layer, and apply color if its changed since last check
  355. switch (biton32(state)) {
  356. case _NAV:
  357. rgblight_set_blue;
  358. rgblight_mode(1);
  359. break;
  360. case _MACROS:
  361. rgblight_set_orange;
  362. is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
  363. break;
  364. case _DIABLO:
  365. rgblight_set_red;
  366. rgblight_mode(5);
  367. break;
  368. case _MEDIA:
  369. rgblight_set_green;
  370. rgblight_mode(22);
  371. break;
  372. default:
  373. rgblight_set_teal;
  374. rgblight_mode(1);
  375. break;
  376. }
  377. #endif
  378. return state;
  379. }
  380. void led_set_user(uint8_t usb_led) {
  381. }