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/>.
22 #include "sensitive.h"
24 #ifdef TAP_DANCE_ENABLE
25 //define diablo macro timer variables
26 static uint16_t diablo_timer[4];
27 static uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 };
28 static uint8_t diablo_key_time[4];
31 bool check_dtimer(uint8_t dtimer) {
32 // has the correct number of seconds elapsed (as defined by diablo_times)
33 return (timer_elapsed(diablo_timer[dtimer]) < (diablo_key_time[dtimer] * 1000)) ? false : true;
39 // Cycle through the times for the macro, starting at 0, for disabled.
40 // Max of six values, so don't exceed
41 void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data, uint8_t diablo_key) {
42 if (state->count >= 7) {
43 diablo_key_time[diablo_key] = diablo_times[0];
44 reset_tap_dance(state);
47 diablo_key_time[diablo_key] = diablo_times[state->count - 1];
52 // Would rather have one function for all of this, but no idea how to do that...
53 void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) {
54 diablo_tapdance_master(state, user_data, 0);
57 void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) {
58 diablo_tapdance_master(state, user_data, 1);
61 void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) {
62 diablo_tapdance_master(state, user_data, 2);
65 void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) {
66 diablo_tapdance_master(state, user_data, 3);
71 //Tap Dance Definitions
72 qk_tap_dance_action_t tap_dance_actions[] = {
73 // tap once to disable, and more to enable timed micros
74 [TD_D3_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1),
75 [TD_D3_2] = ACTION_TAP_DANCE_FN(diablo_tapdance2),
76 [TD_D3_3] = ACTION_TAP_DANCE_FN(diablo_tapdance3),
77 [TD_D3_4] = ACTION_TAP_DANCE_FN(diablo_tapdance4),
83 float tone_qwerty[][2] = SONG(QWERTY_SOUND);
84 float tone_dvorak[][2] = SONG(DVORAK_SOUND);
85 float tone_colemak[][2] = SONG(COLEMAK_SOUND);
86 float tone_workman[][2] = SONG(PLOVER_SOUND);
87 float tone_hackstartup[][2] = SONG(ONE_UP_SOUND);
91 // Add reconfigurable functions here, for keymap customization
92 // This allows for a global, userspace functions, and continued
93 // customization of the keymap. Use _keymap instead of _user
94 // functions in the keymaps
95 __attribute__ ((weak))
96 void matrix_init_keymap(void) {}
98 __attribute__ ((weak))
99 void matrix_scan_keymap(void) {}
101 __attribute__ ((weak))
102 bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
106 __attribute__ ((weak))
107 uint32_t layer_state_set_keymap (uint32_t state) {
111 __attribute__ ((weak))
112 void led_set_keymap(uint8_t usb_led) {}
114 bool is_overwatch = false;
115 #ifdef RGBLIGHT_ENABLE
116 bool rgb_layer_change = true;
122 // Call user matrix init, set default RGB colors and then
123 // call the keymap's init function
124 void matrix_init_user(void) {
125 #ifdef RGBLIGHT_ENABLE
126 uint8_t default_layer = eeconfig_read_default_layer();
131 if (default_layer & (1UL << _COLEMAK)) {
132 rgblight_set_magenta;
134 else if (default_layer & (1UL << _DVORAK)) {
137 else if (default_layer & (1UL << _WORKMAN)) {
151 // _delay_ms(21); // gets rid of tick
153 // PLAY_SONG(tone_hackstartup);
155 matrix_init_keymap();
157 #ifdef TAP_DANCE_ENABLE
159 // Sends the key press to system, but only if on the Diablo layer
160 void send_diablo_keystroke(uint8_t diablo_key) {
161 if (biton32(layer_state) == _DIABLO) {
162 switch (diablo_key) {
179 // Checks each of the 4 timers/keys to see if enough time has elapsed
180 // Runs the "send string" command if enough time has passed, and resets the timer.
181 void run_diablo_macro_check(void) {
184 for (dtime = 0; dtime < 4; dtime++) {
185 if (check_dtimer(dtime) && diablo_key_time[dtime]) {
186 diablo_timer[dtime] = timer_read();
187 send_diablo_keystroke(dtime);
193 // No global matrix scan code, so just run keymap's matix
195 void matrix_scan_user(void) {
196 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
197 run_diablo_macro_check();
199 matrix_scan_keymap();
202 void led_set_user(uint8_t usb_led) {
203 led_set_keymap(usb_led);
208 void persistent_default_layer_set(uint16_t default_layer) {
209 eeconfig_update_default_layer(default_layer);
210 default_layer_set(default_layer);
213 // Defines actions tor my global custom keycodes. Defined in drashna.h file
214 // Then runs the _keymap's recod handier if not processed here
215 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
217 #ifdef CONSOLE_ENABLE
218 xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
223 if (record->event.pressed) {
225 PLAY_SONG(tone_qwerty);
227 persistent_default_layer_set(1UL << _QWERTY);
232 if (record->event.pressed) {
234 PLAY_SONG(tone_colemak);
236 persistent_default_layer_set(1UL << _COLEMAK);
241 if (record->event.pressed) {
243 PLAY_SONG(tone_dvorak);
245 persistent_default_layer_set(1UL << _DVORAK);
250 if (record->event.pressed) {
252 PLAY_SONG(tone_workman);
254 persistent_default_layer_set(1UL << _WORKMAN);
259 if (record->event.pressed) {
261 update_tri_layer(_LOWER, _RAISE, _ADJUST);
265 update_tri_layer(_LOWER, _RAISE, _ADJUST);
270 if (record->event.pressed) {
272 update_tri_layer(_LOWER, _RAISE, _ADJUST);
276 update_tri_layer(_LOWER, _RAISE, _ADJUST);
281 if (record->event.pressed) {
289 #if !(defined(KEYBOARD_orthodox_rev1) || defined(KEYBOARD_ergodox_ez))
291 if (record->event.pressed) {
292 is_overwatch = !is_overwatch;
294 #ifdef RGBLIGHT_ENABLE
295 is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
300 if (!record->event.pressed) {
301 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
302 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
304 SEND_STRING("Salt, salt, salt...");
305 register_code(KC_ENTER);
306 unregister_code(KC_ENTER);
311 if (!record->event.pressed) {
312 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
313 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
315 SEND_STRING("Please sir, can I have some more salt?!");
316 register_code(KC_ENTER);
317 unregister_code(KC_ENTER);
322 if (!record->event.pressed) {
323 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
324 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
326 SEND_STRING("Your salt only makes me harder, and even more aggressive!");
327 register_code(KC_ENTER);
328 unregister_code(KC_ENTER);
333 if (!record->event.pressed) {
334 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
335 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
337 SEND_STRING("Good game, everyone!");
338 register_code(KC_ENTER);
339 unregister_code(KC_ENTER);
344 if (!record->event.pressed) {
345 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
346 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
348 SEND_STRING("Good luck, have fun!!!");
349 register_code(KC_ENTER);
350 unregister_code(KC_ENTER);
355 if (!record->event.pressed) {
356 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
357 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
359 SEND_STRING("Left click to win!");
360 register_code(KC_ENTER);
361 unregister_code(KC_ENTER);
366 if (!record->event.pressed) {
367 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
368 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
370 SEND_STRING("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.");
371 register_code(KC_ENTER);
372 unregister_code(KC_ENTER);
377 if (!record->event.pressed) {
378 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
379 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
381 SEND_STRING("That was positively riveting!");
382 register_code(KC_ENTER);
383 unregister_code(KC_ENTER);
388 if (!record->event.pressed) {
389 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
390 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
392 SEND_STRING("That aim is absolutely amazing. It's almost like you're a machine!" SS_TAP(X_ENTER));
394 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
395 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
396 SEND_STRING("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!" SS_TAP(X_ENTER));
401 if (!record->event.pressed) {
402 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
403 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
405 SEND_STRING("OMG!!! C9!!!");
406 register_code(KC_ENTER);
407 unregister_code(KC_ENTER);
412 if (!record->event.pressed) {
413 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
414 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
416 SEND_STRING("That was a fantastic game, though it was a bit easy. Try harder next time!");
417 register_code(KC_ENTER);
418 unregister_code(KC_ENTER);
423 #ifdef TAP_DANCE_ENABLE
424 case KC_DIABLO_CLEAR: // reset all Diable timers, disabling them
425 if (record->event.pressed) {
428 for (dtime = 0; dtime < 4; dtime++) {
429 diablo_key_time[dtime] = diablo_times[0];
436 if (!record->event.pressed) {
437 SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP
438 #if (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
440 #elif defined(BOOTLOADER_HALFKAY)
442 #elif defined(BOOTLOADER_CATERINA)
445 #ifdef RGBLIGHT_ENABLE
446 " RGBLIGHT_ENABLE=yes"
448 " RGBLIGHT_ENABLE=no"
455 #ifdef FAUXCLICKY_ENABLE
456 " FAUXCLICKY_ENABLE=yes"
458 " FAUXCLICKY_ENABLE=no"
465 if (!record->event.pressed) {
466 #ifdef RGBLIGHT_ENABLE
469 rgblight_setrgb(0xff, 0x00, 0x00);
476 if (record->event.pressed) {
482 if (record->event.pressed) {
483 SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION);
487 case KC_SECRET_1 ... KC_SECRET_5:
488 if (!record->event.pressed) {
489 send_string(secret[keycode - KC_SECRET_1]);
493 case KC_RGB_T: // Because I want the option to go back to normal RGB mode rather than always layer indication
494 #ifdef RGBLIGHT_ENABLE
495 if (record->event.pressed) {
496 rgb_layer_change = !rgb_layer_change;
501 #ifdef RGBLIGHT_ENABLE
502 case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
503 if (record->event.pressed) { //This disrables layer indication, as it's assumed that if you're changing this ... you want that disabled
504 rgb_layer_change = false;
510 return process_record_keymap(keycode, record);
513 // Runs state check and changes underglow color and animation
514 // on layer change, no matter where the change was initiated
515 // Then runs keymap's layer change check
516 uint32_t layer_state_set_user(uint32_t state) {
517 #ifdef RGBLIGHT_ENABLE
518 uint8_t default_layer = eeconfig_read_default_layer();
519 if (rgb_layer_change) {
520 switch (biton32(state)) {
535 is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
565 if (default_layer & (1UL << _COLEMAK)) {
566 rgblight_set_magenta;
568 else if (default_layer & (1UL << _DVORAK)) {
571 else if (default_layer & (1UL << _WORKMAN)) {
582 return layer_state_set_keymap (state);