drashna.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /*
  2. Copyright 2017 Christopher Courtney <drashna@live.com> @drashna
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "drashna.h"
  15. #include "quantum.h"
  16. #include "action.h"
  17. #include "version.h"
  18. #if (__has_include("secrets.h"))
  19. #include "secrets.h"
  20. #else
  21. PROGMEM const char secret[][64] = {
  22. "test1",
  23. "test2",
  24. "test3",
  25. "test4",
  26. "test5"
  27. };
  28. #endif
  29. #ifdef TAP_DANCE_ENABLE
  30. //define diablo macro timer variables
  31. static uint16_t diablo_timer[4];
  32. static uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 };
  33. static uint8_t diablo_key_time[4];
  34. bool check_dtimer(uint8_t dtimer) {
  35. // has the correct number of seconds elapsed (as defined by diablo_times)
  36. return (timer_elapsed(diablo_timer[dtimer]) < (diablo_key_time[dtimer] * 1000)) ? false : true;
  37. };
  38. // Cycle through the times for the macro, starting at 0, for disabled.
  39. // Max of six values, so don't exceed
  40. void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data, uint8_t diablo_key) {
  41. if (state->count >= 7) {
  42. diablo_key_time[diablo_key] = diablo_times[0];
  43. reset_tap_dance(state);
  44. }
  45. else {
  46. diablo_key_time[diablo_key] = diablo_times[state->count - 1];
  47. }
  48. }
  49. // Would rather have one function for all of this, but no idea how to do that...
  50. void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) {
  51. diablo_tapdance_master(state, user_data, 0);
  52. }
  53. void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) {
  54. diablo_tapdance_master(state, user_data, 1);
  55. }
  56. void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) {
  57. diablo_tapdance_master(state, user_data, 2);
  58. }
  59. void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) {
  60. diablo_tapdance_master(state, user_data, 3);
  61. }
  62. //Tap Dance Definitions
  63. qk_tap_dance_action_t tap_dance_actions[] = {
  64. // tap once to disable, and more to enable timed micros
  65. [TD_D3_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1),
  66. [TD_D3_2] = ACTION_TAP_DANCE_FN(diablo_tapdance2),
  67. [TD_D3_3] = ACTION_TAP_DANCE_FN(diablo_tapdance3),
  68. [TD_D3_4] = ACTION_TAP_DANCE_FN(diablo_tapdance4),
  69. };
  70. #endif
  71. #ifdef AUDIO_ENABLE
  72. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  73. float tone_dvorak[][2] = SONG(DVORAK_SOUND);
  74. float tone_colemak[][2] = SONG(COLEMAK_SOUND);
  75. float tone_workman[][2] = SONG(PLOVER_SOUND);
  76. float tone_hackstartup[][2] = SONG(ONE_UP_SOUND);
  77. #endif
  78. // Add reconfigurable functions here, for keymap customization
  79. // This allows for a global, userspace functions, and continued
  80. // customization of the keymap. Use _keymap instead of _user
  81. // functions in the keymaps
  82. __attribute__ ((weak))
  83. void matrix_init_keymap(void) {}
  84. __attribute__ ((weak))
  85. void matrix_scan_keymap(void) {}
  86. __attribute__ ((weak))
  87. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  88. return true;
  89. }
  90. __attribute__ ((weak))
  91. uint32_t layer_state_set_keymap (uint32_t state) {
  92. return state;
  93. }
  94. __attribute__ ((weak))
  95. void led_set_keymap(uint8_t usb_led) {}
  96. bool is_overwatch = false;
  97. #ifdef RGBLIGHT_ENABLE
  98. bool rgb_layer_change = true;
  99. #endif
  100. // Call user matrix init, set default RGB colors and then
  101. // call the keymap's init function
  102. void matrix_init_user(void) {
  103. #ifdef RGBLIGHT_ENABLE
  104. uint8_t default_layer = eeconfig_read_default_layer();
  105. rgblight_enable();
  106. if (true) {
  107. if (default_layer & (1UL << _COLEMAK)) {
  108. rgblight_set_magenta;
  109. }
  110. else if (default_layer & (1UL << _DVORAK)) {
  111. rgblight_set_green;
  112. }
  113. else if (default_layer & (1UL << _WORKMAN)) {
  114. rgblight_set_purple;
  115. }
  116. else {
  117. rgblight_set_teal;
  118. }
  119. }
  120. else
  121. {
  122. rgblight_set_red;
  123. rgblight_mode(5);
  124. }
  125. #endif
  126. #ifdef AUDIO_ENABLE
  127. // _delay_ms(21); // gets rid of tick
  128. // stop_all_notes();
  129. // PLAY_SONG(tone_hackstartup);
  130. #endif
  131. matrix_init_keymap();
  132. }
  133. #ifdef TAP_DANCE_ENABLE
  134. // Sends the key press to system, but only if on the Diablo layer
  135. void send_diablo_keystroke(uint8_t diablo_key) {
  136. if (biton32(layer_state) == _DIABLO) {
  137. switch (diablo_key) {
  138. case 0:
  139. SEND_STRING("1");
  140. break;
  141. case 1:
  142. SEND_STRING("2");
  143. break;
  144. case 2:
  145. SEND_STRING("3");
  146. break;
  147. case 3:
  148. SEND_STRING("4");
  149. break;
  150. }
  151. }
  152. }
  153. // Checks each of the 4 timers/keys to see if enough time has elapsed
  154. // Runs the "send string" command if enough time has passed, and resets the timer.
  155. void run_diablo_macro_check(void) {
  156. uint8_t dtime;
  157. for (dtime = 0; dtime < 4; dtime++) {
  158. if (check_dtimer(dtime) && diablo_key_time[dtime]) {
  159. diablo_timer[dtime] = timer_read();
  160. send_diablo_keystroke(dtime);
  161. }
  162. }
  163. }
  164. #endif
  165. // No global matrix scan code, so just run keymap's matix
  166. // scan function
  167. void matrix_scan_user(void) {
  168. #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
  169. run_diablo_macro_check();
  170. #endif
  171. matrix_scan_keymap();
  172. }
  173. void led_set_user(uint8_t usb_led) {
  174. led_set_keymap(usb_led);
  175. }
  176. void persistent_default_layer_set(uint16_t default_layer) {
  177. eeconfig_update_default_layer(default_layer);
  178. default_layer_set(default_layer);
  179. }
  180. // Defines actions tor my global custom keycodes. Defined in drashna.h file
  181. // Then runs the _keymap's recod handier if not processed here
  182. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  183. #ifdef CONSOLE_ENABLE
  184. xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
  185. #endif
  186. switch (keycode) {
  187. case KC_QWERTY:
  188. if (record->event.pressed) {
  189. #ifdef AUDIO_ENABLE
  190. PLAY_SONG(tone_qwerty);
  191. #endif
  192. persistent_default_layer_set(1UL << _QWERTY);
  193. }
  194. return false;
  195. break;
  196. case KC_COLEMAK:
  197. if (record->event.pressed) {
  198. #ifdef AUDIO_ENABLE
  199. PLAY_SONG(tone_colemak);
  200. #endif
  201. persistent_default_layer_set(1UL << _COLEMAK);
  202. }
  203. return false;
  204. break;
  205. case KC_DVORAK:
  206. if (record->event.pressed) {
  207. #ifdef AUDIO_ENABLE
  208. PLAY_SONG(tone_dvorak);
  209. #endif
  210. persistent_default_layer_set(1UL << _DVORAK);
  211. }
  212. return false;
  213. break;
  214. case KC_WORKMAN:
  215. if (record->event.pressed) {
  216. #ifdef AUDIO_ENABLE
  217. PLAY_SONG(tone_workman);
  218. #endif
  219. persistent_default_layer_set(1UL << _WORKMAN);
  220. }
  221. return false;
  222. break;
  223. case LOWER:
  224. if (record->event.pressed) {
  225. layer_on(_LOWER);
  226. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  227. }
  228. else {
  229. layer_off(_LOWER);
  230. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  231. }
  232. return false;
  233. break;
  234. case RAISE:
  235. if (record->event.pressed) {
  236. layer_on(_RAISE);
  237. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  238. }
  239. else {
  240. layer_off(_RAISE);
  241. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  242. }
  243. return false;
  244. break;
  245. case ADJUST:
  246. if (record->event.pressed) {
  247. layer_on(_ADJUST);
  248. }
  249. else {
  250. layer_off(_ADJUST);
  251. }
  252. return false;
  253. break;
  254. #if !(defined(KEYBOARD_orthodox_rev1) || defined(KEYBOARD_ergodox_ez))
  255. case KC_OVERWATCH:
  256. if (record->event.pressed) {
  257. is_overwatch = !is_overwatch;
  258. }
  259. #ifdef RGBLIGHT_ENABLE
  260. is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
  261. #endif
  262. return false;
  263. break;
  264. case KC_SALT:
  265. if (!record->event.pressed) {
  266. register_code(is_overwatch ? KC_BSPC : KC_ENTER);
  267. unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
  268. _delay_ms(50);
  269. SEND_STRING("Salt, salt, salt...");
  270. register_code(KC_ENTER);
  271. unregister_code(KC_ENTER);
  272. }
  273. return false;
  274. break;
  275. case KC_MORESALT:
  276. if (!record->event.pressed) {
  277. register_code(is_overwatch ? KC_BSPC : KC_ENTER);
  278. unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
  279. _delay_ms(50);
  280. SEND_STRING("Please sir, can I have some more salt?!");
  281. register_code(KC_ENTER);
  282. unregister_code(KC_ENTER);
  283. }
  284. return false;
  285. break;
  286. case KC_SALTHARD:
  287. if (!record->event.pressed) {
  288. register_code(is_overwatch ? KC_BSPC : KC_ENTER);
  289. unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
  290. _delay_ms(50);
  291. SEND_STRING("Your salt only makes me harder, and even more aggressive!");
  292. register_code(KC_ENTER);
  293. unregister_code(KC_ENTER);
  294. }
  295. return false;
  296. break;
  297. case KC_GOODGAME:
  298. if (!record->event.pressed) {
  299. register_code(is_overwatch ? KC_BSPC : KC_ENTER);
  300. unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
  301. _delay_ms(50);
  302. SEND_STRING("Good game, everyone!");
  303. register_code(KC_ENTER);
  304. unregister_code(KC_ENTER);
  305. }
  306. return false;
  307. break;
  308. case KC_GLHF:
  309. if (!record->event.pressed) {
  310. register_code(is_overwatch ? KC_BSPC : KC_ENTER);
  311. unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
  312. _delay_ms(50);
  313. SEND_STRING("Good luck, have fun!!!");
  314. register_code(KC_ENTER);
  315. unregister_code(KC_ENTER);
  316. }
  317. return false;
  318. break;
  319. case KC_SYMM:
  320. if (!record->event.pressed) {
  321. register_code(is_overwatch ? KC_BSPC : KC_ENTER);
  322. unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
  323. _delay_ms(50);
  324. SEND_STRING("Left click to win!");
  325. register_code(KC_ENTER);
  326. unregister_code(KC_ENTER);
  327. }
  328. return false;
  329. break;
  330. case KC_JUSTGAME:
  331. if (!record->event.pressed) {
  332. register_code(is_overwatch ? KC_BSPC : KC_ENTER);
  333. unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
  334. _delay_ms(50);
  335. 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.");
  336. register_code(KC_ENTER);
  337. unregister_code(KC_ENTER);
  338. }
  339. return false;
  340. break;
  341. case KC_TORB:
  342. if (!record->event.pressed) {
  343. register_code(is_overwatch ? KC_BSPC : KC_ENTER);
  344. unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
  345. _delay_ms(50);
  346. SEND_STRING("That was positively riveting!");
  347. register_code(KC_ENTER);
  348. unregister_code(KC_ENTER);
  349. }
  350. return false;
  351. break;
  352. case KC_AIM:
  353. if (!record->event.pressed) {
  354. register_code(is_overwatch ? KC_BSPC : KC_ENTER);
  355. unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
  356. _delay_ms(50);
  357. SEND_STRING("That aim is absolutely amazing. It's almost like you're a machine!" SS_TAP(X_ENTER));
  358. _delay_ms(3000);
  359. register_code(is_overwatch ? KC_BSPC : KC_ENTER);
  360. unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
  361. SEND_STRING("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!" SS_TAP(X_ENTER));
  362. }
  363. return false;
  364. break;
  365. case KC_C9:
  366. if (!record->event.pressed) {
  367. register_code(is_overwatch ? KC_BSPC : KC_ENTER);
  368. unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
  369. _delay_ms(50);
  370. SEND_STRING("OMG!!! C9!!!");
  371. register_code(KC_ENTER);
  372. unregister_code(KC_ENTER);
  373. }
  374. return false;
  375. break;
  376. case KC_GGEZ:
  377. if (!record->event.pressed) {
  378. register_code(is_overwatch ? KC_BSPC : KC_ENTER);
  379. unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
  380. _delay_ms(50);
  381. SEND_STRING("That was a fantastic game, though it was a bit easy. Try harder next time!");
  382. register_code(KC_ENTER);
  383. unregister_code(KC_ENTER);
  384. }
  385. return false;
  386. break;
  387. #endif
  388. #ifdef TAP_DANCE_ENABLE
  389. case KC_DIABLO_CLEAR: // reset all Diable timers, disabling them
  390. if (record->event.pressed) {
  391. uint8_t dtime;
  392. for (dtime = 0; dtime < 4; dtime++) {
  393. diablo_key_time[dtime] = diablo_times[0];
  394. }
  395. }
  396. return false;
  397. break;
  398. #endif
  399. case KC_MAKE:
  400. if (!record->event.pressed) {
  401. SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP
  402. #if (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
  403. ":dfu"
  404. #elif defined(BOOTLOADER_HALFKAY)
  405. ":teensy"
  406. #elif defined(BOOTLOADER_CATERINA)
  407. ":avrdude"
  408. #endif
  409. #ifdef RGBLIGHT_ENABLE
  410. " RGBLIGHT_ENABLE=yes"
  411. #else
  412. " RGBLIGHT_ENABLE=no"
  413. #endif
  414. #ifdef AUDIO_ENABLE
  415. " AUDIO_ENABLE=yes"
  416. #else
  417. " AUDIO_ENABLE=no"
  418. #endif
  419. #ifdef FAUXCLICKY_ENABLE
  420. " FAUXCLICKY_ENABLE=yes"
  421. #else
  422. " FAUXCLICKY_ENABLE=no"
  423. #endif
  424. SS_TAP(X_ENTER));
  425. }
  426. return false;
  427. break;
  428. case KC_RESET:
  429. if (!record->event.pressed) {
  430. #ifdef RGBLIGHT_ENABLE
  431. rgblight_enable();
  432. rgblight_mode(1);
  433. rgblight_setrgb(0xff, 0x00, 0x00);
  434. #endif
  435. reset_keyboard();
  436. }
  437. return false;
  438. break;
  439. case EPRM:
  440. if (record->event.pressed) {
  441. eeconfig_init();
  442. }
  443. return false;
  444. break;
  445. case VRSN:
  446. if (record->event.pressed) {
  447. SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION);
  448. }
  449. return false;
  450. break;
  451. case KC_SECRET_1 ... KC_SECRET_5:
  452. if (!record->event.pressed) {
  453. send_string_P(secret[keycode - KC_SECRET_1]);
  454. }
  455. return false;
  456. break;
  457. case KC_RGB_T: // Because I want the option to go back to normal RGB mode rather than always layer indication
  458. #ifdef RGBLIGHT_ENABLE
  459. if (record->event.pressed) {
  460. rgb_layer_change = !rgb_layer_change;
  461. }
  462. #endif
  463. return false;
  464. break;
  465. #ifdef RGBLIGHT_ENABLE
  466. case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
  467. if (record->event.pressed) { //This disrables layer indication, as it's assumed that if you're changing this ... you want that disabled
  468. rgb_layer_change = false;
  469. }
  470. return true;
  471. break;
  472. #endif
  473. }
  474. return process_record_keymap(keycode, record);
  475. }
  476. // Runs state check and changes underglow color and animation
  477. // on layer change, no matter where the change was initiated
  478. // Then runs keymap's layer change check
  479. uint32_t layer_state_set_user(uint32_t state) {
  480. #ifdef RGBLIGHT_ENABLE
  481. uint8_t default_layer = eeconfig_read_default_layer();
  482. if (rgb_layer_change) {
  483. switch (biton32(state)) {
  484. case _NAV:
  485. rgblight_set_blue;
  486. rgblight_mode(1);
  487. break;
  488. case _SYMB:
  489. rgblight_set_blue;
  490. rgblight_mode(2);
  491. break;
  492. case _MOUS:
  493. rgblight_set_yellow;
  494. rgblight_mode(1);
  495. break;
  496. case _MACROS:
  497. rgblight_set_orange;
  498. is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
  499. break;
  500. case _MEDIA:
  501. rgblight_set_green;
  502. rgblight_mode(22);
  503. break;
  504. case _GAMEPAD:
  505. rgblight_set_orange;
  506. rgblight_mode(17);
  507. break;
  508. case _DIABLO:
  509. rgblight_set_red;
  510. rgblight_mode(5);
  511. break;
  512. case _RAISE:
  513. rgblight_set_yellow;
  514. rgblight_mode(5);
  515. break;
  516. case _LOWER:
  517. rgblight_set_orange;
  518. rgblight_mode(5);
  519. break;
  520. case _ADJUST:
  521. rgblight_set_red;
  522. rgblight_mode(23);
  523. break;
  524. case _COVECUBE:
  525. rgblight_set_green;
  526. rgblight_mode(2);
  527. default:
  528. if (default_layer & (1UL << _COLEMAK)) {
  529. rgblight_set_magenta;
  530. }
  531. else if (default_layer & (1UL << _DVORAK)) {
  532. rgblight_set_green;
  533. }
  534. else if (default_layer & (1UL << _WORKMAN)) {
  535. rgblight_set_purple;
  536. }
  537. else {
  538. rgblight_set_teal;
  539. }
  540. rgblight_mode(1);
  541. break;
  542. }
  543. }
  544. #endif
  545. return layer_state_set_keymap (state);
  546. }