2
0

keymap.c 13 KB

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