drashna.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. #include "eeprom.h"
  17. #include "tap_dances.h"
  18. #include "rgb_stuff.h"
  19. float tone_copy[][2] = SONG(SCROLL_LOCK_ON_SOUND);
  20. float tone_paste[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
  21. static uint16_t copy_paste_timer;
  22. userspace_config_t userspace_config;
  23. // Helper Functions
  24. // This block is for all of the gaming macros, as they were all doing
  25. // the same thing, but with differring text sent.
  26. bool send_game_macro(const char *str, keyrecord_t *record, bool override) {
  27. if (!record->event.pressed || override) {
  28. clear_keyboard();
  29. tap(userspace_config.is_overwatch ? KC_BSPC : KC_ENTER);
  30. wait_ms(50);
  31. send_string(str);
  32. wait_ms(50);
  33. tap(KC_ENTER);
  34. }
  35. if (override) wait_ms(3000);
  36. return false;
  37. }
  38. void tap(uint16_t keycode){ register_code(keycode); unregister_code(keycode); };
  39. // Add reconfigurable functions here, for keymap customization
  40. // This allows for a global, userspace functions, and continued
  41. // customization of the keymap. Use _keymap instead of _user
  42. // functions in the keymaps
  43. __attribute__ ((weak))
  44. void matrix_init_keymap(void) {}
  45. __attribute__ ((weak))
  46. void matrix_scan_keymap(void) {}
  47. __attribute__ ((weak))
  48. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  49. return true;
  50. }
  51. __attribute__ ((weak))
  52. bool process_record_secrets(uint16_t keycode, keyrecord_t *record) {
  53. return true;
  54. }
  55. __attribute__ ((weak))
  56. uint32_t layer_state_set_keymap (uint32_t state) {
  57. return state;
  58. }
  59. __attribute__ ((weak))
  60. void led_set_keymap(uint8_t usb_led) {}
  61. // Call user matrix init, set default RGB colors and then
  62. // call the keymap's init function
  63. void matrix_init_user(void) {
  64. userspace_config.raw = eeprom_read_byte(EECONFIG_USERSPACE);
  65. #ifdef AUDIO_CLICKY
  66. clicky_enable = userspace_config.clicky_enable;
  67. #endif
  68. #ifdef BOOTLOADER_CATERINA
  69. DDRD &= ~(1<<5);
  70. PORTD &= ~(1<<5);
  71. DDRB &= ~(1<<0);
  72. PORTB &= ~(1<<0);
  73. #endif
  74. #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
  75. set_unicode_input_mode(UC_WINC);
  76. #endif //UNICODE_ENABLE
  77. matrix_init_rgb();
  78. matrix_init_keymap();
  79. }
  80. // No global matrix scan code, so just run keymap's matrix
  81. // scan function
  82. void matrix_scan_user(void) {
  83. #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
  84. run_diablo_macro_check();
  85. #endif // TAP_DANCE_ENABLE
  86. #ifdef RGBLIGHT_ENABLE
  87. matrix_scan_rgb();
  88. #endif // RGBLIGHT_ENABLE
  89. matrix_scan_keymap();
  90. }
  91. // Defines actions tor my global custom keycodes. Defined in drashna.h file
  92. // Then runs the _keymap's record handier if not processed here
  93. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  94. // If console is enabled, it will print the matrix position and status of each key pressed
  95. #ifdef KEYLOGGER_ENABLE
  96. xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
  97. #endif //KEYLOGGER_ENABLE
  98. switch (keycode) {
  99. case KC_QWERTY:
  100. if (record->event.pressed) {
  101. set_single_persistent_default_layer(_QWERTY);
  102. }
  103. return false;
  104. break;
  105. case KC_COLEMAK:
  106. if (record->event.pressed) {
  107. set_single_persistent_default_layer(_COLEMAK);
  108. }
  109. return false;
  110. break;
  111. case KC_DVORAK:
  112. if (record->event.pressed) {
  113. set_single_persistent_default_layer(_DVORAK);
  114. }
  115. return false;
  116. break;
  117. case KC_WORKMAN:
  118. if (record->event.pressed) {
  119. set_single_persistent_default_layer(_WORKMAN);
  120. }
  121. return false;
  122. break;
  123. case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
  124. if (!record->event.pressed) {
  125. SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP
  126. #if (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
  127. ":dfu"
  128. #elif defined(BOOTLOADER_HALFKAY)
  129. ":teensy"
  130. #elif defined(BOOTLOADER_CATERINA)
  131. ":avrdude"
  132. #endif // bootloader options
  133. SS_TAP(X_ENTER));
  134. }
  135. return false;
  136. break;
  137. case KC_RESET: // Custom RESET code that sets RGBLights to RED
  138. if (!record->event.pressed) {
  139. #ifdef RGBLIGHT_ENABLE
  140. rgblight_enable_noeeprom();
  141. rgblight_mode_noeeprom(1);
  142. rgblight_setrgb_red();
  143. #endif // RGBLIGHT_ENABLE
  144. reset_keyboard();
  145. }
  146. return false;
  147. break;
  148. case EPRM: // Resets EEPROM
  149. if (record->event.pressed) {
  150. eeconfig_init();
  151. default_layer_set(1UL<<eeconfig_read_default_layer());
  152. layer_state_set(layer_state);
  153. }
  154. return false;
  155. break;
  156. case VRSN: // Prints firmware version
  157. if (record->event.pressed) {
  158. SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE);
  159. }
  160. return false;
  161. break;
  162. /* Code has been depreciated
  163. case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
  164. if (!record->event.pressed) {
  165. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  166. send_string(decoy_secret[keycode - KC_SECRET_1]);
  167. }
  168. return false;
  169. break;
  170. */
  171. // These are a serious of gaming macros.
  172. // Only enables for the viterbi, basically,
  173. // to save on firmware space, since it's limited.
  174. #ifdef MACROS_ENABLED
  175. case KC_OVERWATCH: // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
  176. if (record->event.pressed) { userspace_config.is_overwatch ^= 1; eeprom_update_byte(EECONFIG_USERSPACE, userspace_config.raw); }
  177. #ifdef RGBLIGHT_ENABLE
  178. userspace_config.is_overwatch ? rgblight_mode_noeeprom(17) : rgblight_mode_noeeprom(18);
  179. #endif //RGBLIGHT_ENABLE
  180. return false; break;
  181. case KC_SALT:
  182. return send_game_macro("Salt, salt, salt...", record, false);
  183. case KC_MORESALT:
  184. return send_game_macro("Please sir, can I have some more salt?!", record, false);
  185. case KC_SALTHARD:
  186. return send_game_macro("Your salt only makes me harder, and even more aggressive!", record, false);
  187. case KC_GOODGAME:
  188. return send_game_macro("Good game, everyone!", record, false);
  189. case KC_GLHF:
  190. return send_game_macro("Good luck, have fun!!!", record, false);
  191. case KC_SYMM:
  192. return send_game_macro("Left click to win!", record, false);
  193. case KC_JUSTGAME:
  194. return 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.", record, false);
  195. case KC_TORB:
  196. return send_game_macro("That was positively riveting!", record, false);
  197. case KC_AIM:
  198. send_game_macro("That aim is absolutely amazing. It's almost like you're a machine!", record, true);
  199. return send_game_macro("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!", record, false);
  200. case KC_C9:
  201. return send_game_macro("OMG!!! C9!!!", record, false);
  202. case KC_GGEZ:
  203. return send_game_macro("That was a fantastic game, though it was a bit easy. Try harder next time!", record, false);
  204. #endif // MACROS_ENABLED
  205. case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
  206. #ifdef TAP_DANCE_ENABLE
  207. if (record->event.pressed) {
  208. uint8_t dtime;
  209. for (dtime = 0; dtime < 4; dtime++) {
  210. diablo_key_time[dtime] = diablo_times[0];
  211. }
  212. }
  213. #endif // TAP_DANCE_ENABLE#endif
  214. return false; break;
  215. case KC_CCCV: // One key copy/paste
  216. if(record->event.pressed){
  217. copy_paste_timer = timer_read();
  218. } else {
  219. if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy
  220. register_code(KC_LCTL);
  221. tap(KC_C);
  222. unregister_code(KC_LCTL);
  223. #ifdef AUDIO_ENABLE
  224. PLAY_SONG(tone_copy);
  225. #endif
  226. } else { // Tap, paste
  227. register_code(KC_LCTL);
  228. tap(KC_V);
  229. unregister_code(KC_LCTL);
  230. #ifdef AUDIO_ENABLE
  231. PLAY_SONG(tone_paste);
  232. #endif
  233. }
  234. }
  235. return false;
  236. break;
  237. case CLICKY_TOGGLE:
  238. #ifdef AUDIO_CLICKY
  239. userspace_config.clicky_enable = clicky_enable;
  240. eeprom_update_byte(EECONFIG_USERSPACE, userspace_config.raw);
  241. #endif
  242. break;
  243. #ifdef UNICODE_ENABLE
  244. case UC_FLIP: // (╯°□°)╯ ︵ ┻━┻
  245. if (record->event.pressed) {
  246. register_code(KC_RSFT);
  247. tap(KC_9);
  248. unregister_code(KC_RSFT);
  249. process_unicode((0x256F | QK_UNICODE), record); // Arm
  250. process_unicode((0x00B0 | QK_UNICODE), record); // Eye
  251. process_unicode((0x25A1 | QK_UNICODE), record); // Mouth
  252. process_unicode((0x00B0 | QK_UNICODE), record); // Eye
  253. register_code(KC_RSFT);
  254. tap(KC_0);
  255. unregister_code(KC_RSFT);
  256. process_unicode((0x256F | QK_UNICODE), record); // Arm
  257. tap(KC_SPC);
  258. process_unicode((0x0361 | QK_UNICODE), record); // Flippy
  259. tap(KC_SPC);
  260. process_unicode((0x253B | QK_UNICODE), record); // Table
  261. process_unicode((0x2501 | QK_UNICODE), record); // Table
  262. process_unicode((0x253B | QK_UNICODE), record); // Table
  263. }
  264. return false;
  265. break;
  266. #endif // UNICODE_ENABLE
  267. }
  268. return process_record_keymap(keycode, record) && process_record_secrets(keycode, record) && process_record_user_rgb(keycode, record);
  269. }
  270. // Runs state check and changes underglow color and animation
  271. // on layer change, no matter where the change was initiated
  272. // Then runs keymap's layer change check
  273. uint32_t layer_state_set_user(uint32_t state) {
  274. state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
  275. #ifdef RGBLIGHT_ENABLE
  276. state = layer_state_set_rgb(state);
  277. #endif // RGBLIGHT_ENABLE
  278. return layer_state_set_keymap (state);
  279. }
  280. // Any custom LED code goes here.
  281. // So far, I only have keyboard specific code,
  282. // So nothing goes here.
  283. void led_set_user(uint8_t usb_led) {
  284. led_set_keymap(usb_led);
  285. }