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/>.
19 #include "tap_dances.h"
20 #include "rgb_stuff.h"
22 userspace_config_t userspace_config;
24 uint16_t copy_paste_timer;
28 // This block is for all of the gaming macros, as they were all doing
29 // the same thing, but with differring text sent.
30 bool send_game_macro(const char *str, keyrecord_t *record, bool override) {
31 if (!record->event.pressed || override) {
33 if (userspace_config.is_overwatch) {
41 send_string_with_delay(str, MACRO_TIMER);
45 if (override) wait_ms(3000);
49 bool mod_key_press_timer (uint16_t code, uint16_t mod_code, bool pressed) {
50 static uint16_t this_timer;
52 this_timer= timer_read();
54 if (timer_elapsed(this_timer) < TAPPING_TERM){
56 unregister_code(code);
58 register_code(mod_code);
60 unregister_code(code);
61 unregister_code(mod_code);
67 bool mod_key_press (uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
69 this_timer= timer_read();
71 if (timer_elapsed(this_timer) < TAPPING_TERM){
73 unregister_code(code);
75 register_code(mod_code);
77 unregister_code(code);
78 unregister_code(mod_code);
84 // Add reconfigurable functions here, for keymap customization
85 // This allows for a global, userspace functions, and continued
86 // customization of the keymap. Use _keymap instead of _user
87 // functions in the keymaps
88 __attribute__ ((weak))
89 void matrix_init_keymap(void) {}
91 __attribute__ ((weak))
92 void startup_keymap(void) {}
94 __attribute__ ((weak))
95 void shutdown_keymap(void) {}
97 __attribute__ ((weak))
98 void suspend_power_down_keymap(void) {}
100 __attribute__ ((weak))
101 void suspend_wakeup_init_keymap(void) {}
103 __attribute__ ((weak))
104 void matrix_scan_keymap(void) {}
106 __attribute__ ((weak))
107 bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
111 __attribute__ ((weak))
112 bool process_record_secrets(uint16_t keycode, keyrecord_t *record) {
117 __attribute__ ((weak))
118 uint32_t layer_state_set_keymap (uint32_t state) {
122 __attribute__ ((weak))
123 uint32_t default_layer_state_set_keymap (uint32_t state) {
127 __attribute__ ((weak))
128 void led_set_keymap(uint8_t usb_led) {}
130 __attribute__ ((weak))
131 void eeconfig_init_keymap(void) {}
133 // Call user matrix init, set default RGB colors and then
134 // call the keymap's init function
135 void matrix_init_user(void) {
136 userspace_config.raw = eeconfig_read_user();
138 #ifdef BOOTLOADER_CATERINA
146 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
147 if (eeprom_read_byte(EECONFIG_UNICODEMODE) != UC_WIN) {
148 set_unicode_input_mode(UC_WIN);
150 #endif //UNICODE_ENABLE
151 matrix_init_keymap();
154 void startup_user (void) {
155 #ifdef RGBLIGHT_ENABLE
157 #endif //RGBLIGHT_ENABLE
161 void shutdown_user (void) {
162 #ifdef RGBLIGHT_ENABLE
163 rgblight_enable_noeeprom();
164 rgblight_mode_noeeprom(1);
165 rgblight_setrgb_red();
166 #endif // RGBLIGHT_ENABLE
167 #ifdef RGB_MATRIX_ENABLE
169 for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
171 if (led.matrix_co.raw < 0xFF) {
172 rgb_matrix_set_color( i, 0xFF, 0x00, 0x00 );
175 #endif //RGB_MATRIX_ENABLE
179 void suspend_power_down_user(void) {
180 suspend_power_down_keymap();
183 void suspend_wakeup_init_user(void) {
184 suspend_wakeup_init_keymap();
188 // No global matrix scan code, so just run keymap's matrix
190 void matrix_scan_user(void) {
191 static bool has_ran_yet;
197 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
198 run_diablo_macro_check();
199 #endif // TAP_DANCE_ENABLE
201 #ifdef RGBLIGHT_ENABLE
203 #endif // RGBLIGHT_ENABLE
205 matrix_scan_keymap();
211 // Defines actions tor my global custom keycodes. Defined in drashna.h file
212 // Then runs the _keymap's record handier if not processed here
213 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
215 // If console is enabled, it will print the matrix position and status of each key pressed
216 #ifdef KEYLOGGER_ENABLE
217 #if defined(KEYBOARD_ergodox_ez) || defined(KEYBOARD_iris_rev2)
218 xprintf("KL: col: %u, row: %u, pressed: %u\n", record->event.key.row, record->event.key.col, record->event.pressed);
220 xprintf("KL: col: %u, row: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
222 #endif //KEYLOGGER_ENABLE
226 if (record->event.pressed) {
227 set_single_persistent_default_layer(_QWERTY);
232 if (record->event.pressed) {
233 set_single_persistent_default_layer(_COLEMAK);
238 if (record->event.pressed) {
239 set_single_persistent_default_layer(_DVORAK);
244 if (record->event.pressed) {
245 set_single_persistent_default_layer(_WORKMAN);
251 case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
252 if (!record->event.pressed) {
253 uint8_t temp_mod = get_mods();
255 send_string_with_delay_P(PSTR("make " QMK_KEYBOARD ":" QMK_KEYMAP), 10);
256 if (temp_mod & MODS_SHIFT_MASK) {
257 send_string_with_delay_P(PSTR(
260 #elif defined(BOOTLOADER_DFU)
262 #elif defined(BOOTLOADER_HALFKAY)
264 #elif defined(BOOTLOADER_CATERINA)
266 #endif // bootloader options
269 if (temp_mod & MODS_CTRL_MASK) { send_string_with_delay_P(PSTR(" -j8 --output-sync"), 10); }
270 send_string_with_delay_P(PSTR(SS_TAP(X_ENTER)), 10);
276 case EPRM: // Resets EEPROM
277 if (record->event.pressed) {
282 case VRSN: // Prints firmware version
283 if (record->event.pressed) {
284 send_string_with_delay_P(PSTR(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE), MACRO_TIMER);
289 /* Code has been depreciated
290 case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
291 if (!record->event.pressed) {
292 clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
293 send_string(decoy_secret[keycode - KC_SECRET_1]);
299 // These are a serious of gaming macros.
300 // Only enables for the viterbi, basically,
301 // to save on firmware space, since it's limited.
302 #ifdef MACROS_ENABLED
303 case KC_OVERWATCH: // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
304 if (record->event.pressed) { userspace_config.is_overwatch ^= 1; eeconfig_update_user(userspace_config.raw); }
305 #ifdef RGBLIGHT_ENABLE
306 userspace_config.is_overwatch ? rgblight_mode_noeeprom(17) : rgblight_mode_noeeprom(18);
307 #endif //RGBLIGHT_ENABLE
310 return send_game_macro("Salt, salt, salt...", record, false);
312 return send_game_macro("Please sir, can I have some more salt?!", record, false);
314 return send_game_macro("Your salt only makes me harder, and even more aggressive!", record, false);
316 return send_game_macro("Good game, everyone!", record, false);
318 return send_game_macro("Good luck, have fun!!!", record, false);
320 return send_game_macro("Left click to win!", record, false);
322 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);
324 return send_game_macro("That was positively riveting!", record, false);
326 send_game_macro("That aim is absolutely amazing. It's almost like you're a machine!", record, true);
327 return send_game_macro("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!", record, false);
329 return send_game_macro("OMG!!! C9!!!", record, false);
331 return send_game_macro("That was a fantastic game, though it was a bit easy. Try harder next time!", record, false);
332 #endif // MACROS_ENABLED
335 case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
336 #ifdef TAP_DANCE_ENABLE
337 if (record->event.pressed) {
339 for (dtime = 0; dtime < 4; dtime++) {
340 diablo_key_time[dtime] = diablo_times[0];
343 #endif // TAP_DANCE_ENABLE
347 case KC_CCCV: // One key copy/paste
348 if(record->event.pressed){
349 copy_paste_timer = timer_read();
351 if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy
352 register_code(KC_LCTL);
354 unregister_code(KC_LCTL);
355 } else { // Tap, paste
356 register_code(KC_LCTL);
358 unregister_code(KC_LCTL);
363 #ifdef UNICODE_ENABLE
364 case UC_FLIP: // (ノಠ痊ಠ)ノ彡┻━┻
365 if (record->event.pressed) {
366 send_unicode_hex_string("0028 30CE 0CA0 75CA 0CA0 0029 30CE 5F61 253B 2501 253B");
370 case UC_TABL: // ┬─┬ノ( º _ ºノ)
371 if (record->event.pressed) {
372 send_unicode_hex_string("252C 2500 252C 30CE 0028 0020 00BA 0020 005F 0020 00BA 30CE 0029");
376 case UC_SHRG: // ¯\_(ツ)_/¯
377 if (record->event.pressed) {
378 send_unicode_hex_string("00AF 005C 005F 0028 30C4 0029 005F 002F 00AF");
383 if (record->event.pressed) {
384 send_unicode_hex_string("0CA0 005F 0CA0");
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_user(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);
423 void eeconfig_init_user(void) {
424 userspace_config.raw = 0;
425 eeconfig_update_user(userspace_config.raw);