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;
27 // This block is for all of the gaming macros, as they were all doing
28 // the same thing, but with differring text sent.
29 bool send_game_macro(const char *str, keyrecord_t *record, bool override) {
30 if (!record->event.pressed || override) {
32 if (userspace_config.is_overwatch) {
40 send_string_with_delay(str, MACRO_TIMER);
44 if (override) wait_ms(3000);
48 bool mod_key_press_timer (uint16_t code, uint16_t mod_code, bool pressed) {
49 static uint16_t this_timer;
51 this_timer= timer_read();
53 if (timer_elapsed(this_timer) < TAPPING_TERM){
55 unregister_code(code);
57 register_code(mod_code);
59 unregister_code(code);
60 unregister_code(mod_code);
66 bool mod_key_press (uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
68 this_timer= timer_read();
70 if (timer_elapsed(this_timer) < TAPPING_TERM){
72 unregister_code(code);
74 register_code(mod_code);
76 unregister_code(code);
77 unregister_code(mod_code);
83 // Add reconfigurable functions here, for keymap customization
84 // This allows for a global, userspace functions, and continued
85 // customization of the keymap. Use _keymap instead of _user
86 // functions in the keymaps
87 __attribute__ ((weak))
88 void matrix_init_keymap(void) {}
90 __attribute__ ((weak))
91 void startup_keymap(void) {}
93 __attribute__ ((weak))
94 void shutdown_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) {}
131 // Call user matrix init, set default RGB colors and then
132 // call the keymap's init function
133 void matrix_init_user(void) {
134 userspace_config.raw = eeprom_read_byte(EECONFIG_USERSPACE);
137 #ifdef BOOTLOADER_CATERINA
145 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
146 set_unicode_input_mode(UC_WINC);
147 #endif //UNICODE_ENABLE
148 matrix_init_keymap();
151 void startup_user (void) {
152 #ifdef RGBLIGHT_ENABLE
154 #endif //RGBLIGHT_ENABLE
158 void shutdown_user (void) {
159 #ifdef RGBLIGHT_ENABLE
160 rgblight_enable_noeeprom();
161 rgblight_mode_noeeprom(1);
162 rgblight_setrgb_red();
163 #endif // RGBLIGHT_ENABLE
164 #ifdef RGB_MATRIX_ENABLE
166 for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
168 if (led.matrix_co.raw < 0xFF) {
169 rgb_matrix_set_color( i, 0xFF, 0x00, 0x00 );
172 #endif //RGB_MATRIX_ENABLE
176 void suspend_power_down_user(void)
178 suspend_power_down_keymap();
181 void suspend_wakeup_init_user(void)
183 suspend_wakeup_init_keymap();
184 #ifdef KEYBOARD_ergodox_ez
190 // No global matrix scan code, so just run keymap's matrix
192 void matrix_scan_user(void) {
193 static bool has_ran_yet;
199 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
200 run_diablo_macro_check();
201 #endif // TAP_DANCE_ENABLE
203 #ifdef RGBLIGHT_ENABLE
205 #endif // RGBLIGHT_ENABLE
207 matrix_scan_keymap();
213 // Defines actions tor my global custom keycodes. Defined in drashna.h file
214 // Then runs the _keymap's record handier if not processed here
215 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
217 // If console is enabled, it will print the matrix position and status of each key pressed
218 #ifdef KEYLOGGER_ENABLE
219 xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
220 #endif //KEYLOGGER_ENABLE
224 if (record->event.pressed) {
225 set_single_persistent_default_layer(_QWERTY);
230 if (record->event.pressed) {
231 set_single_persistent_default_layer(_COLEMAK);
236 if (record->event.pressed) {
237 set_single_persistent_default_layer(_DVORAK);
242 if (record->event.pressed) {
243 set_single_persistent_default_layer(_WORKMAN);
249 case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
250 if (!record->event.pressed) {
251 send_string_with_delay_P(PSTR("make " QMK_KEYBOARD ":" QMK_KEYMAP
252 #if (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
254 #elif defined(BOOTLOADER_HALFKAY)
256 #elif defined(BOOTLOADER_CATERINA)
258 #endif // bootloader options
259 SS_TAP(X_ENTER)), 10);
264 case EPRM: // Resets EEPROM
265 if (record->event.pressed) {
267 default_layer_set(1UL<<eeconfig_read_default_layer());
268 layer_state_set(layer_state);
272 case VRSN: // Prints firmware version
273 if (record->event.pressed) {
274 send_string_with_delay_P(PSTR(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE), MACRO_TIMER);
279 /* Code has been depreciated
280 case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
281 if (!record->event.pressed) {
282 clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
283 send_string(decoy_secret[keycode - KC_SECRET_1]);
289 // These are a serious of gaming macros.
290 // Only enables for the viterbi, basically,
291 // to save on firmware space, since it's limited.
292 #ifdef MACROS_ENABLED
293 case KC_OVERWATCH: // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
294 if (record->event.pressed) { userspace_config.is_overwatch ^= 1; eeprom_update_byte(EECONFIG_USERSPACE, userspace_config.raw); }
295 #ifdef RGBLIGHT_ENABLE
296 userspace_config.is_overwatch ? rgblight_mode_noeeprom(17) : rgblight_mode_noeeprom(18);
297 #endif //RGBLIGHT_ENABLE
300 return send_game_macro("Salt, salt, salt...", record, false);
302 return send_game_macro("Please sir, can I have some more salt?!", record, false);
304 return send_game_macro("Your salt only makes me harder, and even more aggressive!", record, false);
306 return send_game_macro("Good game, everyone!", record, false);
308 return send_game_macro("Good luck, have fun!!!", record, false);
310 return send_game_macro("Left click to win!", record, false);
312 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);
314 return send_game_macro("That was positively riveting!", record, false);
316 send_game_macro("That aim is absolutely amazing. It's almost like you're a machine!", record, true);
317 return send_game_macro("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!", record, false);
319 return send_game_macro("OMG!!! C9!!!", record, false);
321 return send_game_macro("That was a fantastic game, though it was a bit easy. Try harder next time!", record, false);
322 #endif // MACROS_ENABLED
325 case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
326 #ifdef TAP_DANCE_ENABLE
327 if (record->event.pressed) {
329 for (dtime = 0; dtime < 4; dtime++) {
330 diablo_key_time[dtime] = diablo_times[0];
333 #endif // TAP_DANCE_ENABLE
337 case KC_CCCV: // One key copy/paste
338 if(record->event.pressed){
339 copy_paste_timer = timer_read();
341 if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy
342 register_code(KC_LCTL);
344 unregister_code(KC_LCTL);
346 PLAY_SONG(tone_copy);
348 } else { // Tap, paste
349 register_code(KC_LCTL);
351 unregister_code(KC_LCTL);
353 PLAY_SONG(tone_paste);
359 #ifdef UNICODE_ENABLE
360 case UC_FLIP: // (╯°□°)╯ ︵ ┻━┻
361 if (record->event.pressed) {
362 register_code(KC_RSFT);
364 unregister_code(KC_RSFT);
365 process_unicode((0x256F | QK_UNICODE), record); // Arm
366 process_unicode((0x00B0 | QK_UNICODE), record); // Eye
367 process_unicode((0x25A1 | QK_UNICODE), record); // Mouth
368 process_unicode((0x00B0 | QK_UNICODE), record); // Eye
369 register_code(KC_RSFT);
371 unregister_code(KC_RSFT);
372 process_unicode((0x256F | QK_UNICODE), record); // Arm
374 process_unicode((0x0361 | QK_UNICODE), record); // Flippy
376 process_unicode((0x253B | QK_UNICODE), record); // Table
377 process_unicode((0x2501 | QK_UNICODE), record); // Table
378 process_unicode((0x253B | QK_UNICODE), record); // Table
382 #endif // UNICODE_ENABLE
385 return process_record_keymap(keycode, record) &&
386 #ifdef RGBLIGHT_ENABLE
387 process_record_user_rgb(keycode, record) &&
388 #endif // RGBLIGHT_ENABLE
389 process_record_secrets(keycode, record);
394 // Runs state check and changes underglow color and animation
395 // on layer change, no matter where the change was initiated
396 // Then runs keymap's layer change check
397 uint32_t layer_state_set_user(uint32_t state) {
398 state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
399 #ifdef RGBLIGHT_ENABLE
400 state = layer_state_set_rgb(state);
401 #endif // RGBLIGHT_ENABLE
402 return layer_state_set_keymap (state);
406 uint32_t default_layer_state_set_kb(uint32_t state) {
407 return default_layer_state_set_keymap (state);
411 // Any custom LED code goes here.
412 // So far, I only have keyboard specific code,
413 // So nothing goes here.
414 void led_set_user(uint8_t usb_led) {
415 led_set_keymap(usb_led);