drashna.c 14 KB

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