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 #ifdef FAUXCLICKY_ENABLE
37 float fauxclicky_pressed_note[2] = MUSICAL_NOTE(_A6, 2); // (_D4, 0.25);
38 float fauxclicky_released_note[2] = MUSICAL_NOTE(_A6, 2); // (_C4, 0.125);
39 #else // FAUXCLICKY_ENABLE
40 float fauxclicky_pressed[][2] = SONG(S__NOTE(_A6)); // change to your tastes
41 float fauxclicky_released[][2] = SONG(S__NOTE(_A6)); // change to your tastes
42 #endif // FAUXCLICKY_ENABLE
44 float tone_copy[][2] = SONG(SCROLL_LOCK_ON_SOUND);
45 float tone_paste[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
48 bool faux_click_enabled = false;
49 bool is_overwatch = false;
50 static uint16_t copy_paste_timer;
51 #ifdef RGBLIGHT_ENABLE
52 bool rgb_layer_change = true;
55 #ifdef TAP_DANCE_ENABLE
56 //define diablo macro timer variables
57 static uint16_t diablo_timer[4];
58 static uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 };
59 static uint8_t diablo_key_time[4];
61 bool check_dtimer(uint8_t dtimer) {
62 // has the correct number of seconds elapsed (as defined by diablo_times)
63 return (timer_elapsed(diablo_timer[dtimer]) < (diablo_key_time[dtimer] * 1000)) ? false : true;
66 // Cycle through the times for the macro, starting at 0, for disabled.
67 // Max of six values, so don't exceed
68 void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data, uint8_t diablo_key) {
69 if (state->count >= 7) {
70 diablo_key_time[diablo_key] = diablo_times[0];
71 reset_tap_dance(state);
74 diablo_key_time[diablo_key] = diablo_times[state->count - 1];
78 // Would rather have one function for all of this, but no idea how to do that...
79 void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) {
80 diablo_tapdance_master(state, user_data, 0);
82 void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) {
83 diablo_tapdance_master(state, user_data, 1);
85 void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) {
86 diablo_tapdance_master(state, user_data, 2);
88 void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) {
89 diablo_tapdance_master(state, user_data, 3);
92 //Tap Dance Definitions
93 qk_tap_dance_action_t tap_dance_actions[] = {
94 // tap once to disable, and more to enable timed micros
95 [TD_D3_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1),
96 [TD_D3_2] = ACTION_TAP_DANCE_FN(diablo_tapdance2),
97 [TD_D3_3] = ACTION_TAP_DANCE_FN(diablo_tapdance3),
98 [TD_D3_4] = ACTION_TAP_DANCE_FN(diablo_tapdance4),
102 // Sends the key press to system, but only if on the Diablo layer
103 void send_diablo_keystroke(uint8_t diablo_key) {
104 if (biton32(layer_state) == _DIABLO) {
105 switch (diablo_key) {
122 // Checks each of the 4 timers/keys to see if enough time has elapsed
123 // Runs the "send string" command if enough time has passed, and resets the timer.
124 void run_diablo_macro_check(void) {
127 for (dtime = 0; dtime < 4; dtime++) {
128 if (check_dtimer(dtime) && diablo_key_time[dtime]) {
129 diablo_timer[dtime] = timer_read();
130 send_diablo_keystroke(dtime);
135 #endif // TAP_DANCE_ENABLE
138 // Add reconfigurable functions here, for keymap customization
139 // This allows for a global, userspace functions, and continued
140 // customization of the keymap. Use _keymap instead of _user
141 // functions in the keymaps
142 __attribute__ ((weak))
143 void matrix_init_keymap(void) {}
145 __attribute__ ((weak))
146 void matrix_scan_keymap(void) {}
148 __attribute__ ((weak))
149 bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
153 __attribute__ ((weak))
154 uint32_t layer_state_set_keymap (uint32_t state) {
158 __attribute__ ((weak))
159 void led_set_keymap(uint8_t usb_led) {}
162 // Call user matrix init, set default RGB colors and then
163 // call the keymap's init function
164 void matrix_init_user(void) {
165 #ifdef RGBLIGHT_ENABLE
166 uint8_t default_layer = eeconfig_read_default_layer();
171 if (default_layer & (1UL << _COLEMAK)) {
172 rgblight_sethsv_magenta();
174 else if (default_layer & (1UL << _DVORAK)) {
175 rgblight_sethsv_green();
177 else if (default_layer & (1UL << _WORKMAN)) {
178 rgblight_sethsv_goldenrod();
181 rgblight_sethsv_teal();
186 rgblight_setrgb_red();
189 #endif // RGBLIGHT_ENABLE
191 #if ( defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) )
192 set_unicode_input_mode(UC_WINC);
193 #endif //UNICODE_ENABLE
195 matrix_init_keymap();
197 // No global matrix scan code, so just run keymap's matrix
199 void matrix_scan_user(void) {
200 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
201 run_diablo_macro_check();
202 #endif // TAP_DANCE_ENABLE
203 matrix_scan_keymap();
206 void tap(uint16_t keycode){
207 register_code(keycode);
208 unregister_code(keycode);
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(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);
265 if (record->event.pressed) {
267 update_tri_layer(_LOWER, _RAISE, _ADJUST);
271 update_tri_layer(_LOWER, _RAISE, _ADJUST);
276 if (record->event.pressed) {
278 update_tri_layer(_LOWER, _RAISE, _ADJUST);
282 update_tri_layer(_LOWER, _RAISE, _ADJUST);
287 if (record->event.pressed) {
297 case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
298 if (!record->event.pressed) {
299 SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP
300 #if (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
302 #elif defined(BOOTLOADER_HALFKAY)
304 #elif defined(BOOTLOADER_CATERINA)
306 #endif // bootloader options
313 case KC_RESET: // Custom RESET code that sets RGBLights to RED
314 if (!record->event.pressed) {
315 #ifdef RGBLIGHT_ENABLE
318 rgblight_setrgb_red();
319 #endif // RGBLIGHT_ENABLE
326 case EPRM: // Resets EEPROM
327 if (record->event.pressed) {
332 case VRSN: // Prints firmware version
333 if (record->event.pressed) {
334 SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE);
340 case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
341 if (!record->event.pressed) {
342 clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
343 send_string_P(secret[keycode - KC_SECRET_1]);
349 // These are a serious of gaming macros.
350 // Only enables for the viterbi, basically,
351 // to save on firmware space, since it's limited.
352 #if !(defined(KEYBOARD_orthodox_rev1) || defined(KEYBOARD_orthodox_rev3) || defined(KEYBOARD_ergodox_ez))
353 case KC_OVERWATCH: // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
354 if (record->event.pressed) { is_overwatch = !is_overwatch; }
355 #ifdef RGBLIGHT_ENABLE
356 is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
357 #endif //RGBLIGHT_ENABLE
360 return send_game_macro("Salt, salt, salt...", record, false);
362 return send_game_macro("Please sir, can I have some more salt?!", record, false);
364 return send_game_macro("Your salt only makes me harder, and even more aggressive!", record, false);
366 return send_game_macro("Good game, everyone!", record, false);
368 return send_game_macro("Good luck, have fun!!!", record, false);
370 return send_game_macro("Left click to win!", record, false);
372 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);
374 return send_game_macro("That was positively riveting!", record, false);
376 send_game_macro("That aim is absolutely amazing. It's almost like you're a machine!", record, true);
377 return send_game_macro("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!", record, false);
379 return send_game_macro("OMG!!! C9!!!", record, false);
381 return send_game_macro("That was a fantastic game, though it was a bit easy. Try harder next time!", record, false);
382 #endif // !(defined(KEYBOARD_orthodox_rev1) || defined(KEYBOARD_orthodox_rev3) || defined(KEYBOARD_ergodox_ez))
385 #ifdef TAP_DANCE_ENABLE
386 case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
387 if (record->event.pressed) {
389 for (dtime = 0; dtime < 4; dtime++) {
390 diablo_key_time[dtime] = diablo_times[0];
394 #endif // TAP_DANCE_ENABLE
397 case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal
398 #ifdef RGBLIGHT_ENABLE
399 if (record->event.pressed) {
400 rgb_layer_change = !rgb_layer_change;
401 if (rgb_layer_change) {
402 layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better)
405 #endif // RGBLIGHT_ENABLE
407 #ifdef RGBLIGHT_ENABLE
408 case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
409 if (record->event.pressed) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
410 rgb_layer_change = false;
413 #endif // RGBLIGHT_ENABLE
416 case KC_CCCV: // One key copy/paste
417 if(record->event.pressed){
418 copy_paste_timer = timer_read();
420 if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy
421 register_code(KC_LCTL);
423 unregister_code(KC_LCTL);
425 PLAY_SONG(tone_copy);
427 } else { // Tap, paste
428 register_code(KC_LCTL);
430 unregister_code(KC_LCTL);
432 PLAY_SONG(tone_paste);
439 #ifdef UNICODE_ENABLE
440 case UC_FLIP: // (╯°□°)╯ ︵ ┻━┻
441 if (record->event.pressed) {
442 register_code(KC_RSFT);
444 unregister_code(KC_RSFT);
445 process_unicode((0x256F | QK_UNICODE), record); // Arm
446 process_unicode((0x00B0 | QK_UNICODE), record); // Eye
447 process_unicode((0x25A1 | QK_UNICODE), record); // Mouth
448 process_unicode((0x00B0 | QK_UNICODE), record); // Eye
449 register_code(KC_RSFT);
451 unregister_code(KC_RSFT);
452 process_unicode((0x256F | QK_UNICODE), record); // Arm
454 process_unicode((0x0361 | QK_UNICODE), record); // Flippy
456 process_unicode((0x253B | QK_UNICODE), record); // Table
457 process_unicode((0x2501 | QK_UNICODE), record); // Table
458 process_unicode((0x253B | QK_UNICODE), record); // Table
462 #endif // UNICODE_ENABLE
465 return process_record_keymap(keycode, record);
469 // Runs state check and changes underglow color and animation
470 // on layer change, no matter where the change was initiated
471 // Then runs keymap's layer change check
472 uint32_t layer_state_set_user(uint32_t state) {
473 #ifdef RGBLIGHT_ENABLE
474 uint8_t default_layer = eeconfig_read_default_layer();
476 if (rgb_layer_change) {
477 switch (biton32(state)) {
479 rgblight_sethsv_blue();
483 rgblight_sethsv_blue();
487 rgblight_sethsv_yellow();
491 rgblight_sethsv_orange();
492 is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
495 rgblight_sethsv_chartreuse();
499 rgblight_sethsv_orange();
503 rgblight_sethsv_red();
507 rgblight_sethsv_yellow();
511 rgblight_sethsv_orange();
515 rgblight_sethsv_red();
519 rgblight_sethsv_green();
522 default: // for any other layers, or the default layer
523 if (default_layer & (1UL << _COLEMAK)) {
524 rgblight_sethsv_magenta();
526 else if (default_layer & (1UL << _DVORAK)) {
527 rgblight_sethsv_green();
529 else if (default_layer & (1UL << _WORKMAN)) {
530 rgblight_sethsv_goldenrod();
533 rgblight_sethsv_teal();
535 if (biton32(state) == _MODS) { // If the non-OSM layer is enabled, then breathe
537 } else { // otherwise, stay solid
543 #endif // RGBLIGHT_ENABLE
544 return layer_state_set_keymap (state);
548 // Any custom LED code goes here.
549 // So far, I only have keyboard specific code,
550 // So nothing goes here.
551 void led_set_user(uint8_t usb_led) {
552 led_set_keymap(usb_led);