2 Copyright 2017 Christopher Courtney <drashna@live.com> @drashna
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "tap_dances.h"
22 #include "rgb_stuff.h"
25 float tone_copy[][2] = SONG(SCROLL_LOCK_ON_SOUND);
26 float tone_paste[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
28 static uint16_t copy_paste_timer;
29 userspace_config_t userspace_config;
34 // This block is for all of the gaming macros, as they were all doing
35 // the same thing, but with differring text sent.
36 bool send_game_macro(const char *str, keyrecord_t *record, bool override) {
37 if (!record->event.pressed || override) {
39 tap(userspace_config.is_overwatch ? KC_BSPC : KC_ENTER);
41 send_string_with_delay(str, MACRO_TIMER);
45 if (override) wait_ms(3000);
49 void tap(uint16_t keycode){ register_code(keycode); unregister_code(keycode); };
51 bool mod_key_press_timer (uint16_t code, uint16_t mod_code, bool pressed) {
52 static uint16_t this_timer;
54 this_timer= timer_read();
56 if (timer_elapsed(this_timer) < TAPPING_TERM){
58 unregister_code(code);
60 register_code(mod_code);
62 unregister_code(code);
63 unregister_code(mod_code);
69 bool mod_key_press (uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
71 this_timer= timer_read();
73 if (timer_elapsed(this_timer) < TAPPING_TERM){
75 unregister_code(code);
77 register_code(mod_code);
79 unregister_code(code);
80 unregister_code(mod_code);
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) {}
93 __attribute__ ((weak))
94 void startup_keymap(void) {}
96 __attribute__ ((weak))
97 void suspend_power_down_keymap(void) {}
99 __attribute__ ((weak))
100 void suspend_wakeup_init_keymap(void) {}
102 __attribute__ ((weak))
103 void matrix_scan_keymap(void) {}
105 __attribute__ ((weak))
106 bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
110 __attribute__ ((weak))
111 bool process_record_secrets(uint16_t keycode, keyrecord_t *record) {
116 __attribute__ ((weak))
117 uint32_t layer_state_set_keymap (uint32_t state) {
121 __attribute__ ((weak))
122 uint32_t default_layer_state_set_keymap (uint32_t state) {
126 __attribute__ ((weak))
127 void led_set_keymap(uint8_t usb_led) {}
130 // Call user matrix init, set default RGB colors and then
131 // call the keymap's init function
132 void matrix_init_user(void) {
133 userspace_config.raw = eeprom_read_byte(EECONFIG_USERSPACE);
136 clicky_enable = userspace_config.clicky_enable;
139 #ifdef BOOTLOADER_CATERINA
148 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
149 set_unicode_input_mode(UC_WINC);
150 #endif //UNICODE_ENABLE
151 matrix_init_keymap();
154 void startup_user (void) {
155 #ifdef RGBLIGHT_ENABLE
157 #endif //RGBLIGHT_ENABLE
161 void suspend_power_down_user(void)
163 suspend_power_down_keymap();
166 void suspend_wakeup_init_user(void)
168 suspend_wakeup_init_keymap();
169 #ifdef KEYBOARD_ergodox_ez
175 // No global matrix scan code, so just run keymap's matrix
177 void matrix_scan_user(void) {
178 static bool has_ran_yet;
184 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
185 run_diablo_macro_check();
186 #endif // TAP_DANCE_ENABLE
188 #ifdef RGBLIGHT_ENABLE
190 #endif // RGBLIGHT_ENABLE
192 matrix_scan_keymap();
198 // Defines actions tor my global custom keycodes. Defined in drashna.h file
199 // Then runs the _keymap's record handier if not processed here
200 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
202 // If console is enabled, it will print the matrix position and status of each key pressed
203 #ifdef KEYLOGGER_ENABLE
204 xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
205 #endif //KEYLOGGER_ENABLE
209 if (record->event.pressed) {
210 set_single_persistent_default_layer(_QWERTY);
215 if (record->event.pressed) {
216 set_single_persistent_default_layer(_COLEMAK);
221 if (record->event.pressed) {
222 set_single_persistent_default_layer(_DVORAK);
227 if (record->event.pressed) {
228 set_single_persistent_default_layer(_WORKMAN);
234 case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
235 if (!record->event.pressed) {
236 send_string_with_delay_P(PSTR("make " QMK_KEYBOARD ":" QMK_KEYMAP
237 #if (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
239 #elif defined(BOOTLOADER_HALFKAY)
241 #elif defined(BOOTLOADER_CATERINA)
243 #endif // bootloader options
244 SS_TAP(X_ENTER)), 10);
250 case KC_RESET: // Custom RESET code that sets RGBLights to RED
251 if (!record->event.pressed) {
252 #ifdef RGBLIGHT_ENABLE
253 rgblight_enable_noeeprom();
254 rgblight_mode_noeeprom(1);
255 rgblight_setrgb_red();
256 #endif // RGBLIGHT_ENABLE
263 case EPRM: // Resets EEPROM
264 if (record->event.pressed) {
266 default_layer_set(1UL<<eeconfig_read_default_layer());
267 layer_state_set(layer_state);
271 case VRSN: // Prints firmware version
272 if (record->event.pressed) {
273 send_string_with_delay_P(PSTR(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE), MACRO_TIMER);
278 /* Code has been depreciated
279 case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
280 if (!record->event.pressed) {
281 clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
282 send_string(decoy_secret[keycode - KC_SECRET_1]);
288 // These are a serious of gaming macros.
289 // Only enables for the viterbi, basically,
290 // to save on firmware space, since it's limited.
291 #ifdef MACROS_ENABLED
292 case KC_OVERWATCH: // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
293 if (record->event.pressed) { userspace_config.is_overwatch ^= 1; eeprom_update_byte(EECONFIG_USERSPACE, userspace_config.raw); }
294 #ifdef RGBLIGHT_ENABLE
295 userspace_config.is_overwatch ? rgblight_mode_noeeprom(17) : rgblight_mode_noeeprom(18);
296 #endif //RGBLIGHT_ENABLE
299 return send_game_macro("Salt, salt, salt...", record, false);
301 return send_game_macro("Please sir, can I have some more salt?!", record, false);
303 return send_game_macro("Your salt only makes me harder, and even more aggressive!", record, false);
305 return send_game_macro("Good game, everyone!", record, false);
307 return send_game_macro("Good luck, have fun!!!", record, false);
309 return send_game_macro("Left click to win!", record, false);
311 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);
313 return send_game_macro("That was positively riveting!", record, false);
315 send_game_macro("That aim is absolutely amazing. It's almost like you're a machine!", record, true);
316 return send_game_macro("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!", record, false);
318 return send_game_macro("OMG!!! C9!!!", record, false);
320 return send_game_macro("That was a fantastic game, though it was a bit easy. Try harder next time!", record, false);
321 #endif // MACROS_ENABLED
324 case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
325 #ifdef TAP_DANCE_ENABLE
326 if (record->event.pressed) {
328 for (dtime = 0; dtime < 4; dtime++) {
329 diablo_key_time[dtime] = diablo_times[0];
332 #endif // TAP_DANCE_ENABLE
336 case KC_CCCV: // One key copy/paste
337 if(record->event.pressed){
338 copy_paste_timer = timer_read();
340 if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy
341 register_code(KC_LCTL);
343 unregister_code(KC_LCTL);
345 PLAY_SONG(tone_copy);
347 } else { // Tap, paste
348 register_code(KC_LCTL);
350 unregister_code(KC_LCTL);
352 PLAY_SONG(tone_paste);
360 userspace_config.clicky_enable = clicky_enable;
361 eeprom_update_byte(EECONFIG_USERSPACE, userspace_config.raw);
364 #ifdef UNICODE_ENABLE
365 case UC_FLIP: // (╯°□°)╯ ︵ ┻━┻
366 if (record->event.pressed) {
367 register_code(KC_RSFT);
369 unregister_code(KC_RSFT);
370 process_unicode((0x256F | QK_UNICODE), record); // Arm
371 process_unicode((0x00B0 | QK_UNICODE), record); // Eye
372 process_unicode((0x25A1 | QK_UNICODE), record); // Mouth
373 process_unicode((0x00B0 | QK_UNICODE), record); // Eye
374 register_code(KC_RSFT);
376 unregister_code(KC_RSFT);
377 process_unicode((0x256F | QK_UNICODE), record); // Arm
379 process_unicode((0x0361 | QK_UNICODE), record); // Flippy
381 process_unicode((0x253B | QK_UNICODE), record); // Table
382 process_unicode((0x2501 | QK_UNICODE), record); // Table
383 process_unicode((0x253B | QK_UNICODE), record); // Table
387 #endif // UNICODE_ENABLE
390 return process_record_keymap(keycode, record) &&
391 #ifdef RGBLIGHT_ENABLE
392 process_record_user_rgb(keycode, record) &&
393 #endif // RGBLIGHT_ENABLE
394 process_record_secrets(keycode, record);
399 // Runs state check and changes underglow color and animation
400 // on layer change, no matter where the change was initiated
401 // Then runs keymap's layer change check
402 uint32_t layer_state_set_user(uint32_t state) {
403 state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
404 #ifdef RGBLIGHT_ENABLE
405 state = layer_state_set_rgb(state);
406 #endif // RGBLIGHT_ENABLE
407 return layer_state_set_keymap (state);
411 uint32_t default_layer_state_set_kb(uint32_t state) {
412 return default_layer_state_set_keymap (state);
416 // Any custom LED code goes here.
417 // So far, I only have keyboard specific code,
418 // So nothing goes here.
419 void led_set_user(uint8_t usb_led) {
420 led_set_keymap(usb_led);