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 clicky_enable = userspace_config.clicky_enable;
140 #ifdef BOOTLOADER_CATERINA
149 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
150 set_unicode_input_mode(UC_WINC);
151 #endif //UNICODE_ENABLE
152 matrix_init_keymap();
155 void startup_user (void) {
156 #ifdef RGBLIGHT_ENABLE
158 #endif //RGBLIGHT_ENABLE
162 void shutdown_user (void) {
163 #ifdef RGBLIGHT_ENABLE
164 rgblight_enable_noeeprom();
165 rgblight_mode_noeeprom(1);
166 rgblight_setrgb_red();
167 #endif // RGBLIGHT_ENABLE
168 #ifdef RGB_MATRIX_ENABLE
170 for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
172 if (led.matrix_co.raw < 0xFF) {
173 rgb_matrix_set_color( i, 0xFF, 0x00, 0x00 );
176 #endif //RGB_MATRIX_ENABLE
180 void suspend_power_down_user(void)
182 suspend_power_down_keymap();
185 void suspend_wakeup_init_user(void)
187 suspend_wakeup_init_keymap();
188 #ifdef KEYBOARD_ergodox_ez
194 // No global matrix scan code, so just run keymap's matrix
196 void matrix_scan_user(void) {
197 static bool has_ran_yet;
203 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
204 run_diablo_macro_check();
205 #endif // TAP_DANCE_ENABLE
207 #ifdef RGBLIGHT_ENABLE
209 #endif // RGBLIGHT_ENABLE
211 matrix_scan_keymap();
217 // Defines actions tor my global custom keycodes. Defined in drashna.h file
218 // Then runs the _keymap's record handier if not processed here
219 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
221 // If console is enabled, it will print the matrix position and status of each key pressed
222 #ifdef KEYLOGGER_ENABLE
223 xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
224 #endif //KEYLOGGER_ENABLE
228 if (record->event.pressed) {
229 set_single_persistent_default_layer(_QWERTY);
234 if (record->event.pressed) {
235 set_single_persistent_default_layer(_COLEMAK);
240 if (record->event.pressed) {
241 set_single_persistent_default_layer(_DVORAK);
246 if (record->event.pressed) {
247 set_single_persistent_default_layer(_WORKMAN);
253 case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
254 if (!record->event.pressed) {
255 send_string_with_delay_P(PSTR("make " QMK_KEYBOARD ":" QMK_KEYMAP
256 #if (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
258 #elif defined(BOOTLOADER_HALFKAY)
260 #elif defined(BOOTLOADER_CATERINA)
262 #endif // bootloader options
263 SS_TAP(X_ENTER)), 10);
268 case EPRM: // Resets EEPROM
269 if (record->event.pressed) {
271 default_layer_set(1UL<<eeconfig_read_default_layer());
272 layer_state_set(layer_state);
276 case VRSN: // Prints firmware version
277 if (record->event.pressed) {
278 send_string_with_delay_P(PSTR(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE), MACRO_TIMER);
283 /* Code has been depreciated
284 case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
285 if (!record->event.pressed) {
286 clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
287 send_string(decoy_secret[keycode - KC_SECRET_1]);
293 // These are a serious of gaming macros.
294 // Only enables for the viterbi, basically,
295 // to save on firmware space, since it's limited.
296 #ifdef MACROS_ENABLED
297 case KC_OVERWATCH: // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
298 if (record->event.pressed) { userspace_config.is_overwatch ^= 1; eeprom_update_byte(EECONFIG_USERSPACE, userspace_config.raw); }
299 #ifdef RGBLIGHT_ENABLE
300 userspace_config.is_overwatch ? rgblight_mode_noeeprom(17) : rgblight_mode_noeeprom(18);
301 #endif //RGBLIGHT_ENABLE
304 return send_game_macro("Salt, salt, salt...", record, false);
306 return send_game_macro("Please sir, can I have some more salt?!", record, false);
308 return send_game_macro("Your salt only makes me harder, and even more aggressive!", record, false);
310 return send_game_macro("Good game, everyone!", record, false);
312 return send_game_macro("Good luck, have fun!!!", record, false);
314 return send_game_macro("Left click to win!", record, false);
316 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);
318 return send_game_macro("That was positively riveting!", record, false);
320 send_game_macro("That aim is absolutely amazing. It's almost like you're a machine!", record, true);
321 return send_game_macro("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!", record, false);
323 return send_game_macro("OMG!!! C9!!!", record, false);
325 return send_game_macro("That was a fantastic game, though it was a bit easy. Try harder next time!", record, false);
326 #endif // MACROS_ENABLED
329 case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
330 #ifdef TAP_DANCE_ENABLE
331 if (record->event.pressed) {
333 for (dtime = 0; dtime < 4; dtime++) {
334 diablo_key_time[dtime] = diablo_times[0];
337 #endif // TAP_DANCE_ENABLE
343 userspace_config.clicky_enable = clicky_enable;
344 eeprom_update_byte(EECONFIG_USERSPACE, userspace_config.raw);
347 #ifdef UNICODE_ENABLE
348 case UC_FLIP: // (╯°□°)╯ ︵ ┻━┻
349 if (record->event.pressed) {
350 register_code(KC_RSFT);
352 unregister_code(KC_RSFT);
353 process_unicode((0x256F | QK_UNICODE), record); // Arm
354 process_unicode((0x00B0 | QK_UNICODE), record); // Eye
355 process_unicode((0x25A1 | QK_UNICODE), record); // Mouth
356 process_unicode((0x00B0 | QK_UNICODE), record); // Eye
357 register_code(KC_RSFT);
359 unregister_code(KC_RSFT);
360 process_unicode((0x256F | QK_UNICODE), record); // Arm
362 process_unicode((0x0361 | QK_UNICODE), record); // Flippy
364 process_unicode((0x253B | QK_UNICODE), record); // Table
365 process_unicode((0x2501 | QK_UNICODE), record); // Table
366 process_unicode((0x253B | QK_UNICODE), record); // Table
370 #endif // UNICODE_ENABLE
373 return process_record_keymap(keycode, record) &&
374 #ifdef RGBLIGHT_ENABLE
375 process_record_user_rgb(keycode, record) &&
376 #endif // RGBLIGHT_ENABLE
377 process_record_secrets(keycode, record);
382 // Runs state check and changes underglow color and animation
383 // on layer change, no matter where the change was initiated
384 // Then runs keymap's layer change check
385 uint32_t layer_state_set_user(uint32_t state) {
386 state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
387 #ifdef RGBLIGHT_ENABLE
388 state = layer_state_set_rgb(state);
389 #endif // RGBLIGHT_ENABLE
390 return layer_state_set_keymap (state);
394 uint32_t default_layer_state_set_kb(uint32_t state) {
395 return default_layer_state_set_keymap (state);
399 // Any custom LED code goes here.
400 // So far, I only have keyboard specific code,
401 // So nothing goes here.
402 void led_set_user(uint8_t usb_led) {
403 led_set_keymap(usb_led);