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 bool faux_click_enabled = false;
45 bool is_overwatch = false;
46 #ifdef RGBLIGHT_ENABLE
47 bool rgb_layer_change = true;
50 #ifdef TAP_DANCE_ENABLE
51 //define diablo macro timer variables
52 static uint16_t diablo_timer[4];
53 static uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 };
54 static uint8_t diablo_key_time[4];
56 bool check_dtimer(uint8_t dtimer) {
57 // has the correct number of seconds elapsed (as defined by diablo_times)
58 return (timer_elapsed(diablo_timer[dtimer]) < (diablo_key_time[dtimer] * 1000)) ? false : true;
61 // Cycle through the times for the macro, starting at 0, for disabled.
62 // Max of six values, so don't exceed
63 void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data, uint8_t diablo_key) {
64 if (state->count >= 7) {
65 diablo_key_time[diablo_key] = diablo_times[0];
66 reset_tap_dance(state);
69 diablo_key_time[diablo_key] = diablo_times[state->count - 1];
73 // Would rather have one function for all of this, but no idea how to do that...
74 void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) {
75 diablo_tapdance_master(state, user_data, 0);
77 void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) {
78 diablo_tapdance_master(state, user_data, 1);
80 void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) {
81 diablo_tapdance_master(state, user_data, 2);
83 void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) {
84 diablo_tapdance_master(state, user_data, 3);
87 //Tap Dance Definitions
88 qk_tap_dance_action_t tap_dance_actions[] = {
89 // tap once to disable, and more to enable timed micros
90 [TD_D3_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1),
91 [TD_D3_2] = ACTION_TAP_DANCE_FN(diablo_tapdance2),
92 [TD_D3_3] = ACTION_TAP_DANCE_FN(diablo_tapdance3),
93 [TD_D3_4] = ACTION_TAP_DANCE_FN(diablo_tapdance4),
97 // Sends the key press to system, but only if on the Diablo layer
98 void send_diablo_keystroke(uint8_t diablo_key) {
99 if (biton32(layer_state) == _DIABLO) {
100 switch (diablo_key) {
117 // Checks each of the 4 timers/keys to see if enough time has elapsed
118 // Runs the "send string" command if enough time has passed, and resets the timer.
119 void run_diablo_macro_check(void) {
122 for (dtime = 0; dtime < 4; dtime++) {
123 if (check_dtimer(dtime) && diablo_key_time[dtime]) {
124 diablo_timer[dtime] = timer_read();
125 send_diablo_keystroke(dtime);
130 #endif // TAP_DANCE_ENABLE
133 // Add reconfigurable functions here, for keymap customization
134 // This allows for a global, userspace functions, and continued
135 // customization of the keymap. Use _keymap instead of _user
136 // functions in the keymaps
137 __attribute__ ((weak))
138 void matrix_init_keymap(void) {}
140 __attribute__ ((weak))
141 void matrix_scan_keymap(void) {}
143 __attribute__ ((weak))
144 bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
148 __attribute__ ((weak))
149 uint32_t layer_state_set_keymap (uint32_t state) {
153 __attribute__ ((weak))
154 void led_set_keymap(uint8_t usb_led) {}
157 // Call user matrix init, set default RGB colors and then
158 // call the keymap's init function
159 void matrix_init_user(void) {
160 #ifdef RGBLIGHT_ENABLE
161 uint8_t default_layer = eeconfig_read_default_layer();
166 if (default_layer & (1UL << _COLEMAK)) {
167 rgblight_sethsv_magenta();
169 else if (default_layer & (1UL << _DVORAK)) {
170 rgblight_sethsv_green();
172 else if (default_layer & (1UL << _WORKMAN)) {
173 rgblight_sethsv_goldenrod();
176 rgblight_sethsv_teal();
181 rgblight_setrgb_red();
184 #endif // RGBLIGHT_ENABLE
186 #if ( defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) )
187 set_unicode_input_mode(UC_WINC);
188 #endif //UNICODE_ENABLE
190 matrix_init_keymap();
192 // No global matrix scan code, so just run keymap's matrix
194 void matrix_scan_user(void) {
195 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
196 run_diablo_macro_check();
197 #endif // TAP_DANCE_ENABLE
198 matrix_scan_keymap();
201 // This block is for all of the gaming macros, as they were all doing
202 // the same thing, but with differring text sent.
203 bool send_game_macro(const char *str, keyrecord_t *record, bool override) {
204 if (!record->event.pressed || override) {
206 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
207 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
210 register_code(KC_ENTER);
211 unregister_code(KC_ENTER);
213 if (override) wait_ms(3000);
218 // Defines actions tor my global custom keycodes. Defined in drashna.h file
219 // Then runs the _keymap's record handier if not processed here
220 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
222 // If console is enabled, it will print the matrix position and status of each key pressed
223 #ifdef CONSOLE_ENABLE
224 xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
225 #endif //CONSOLE_ENABLE
227 // Run custom faux click code, but only if faux clicky is enabled
229 if ( (faux_click_enabled && keycode != KC_FXCL) || (!faux_click_enabled && keycode == KC_FXCL) ) {
230 if (record->event.pressed) {
232 PLAY_SONG(fauxclicky_pressed);
235 PLAY_SONG(fauxclicky_released);
238 #endif //AUDIO_ENABLE
243 if (record->event.pressed) {
244 set_single_persistent_default_layer(_QWERTY);
249 if (record->event.pressed) {
250 set_single_persistent_default_layer(_COLEMAK);
255 if (record->event.pressed) {
256 set_single_persistent_default_layer(_DVORAK);
261 if (record->event.pressed) {
262 set_single_persistent_default_layer(_WORKMAN);
269 if (record->event.pressed) {
271 update_tri_layer(_LOWER, _RAISE, _ADJUST);
275 update_tri_layer(_LOWER, _RAISE, _ADJUST);
280 if (record->event.pressed) {
282 update_tri_layer(_LOWER, _RAISE, _ADJUST);
286 update_tri_layer(_LOWER, _RAISE, _ADJUST);
291 if (record->event.pressed) {
301 case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
302 if (!record->event.pressed) {
303 SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP
304 #if (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
306 #elif defined(BOOTLOADER_HALFKAY)
308 #elif defined(BOOTLOADER_CATERINA)
310 #endif // bootloader options
317 case KC_RESET: // Custom RESET code that sets RGBLights to RED
318 if (!record->event.pressed) {
319 #ifdef RGBLIGHT_ENABLE
322 rgblight_setrgb_red();
323 #endif // RGBLIGHT_ENABLE
330 case EPRM: // Resets EEPROM
331 if (record->event.pressed) {
336 case VRSN: // Prints firmware version
337 if (record->event.pressed) {
338 SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE);
344 case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
345 if (!record->event.pressed) {
346 clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
347 send_string_P(secret[keycode - KC_SECRET_1]);
353 // These are a serious of gaming macros.
354 // Only enables for the viterbi, basically,
355 // to save on firmware space, since it's limited.
356 #if !(defined(KEYBOARD_orthodox_rev1) || defined(KEYBOARD_orthodox_rev3) || defined(KEYBOARD_ergodox_ez))
357 case KC_OVERWATCH: // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
358 if (record->event.pressed) { is_overwatch = !is_overwatch; }
359 #ifdef RGBLIGHT_ENABLE
360 is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
361 #endif //RGBLIGHT_ENABLE
364 return send_game_macro("Salt, salt, salt...", record, false);
366 return send_game_macro("Please sir, can I have some more salt?!", record, false);
368 return send_game_macro("Your salt only makes me harder, and even more aggressive!", record, false);
370 return send_game_macro("Good game, everyone!", record, false);
372 return send_game_macro("Good luck, have fun!!!", record, false);
374 return send_game_macro("Left click to win!", record, false);
376 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);
378 return send_game_macro("That was positively riveting!", record, false);
380 send_game_macro("That aim is absolutely amazing. It's almost like you're a machine!", record, true);
381 return send_game_macro("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!", record, false);
383 return send_game_macro("OMG!!! C9!!!", record, false);
385 return send_game_macro("That was a fantastic game, though it was a bit easy. Try harder next time!", record, false);
386 #endif // !(defined(KEYBOARD_orthodox_rev1) || defined(KEYBOARD_orthodox_rev3) || defined(KEYBOARD_ergodox_ez))
389 #ifdef TAP_DANCE_ENABLE
390 case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
391 if (record->event.pressed) {
393 for (dtime = 0; dtime < 4; dtime++) {
394 diablo_key_time[dtime] = diablo_times[0];
398 #endif // TAP_DANCE_ENABLE
402 if (!record->event.pressed) { // Toggles the custom faux click code
403 faux_click_enabled = !faux_click_enabled;
406 case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal
407 #ifdef RGBLIGHT_ENABLE
408 if (record->event.pressed) {
409 rgb_layer_change = !rgb_layer_change;
410 if (rgb_layer_change) {
411 layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better)
414 #endif // RGBLIGHT_ENABLE
416 #ifdef RGBLIGHT_ENABLE
417 case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
418 if (record->event.pressed) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
419 rgb_layer_change = false;
422 #endif // RGBLIGHT_ENABLE
424 return process_record_keymap(keycode, record);
428 // Runs state check and changes underglow color and animation
429 // on layer change, no matter where the change was initiated
430 // Then runs keymap's layer change check
431 uint32_t layer_state_set_user(uint32_t state) {
432 #ifdef RGBLIGHT_ENABLE
433 uint8_t default_layer = eeconfig_read_default_layer();
434 if (rgb_layer_change) {
435 switch (biton32(state)) {
437 rgblight_sethsv_blue();
441 rgblight_sethsv_blue();
445 rgblight_sethsv_yellow();
449 rgblight_sethsv_orange();
450 is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
453 rgblight_sethsv_chartreuse();
457 rgblight_sethsv_orange();
461 rgblight_sethsv_red();
465 rgblight_sethsv_yellow();
469 rgblight_sethsv_orange();
473 rgblight_sethsv_red();
477 rgblight_sethsv_green();
480 default: // for any other layers, or the default layer
481 if (default_layer & (1UL << _COLEMAK)) {
482 rgblight_sethsv_magenta();
484 else if (default_layer & (1UL << _DVORAK)) {
485 rgblight_sethsv_green();
487 else if (default_layer & (1UL << _WORKMAN)) {
488 rgblight_sethsv_goldenrod();
491 rgblight_sethsv_teal();
493 if (biton32(state) == _MODS) { // If the non-OSM layer is enabled, then breathe
495 } else { // otherwise, stay solid
501 #endif // RGBLIGHT_ENABLE
502 return layer_state_set_keymap (state);
506 // Any custom LED code goes here.
507 // So far, I only have keyboard specific code,
508 // So nothing goes here.
509 void led_set_user(uint8_t usb_led) {
510 led_set_keymap(usb_led);