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;
23 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
24 #define DRASHNA_UNICODE_MODE UC_WIN
26 // set to 2 for UC_WIN, set to 4 for UC_WINC
27 #define DRASHNA_UNICODE_MODE 2
30 uint16_t copy_paste_timer;
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 if (userspace_config.is_overwatch) {
47 send_string_with_delay(str, MACRO_TIMER);
51 if (override) wait_ms(3000);
55 bool mod_key_press_timer (uint16_t code, uint16_t mod_code, bool pressed) {
56 static uint16_t this_timer;
58 this_timer= timer_read();
60 if (timer_elapsed(this_timer) < TAPPING_TERM){
62 unregister_code(code);
64 register_code(mod_code);
66 unregister_code(code);
67 unregister_code(mod_code);
73 bool mod_key_press (uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
75 this_timer= timer_read();
77 if (timer_elapsed(this_timer) < TAPPING_TERM){
79 unregister_code(code);
81 register_code(mod_code);
83 unregister_code(code);
84 unregister_code(mod_code);
90 void bootmagic_lite(void) {
92 #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
93 wait_ms(DEBOUNCING_DELAY * 2);
94 #elif defined(DEBOUNCE) && DEBOUNCE > 0
95 wait_ms(DEBOUNCE * 2);
100 if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
105 // Add reconfigurable functions here, for keymap customization
106 // This allows for a global, userspace functions, and continued
107 // customization of the keymap. Use _keymap instead of _user
108 // functions in the keymaps
109 __attribute__ ((weak))
110 void matrix_init_keymap(void) {}
112 __attribute__ ((weak))
113 void startup_keymap(void) {}
115 __attribute__ ((weak))
116 void shutdown_keymap(void) {}
118 __attribute__ ((weak))
119 void suspend_power_down_keymap(void) {}
121 __attribute__ ((weak))
122 void suspend_wakeup_init_keymap(void) {}
124 __attribute__ ((weak))
125 void matrix_scan_keymap(void) {}
127 __attribute__ ((weak))
128 bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
132 __attribute__ ((weak))
133 bool process_record_secrets(uint16_t keycode, keyrecord_t *record) {
138 __attribute__ ((weak))
139 uint32_t layer_state_set_keymap (uint32_t state) {
143 __attribute__ ((weak))
144 uint32_t default_layer_state_set_keymap (uint32_t state) {
148 __attribute__ ((weak))
149 void led_set_keymap(uint8_t usb_led) {}
151 __attribute__ ((weak))
152 void eeconfig_init_keymap(void) {}
154 // Call user matrix init, set default RGB colors and then
155 // call the keymap's init function
156 void matrix_init_user(void) {
157 #if !defined(BOOTMAGIC_LITE) && !defined(BOOTMAGIC_ENABLE)
161 userspace_config.raw = eeconfig_read_user();
163 #ifdef BOOTLOADER_CATERINA
171 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
172 set_unicode_input_mode(DRASHNA_UNICODE_MODE);
173 get_unicode_input_mode();
174 #endif //UNICODE_ENABLE
175 matrix_init_keymap();
178 void startup_user (void) {
179 #ifdef RGBLIGHT_ENABLE
181 #endif //RGBLIGHT_ENABLE
185 void shutdown_user (void) {
186 #ifdef RGBLIGHT_ENABLE
187 rgblight_enable_noeeprom();
188 rgblight_mode_noeeprom(1);
189 rgblight_setrgb_red();
190 #endif // RGBLIGHT_ENABLE
191 #ifdef RGB_MATRIX_ENABLE
193 for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
195 if (led.matrix_co.raw < 0xFF) {
196 rgb_matrix_set_color( i, 0xFF, 0x00, 0x00 );
199 #endif //RGB_MATRIX_ENABLE
203 void suspend_power_down_user(void) {
204 suspend_power_down_keymap();
207 void suspend_wakeup_init_user(void) {
208 suspend_wakeup_init_keymap();
212 // No global matrix scan code, so just run keymap's matrix
214 void matrix_scan_user(void) {
215 static bool has_ran_yet;
221 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
222 run_diablo_macro_check();
223 #endif // TAP_DANCE_ENABLE
225 #ifdef RGBLIGHT_ENABLE
227 #endif // RGBLIGHT_ENABLE
229 matrix_scan_keymap();
235 // Defines actions tor my global custom keycodes. Defined in drashna.h file
236 // Then runs the _keymap's record handier if not processed here
237 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
239 // If console is enabled, it will print the matrix position and status of each key pressed
240 #ifdef KEYLOGGER_ENABLE
241 #if defined(KEYBOARD_ergodox_ez) || defined(KEYBOARD_iris_rev2)
242 xprintf("KL: col: %u, row: %u, pressed: %u\n", record->event.key.row, record->event.key.col, record->event.pressed);
244 xprintf("KL: col: %u, row: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
246 #endif //KEYLOGGER_ENABLE
250 if (record->event.pressed) {
251 set_single_persistent_default_layer(_QWERTY);
255 if (record->event.pressed) {
256 set_single_persistent_default_layer(_COLEMAK);
260 if (record->event.pressed) {
261 set_single_persistent_default_layer(_DVORAK);
265 if (record->event.pressed) {
266 set_single_persistent_default_layer(_WORKMAN);
271 case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
272 if (!record->event.pressed) {
273 uint8_t temp_mod = get_mods();
274 uint8_t temp_osm = get_oneshot_mods();
275 clear_mods(); clear_oneshot_mods();
276 send_string_with_delay_P(PSTR("make " QMK_KEYBOARD ":" QMK_KEYMAP), 10);
277 if (temp_mod & MODS_SHIFT_MASK || temp_osm & MODS_SHIFT_MASK) {
279 send_string_with_delay_P(PSTR(":dfu-util"), 10);
280 #elif defined(BOOTLOADER_DFU)
281 send_string_with_delay_P(PSTR(":dfu"), 10);
282 #elif defined(BOOTLOADER_HALFKAY)
283 send_string_with_delay_P(PSTR(":teensy"), 10);
284 #elif defined(BOOTLOADER_CATERINA)
285 send_string_with_delay_P(PSTR(":avrdude"), 10);
286 #endif // bootloader options
288 #if defined(KEYBOARD_viterbi)
289 send_string_with_delay_P(PSTR(":dfu"), 10);
291 if (temp_mod & MODS_CTRL_MASK || temp_osm & MODS_CTRL_MASK) { send_string_with_delay_P(PSTR(" -j8 --output-sync"), 10); }
292 send_string_with_delay_P(PSTR(SS_TAP(X_ENTER)), 10);
297 case EPRM: // Resets EEPROM
298 if (record->event.pressed) {
302 case VRSN: // Prints firmware version
303 if (record->event.pressed) {
304 send_string_with_delay_P(PSTR(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE), MACRO_TIMER);
308 // These are a serious of gaming macros.
309 // Only enables for the viterbi, basically,
310 // to save on firmware space, since it's limited.
311 #ifdef MACROS_ENABLED
312 case KC_OVERWATCH: // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
313 if (record->event.pressed) { userspace_config.is_overwatch ^= 1; eeconfig_update_user(userspace_config.raw); }
314 #ifdef RGBLIGHT_ENABLE
315 userspace_config.is_overwatch ? rgblight_mode_noeeprom(17) : rgblight_mode_noeeprom(18);
316 #endif //RGBLIGHT_ENABLE
319 return send_game_macro("Salt, salt, salt...", record, false);
321 return send_game_macro("Please sir, can I have some more salt?!", record, false);
323 return send_game_macro("Your salt only makes me harder, and even more aggressive!", record, false);
325 return send_game_macro("Good game, everyone!", record, false);
327 return send_game_macro("Good luck, have fun!!!", record, false);
329 return send_game_macro("Left click to win!", record, false);
331 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);
333 return send_game_macro("That was positively riveting!", record, false);
335 send_game_macro("That aim is absolutely amazing. It's almost like you're a machine!", record, true);
336 return send_game_macro("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!", record, false);
338 return send_game_macro("OMG!!! C9!!!", record, false);
340 return send_game_macro("That was a fantastic game, though it was a bit easy. Try harder next time!", record, false);
341 #endif // MACROS_ENABLED
344 case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
345 #ifdef TAP_DANCE_ENABLE
346 if (record->event.pressed) {
348 for (dtime = 0; dtime < 4; dtime++) {
349 diablo_key_time[dtime] = diablo_times[0];
352 #endif // TAP_DANCE_ENABLE
356 case KC_CCCV: // One key copy/paste
357 if(record->event.pressed){
358 copy_paste_timer = timer_read();
360 if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy
361 register_code(KC_LCTL);
363 unregister_code(KC_LCTL);
364 } else { // Tap, paste
365 register_code(KC_LCTL);
367 unregister_code(KC_LCTL);
371 #ifdef UNICODE_ENABLE
372 case UC_FLIP: // (ノಠ痊ಠ)ノ彡┻━┻
373 if (record->event.pressed) {
374 send_unicode_hex_string("0028 30CE 0CA0 75CA 0CA0 0029 30CE 5F61 253B 2501 253B");
377 case UC_TABL: // ┬─┬ノ( º _ ºノ)
378 if (record->event.pressed) {
379 send_unicode_hex_string("252C 2500 252C 30CE 0028 0020 00BA 0020 005F 0020 00BA 30CE 0029");
382 case UC_SHRG: // ¯\_(ツ)_/¯
383 if (record->event.pressed) {
384 send_unicode_hex_string("00AF 005C 005F 0028 30C4 0029 005F 002F 00AF");
388 if (record->event.pressed) {
389 send_unicode_hex_string("0CA0 005F 0CA0");
394 return process_record_keymap(keycode, record) &&
395 #ifdef RGBLIGHT_ENABLE
396 process_record_user_rgb(keycode, record) &&
397 #endif // RGBLIGHT_ENABLE
398 process_record_secrets(keycode, record);
403 // Runs state check and changes underglow color and animation
404 // on layer change, no matter where the change was initiated
405 // Then runs keymap's layer change check
406 uint32_t layer_state_set_user(uint32_t state) {
407 state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
408 #ifdef RGBLIGHT_ENABLE
409 state = layer_state_set_rgb(state);
410 #endif // RGBLIGHT_ENABLE
411 return layer_state_set_keymap (state);
415 uint32_t default_layer_state_set_user(uint32_t state) {
416 return default_layer_state_set_keymap(state);
420 // Any custom LED code goes here.
421 // So far, I only have keyboard specific code,
422 // So nothing goes here.
423 void led_set_user(uint8_t usb_led) {
424 led_set_keymap(usb_led);
427 void eeconfig_init_user(void) {
428 userspace_config.raw = 0;
429 userspace_config.rgb_layer_change = true;
430 eeconfig_update_user(userspace_config.raw);
431 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
432 set_unicode_input_mode(DRASHNA_UNICODE_MODE);
433 get_unicode_input_mode();
435 eeprom_update_byte(EECONFIG_UNICODEMODE, DRASHNA_UNICODE_MODE);