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 #if (__has_include("secrets.h") && !defined(NO_SECRETS))
24 // `PROGMEM const char secret[][x]` may work better, but it takes up more space in the firmware
25 // And I'm not familiar enough to know which is better or why...
26 PROGMEM const char secret[][64] = {
36 float tone_copy[][2] = SONG(SCROLL_LOCK_ON_SOUND);
37 float tone_paste[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
40 static uint16_t copy_paste_timer;
41 #ifdef RGBLIGHT_ENABLE
42 bool rgb_layer_change = true;
45 userspace_config_t userspace_config;
48 void tap(uint16_t keycode){ register_code(keycode); unregister_code(keycode); };
50 #ifdef RGBLIGHT_ENABLE
51 void rgblight_sethsv_default_helper(uint8_t index) {
52 uint8_t default_layer = eeconfig_read_default_layer();
53 if (default_layer & (1UL << _COLEMAK)) {
54 rgblight_sethsv_at(300, 255, 255, index);
55 rgblight_sethsv_at(300, 255, 255, index);
57 else if (default_layer & (1UL << _DVORAK)) {
58 rgblight_sethsv_at(120, 255, 255, index);
59 rgblight_sethsv_at(120, 255, 255, index);
61 else if (default_layer & (1UL << _WORKMAN)) {
62 rgblight_sethsv_at(43, 255, 255, index);
63 rgblight_sethsv_at(43, 255, 255, index);
66 rgblight_sethsv_at(180, 255, 255, index);
67 rgblight_sethsv_at(180, 255, 255, index);
70 #endif // RGBLIGHT_ENABLE
73 // ========================================= TAP DANCE =========================================
74 #ifdef TAP_DANCE_ENABLE
75 //define diablo macro timer variables
76 static uint16_t diablo_timer[4];
77 static uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 };
78 static uint8_t diablo_key_time[4];
80 // has the correct number of seconds elapsed (as defined by diablo_times)
81 bool check_dtimer(uint8_t dtimer) { return (timer_elapsed(diablo_timer[dtimer]) < (diablo_key_time[dtimer] * 1000)) ? false : true; };
83 // Cycle through the times for the macro, starting at 0, for disabled.
84 // Max of six values, so don't exceed
85 void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data, uint8_t diablo_key) {
86 if (state->count >= 7) {
87 diablo_key_time[diablo_key] = diablo_times[0];
88 reset_tap_dance(state);
90 diablo_key_time[diablo_key] = diablo_times[state->count - 1];
94 // Would rather have one function for all of this, but no idea how to do that...
95 void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 0); }
96 void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 1); }
97 void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 2); }
98 void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 3); }
100 //Tap Dance Definitions
101 qk_tap_dance_action_t tap_dance_actions[] = {
102 // tap once to disable, and more to enable timed micros
103 [TD_D3_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1),
104 [TD_D3_2] = ACTION_TAP_DANCE_FN(diablo_tapdance2),
105 [TD_D3_3] = ACTION_TAP_DANCE_FN(diablo_tapdance3),
106 [TD_D3_4] = ACTION_TAP_DANCE_FN(diablo_tapdance4),
109 // Sends the key press to system, but only if on the Diablo layer
110 void send_diablo_keystroke(uint8_t diablo_key) {
111 if (biton32(layer_state) == _DIABLO) {
112 switch (diablo_key) {
125 // Checks each of the 4 timers/keys to see if enough time has elapsed
126 // Runs the "send string" command if enough time has passed, and resets the timer.
127 void run_diablo_macro_check(void) {
129 for (dtime = 0; dtime < 4; dtime++) {
130 if (check_dtimer(dtime) && diablo_key_time[dtime]) {
131 diablo_timer[dtime] = timer_read();
132 send_diablo_keystroke(dtime);
136 #endif // TAP_DANCE_ENABLE
139 // Add reconfigurable functions here, for keymap customization
140 // This allows for a global, userspace functions, and continued
141 // customization of the keymap. Use _keymap instead of _user
142 // functions in the keymaps
143 __attribute__ ((weak))
144 void matrix_init_keymap(void) {}
146 __attribute__ ((weak))
147 void matrix_scan_keymap(void) {}
149 __attribute__ ((weak))
150 bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
154 __attribute__ ((weak))
155 uint32_t layer_state_set_keymap (uint32_t state) {
159 __attribute__ ((weak))
160 void led_set_keymap(uint8_t usb_led) {}
163 // Call user matrix init, set default RGB colors and then
164 // call the keymap's init function
165 void matrix_init_user(void) {
166 uint8_t default_layer = eeconfig_read_default_layer();
168 #ifdef RGBLIGHT_ENABLE
170 #endif // RGBLIGHT_ENABLE
172 if (default_layer & (1UL << _COLEMAK)) {
173 #ifdef RGBLIGHT_ENABLE
174 rgblight_sethsv_magenta();
175 #endif // RGBLIGHT_ENABLE
176 } else if (default_layer & (1UL << _DVORAK)) {
177 #ifdef RGBLIGHT_ENABLE
178 rgblight_sethsv_green();
179 #endif // RGBLIGHT_ENABLE
180 } else if (default_layer & (1UL << _WORKMAN)) {
181 #ifdef RGBLIGHT_ENABLE
182 rgblight_sethsv_goldenrod();
183 #endif // RGBLIGHT_ENABLE
185 #ifdef RGBLIGHT_ENABLE
186 rgblight_sethsv_teal();
187 #endif // RGBLIGHT_ENABLE
190 userspace_config.raw = eeprom_read_byte(EECONFIG_USERSPACE);
191 clicky_enable = userspace_config.clicky_enable;
193 #if ( defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) )
194 set_unicode_input_mode(UC_WINC);
195 #endif //UNICODE_ENABLE
197 matrix_init_keymap();
199 // No global matrix scan code, so just run keymap's matrix
201 void matrix_scan_user(void) {
203 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
204 run_diablo_macro_check();
205 #endif // TAP_DANCE_ENABLE
207 matrix_scan_keymap();
211 // This block is for all of the gaming macros, as they were all doing
212 // the same thing, but with differring text sent.
213 bool send_game_macro(const char *str, keyrecord_t *record, bool override) {
214 if (!record->event.pressed || override) {
216 tap(userspace_config.is_overwatch ? KC_BSPC : KC_ENTER);
222 if (override) wait_ms(3000);
227 // Defines actions tor my global custom keycodes. Defined in drashna.h file
228 // Then runs the _keymap's record handier if not processed here
229 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
231 // If console is enabled, it will print the matrix position and status of each key pressed
232 #ifdef CONSOLE_ENABLE
233 xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
234 #endif //CONSOLE_ENABLE
239 if (record->event.pressed) {
240 set_single_persistent_default_layer(_QWERTY);
245 if (record->event.pressed) {
246 set_single_persistent_default_layer(_COLEMAK);
251 if (record->event.pressed) {
252 set_single_persistent_default_layer(_DVORAK);
257 if (record->event.pressed) {
258 set_single_persistent_default_layer(_WORKMAN);
264 case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
265 if (!record->event.pressed) {
266 SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP
267 #if (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
269 #elif defined(BOOTLOADER_HALFKAY)
271 #elif defined(BOOTLOADER_CATERINA)
273 #endif // bootloader options
280 case KC_RESET: // Custom RESET code that sets RGBLights to RED
281 if (!record->event.pressed) {
282 #ifdef RGBLIGHT_ENABLE
285 rgblight_setrgb_red();
286 #endif // RGBLIGHT_ENABLE
293 case EPRM: // Resets EEPROM
294 if (record->event.pressed) {
299 case VRSN: // Prints firmware version
300 if (record->event.pressed) {
301 SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE);
307 case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
308 if (!record->event.pressed) {
309 clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
310 send_string_P(secret[keycode - KC_SECRET_1]);
316 // These are a serious of gaming macros.
317 // Only enables for the viterbi, basically,
318 // to save on firmware space, since it's limited.
319 #if !(defined(KEYBOARD_orthodox_rev1) || defined(KEYBOARD_orthodox_rev3) || defined(KEYBOARD_ergodox_ez) || defined(KEYBOARD_iris_rev2))
320 case KC_OVERWATCH: // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
321 if (record->event.pressed) { userspace_config.is_overwatch ^= 1; eeprom_update_byte(EECONFIG_USERSPACE, userspace_config.raw); }
322 #ifdef RGBLIGHT_ENABLE
323 userspace_config.is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
324 #endif //RGBLIGHT_ENABLE
327 return send_game_macro("Salt, salt, salt...", record, false);
329 return send_game_macro("Please sir, can I have some more salt?!", record, false);
331 return send_game_macro("Your salt only makes me harder, and even more aggressive!", record, false);
333 return send_game_macro("Good game, everyone!", record, false);
335 return send_game_macro("Good luck, have fun!!!", record, false);
337 return send_game_macro("Left click to win!", record, false);
339 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);
341 return send_game_macro("That was positively riveting!", record, false);
343 send_game_macro("That aim is absolutely amazing. It's almost like you're a machine!", record, true);
344 return send_game_macro("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!", record, false);
346 return send_game_macro("OMG!!! C9!!!", record, false);
348 return send_game_macro("That was a fantastic game, though it was a bit easy. Try harder next time!", record, false);
349 #endif // !(defined(KEYBOARD_orthodox_rev1) || defined(KEYBOARD_orthodox_rev3) || defined(KEYBOARD_ergodox_ez))
352 #ifdef TAP_DANCE_ENABLE
353 case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
354 if (record->event.pressed) {
356 for (dtime = 0; dtime < 4; dtime++) {
357 diablo_key_time[dtime] = diablo_times[0];
361 #endif // TAP_DANCE_ENABLE
364 case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal
365 #ifdef RGBLIGHT_ENABLE
366 if (record->event.pressed) {
367 rgb_layer_change = !rgb_layer_change;
368 if (rgb_layer_change) {
369 layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better)
372 #endif // RGBLIGHT_ENABLE
374 #ifdef RGBLIGHT_ENABLE
375 case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
376 if (record->event.pressed) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
377 rgb_layer_change = false;
380 #endif // RGBLIGHT_ENABLE
383 case KC_CCCV: // One key copy/paste
384 if(record->event.pressed){
385 copy_paste_timer = timer_read();
387 if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy
388 register_code(KC_LCTL);
390 unregister_code(KC_LCTL);
392 PLAY_SONG(tone_copy);
394 } else { // Tap, paste
395 register_code(KC_LCTL);
397 unregister_code(KC_LCTL);
399 PLAY_SONG(tone_paste);
406 userspace_config.clicky_enable = clicky_enable;
407 eeprom_update_byte(EECONFIG_USERSPACE, userspace_config.raw);
409 #ifdef UNICODE_ENABLE
410 case UC_FLIP: // (╯°□°)╯ ︵ ┻━┻
411 if (record->event.pressed) {
412 register_code(KC_RSFT);
414 unregister_code(KC_RSFT);
415 process_unicode((0x256F | QK_UNICODE), record); // Arm
416 process_unicode((0x00B0 | QK_UNICODE), record); // Eye
417 process_unicode((0x25A1 | QK_UNICODE), record); // Mouth
418 process_unicode((0x00B0 | QK_UNICODE), record); // Eye
419 register_code(KC_RSFT);
421 unregister_code(KC_RSFT);
422 process_unicode((0x256F | QK_UNICODE), record); // Arm
424 process_unicode((0x0361 | QK_UNICODE), record); // Flippy
426 process_unicode((0x253B | QK_UNICODE), record); // Table
427 process_unicode((0x2501 | QK_UNICODE), record); // Table
428 process_unicode((0x253B | QK_UNICODE), record); // Table
432 #endif // UNICODE_ENABLE
435 return process_record_keymap(keycode, record);
440 // Runs state check and changes underglow color and animation
441 // on layer change, no matter where the change was initiated
442 // Then runs keymap's layer change check
443 uint32_t layer_state_set_user(uint32_t state) {
444 uint8_t default_layer = eeconfig_read_default_layer();
445 state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
447 switch (biton32(state)) {
449 #ifdef RGBLIGHT_ENABLE
450 if (rgb_layer_change) {
451 rgblight_sethsv_blue();
454 #endif // RGBLIGHT_ENABLE
457 #ifdef RGBLIGHT_ENABLE
458 if (rgb_layer_change) {
459 rgblight_sethsv_blue();
462 #endif // RGBLIGHT_ENABLE
465 #ifdef RGBLIGHT_ENABLE
466 if (rgb_layer_change) {
467 rgblight_sethsv_yellow();
470 #endif // RGBLIGHT_ENABLE
473 #ifdef RGBLIGHT_ENABLE
474 if (rgb_layer_change) {
475 rgblight_sethsv_orange();
476 userspace_config.is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
478 #endif // RGBLIGHT_ENABLE
481 #ifdef RGBLIGHT_ENABLE
482 if (rgb_layer_change) {
483 rgblight_sethsv_chartreuse();
486 #endif // RGBLIGHT_ENABLE
489 #ifdef RGBLIGHT_ENABLE
490 if (rgb_layer_change) {
491 rgblight_sethsv_orange();
494 #endif // RGBLIGHT_ENABLE
497 #ifdef RGBLIGHT_ENABLE
498 if (rgb_layer_change) {
499 rgblight_sethsv_red();
502 #endif // RGBLIGHT_ENABLE
505 #ifdef RGBLIGHT_ENABLE
506 if (rgb_layer_change) {
507 rgblight_sethsv_yellow();
510 #endif // RGBLIGHT_ENABLE
513 #ifdef RGBLIGHT_ENABLE
514 if (rgb_layer_change) {
515 rgblight_sethsv_orange();
518 #endif // RGBLIGHT_ENABLE
521 #ifdef RGBLIGHT_ENABLE
522 if (rgb_layer_change) {
523 rgblight_sethsv_red();
526 #endif // RGBLIGHT_ENABLE
529 #ifdef RGBLIGHT_ENABLE
530 if (rgb_layer_change) {
531 rgblight_sethsv_green();
534 #endif // RGBLIGHT_ENABLE
536 default: // for any other layers, or the default layer
537 if (default_layer & (1UL << _COLEMAK)) {
538 #ifdef RGBLIGHT_ENABLE
539 if (rgb_layer_change) { rgblight_sethsv_magenta(); }
540 #endif // RGBLIGHT_ENABLE
542 else if (default_layer & (1UL << _DVORAK)) {
543 #ifdef RGBLIGHT_ENABLE
544 if (rgb_layer_change) { rgblight_sethsv_green(); }
545 #endif // RGBLIGHT_ENABLE
547 else if (default_layer & (1UL << _WORKMAN)) {
548 #ifdef RGBLIGHT_ENABLE
549 if (rgb_layer_change) { rgblight_sethsv_goldenrod(); }
550 #endif // RGBLIGHT_ENABLE
553 #ifdef RGBLIGHT_ENABLE
554 if (rgb_layer_change) { rgblight_sethsv_teal(); }
555 #endif // RGBLIGHT_ENABLE
557 if (biton32(state) == _MODS) { // If the non-OSM layer is enabled, then breathe
558 #ifdef RGBLIGHT_ENABLE
559 if (rgb_layer_change) { rgblight_mode(2); }
560 #endif // RGBLIGHT_ENABLE
561 } else { // otherwise, stay solid
562 #ifdef RGBLIGHT_ENABLE
563 if (rgb_layer_change) { rgblight_mode(1); }
564 #endif // RGBLIGHT_ENABLE
568 return layer_state_set_keymap (state);
572 // Any custom LED code goes here.
573 // So far, I only have keyboard specific code,
574 // So nothing goes here.
575 void led_set_user(uint8_t usb_led) {
576 led_set_keymap(usb_led);