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/>.
23 #ifdef TAP_DANCE_ENABLE
24 //define diablo macro timer variables
25 static uint16_t diablo_timer[4];
26 static uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 };
27 static uint8_t diablo_key_time[4];
30 bool check_dtimer(uint8_t dtimer) {
31 // has the correct number of seconds elapsed (as defined by diablo_times)
32 return (timer_elapsed(diablo_timer[dtimer]) < (diablo_key_time[dtimer] * 1000)) ? false : true;
38 // Cycle through the times for the macro, starting at 0, for disabled.
39 // Max of six values, so don't exceed
40 void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data, uint8_t diablo_key) {
41 if (state->count >= 7) {
42 diablo_key_time[diablo_key] = diablo_times[0];
43 reset_tap_dance(state);
46 diablo_key_time[diablo_key] = diablo_times[state->count - 1];
51 // Would rather have one function for all of this, but no idea how to do that...
52 void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) {
53 diablo_tapdance_master(state, user_data, 0);
56 void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) {
57 diablo_tapdance_master(state, user_data, 1);
60 void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) {
61 diablo_tapdance_master(state, user_data, 2);
64 void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) {
65 diablo_tapdance_master(state, user_data, 3);
70 //Tap Dance Definitions
71 qk_tap_dance_action_t tap_dance_actions[] = {
72 // tap once to disable, and more to enable timed micros
73 [TD_D3_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1),
74 [TD_D3_2] = ACTION_TAP_DANCE_FN(diablo_tapdance2),
75 [TD_D3_3] = ACTION_TAP_DANCE_FN(diablo_tapdance3),
76 [TD_D3_4] = ACTION_TAP_DANCE_FN(diablo_tapdance4),
82 // Add reconfigurable functions here, for keymap customization
83 // This allows for a global, userspace functions, and continued
84 // customization of the keymap. Use _keymap instead of _user
85 // functions in the keymaps
86 __attribute__ ((weak))
87 void matrix_init_keymap(void) {}
89 __attribute__ ((weak))
90 void matrix_scan_keymap(void) {}
92 __attribute__ ((weak))
93 bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
97 __attribute__ ((weak))
98 uint32_t layer_state_set_keymap (uint32_t state) {
102 __attribute__ ((weak))
103 void led_set_keymap(uint8_t usb_led) {}
105 bool is_overwatch = false;
106 #ifdef RGBLIGHT_ENABLE
107 bool rgb_layer_change = true;
113 // Call user matrix init, set default RGB colors and then
114 // call the keymap's init function
115 void matrix_init_user(void) {
116 #ifdef RGBLIGHT_ENABLE
117 uint8_t default_layer = eeconfig_read_default_layer();
122 if (default_layer & (1UL << _COLEMAK)) {
123 rgblight_set_magenta;
125 else if (default_layer & (1UL << _DVORAK)) {
128 else if (default_layer & (1UL << _WORKMAN)) {
141 matrix_init_keymap();
143 #ifdef TAP_DANCE_ENABLE
145 // Sends the key press to system, but only if on the Diablo layer
146 void send_diablo_keystroke(uint8_t diablo_key) {
147 if (biton32(layer_state) == _DIABLO) {
148 switch (diablo_key) {
165 // Checks each of the 4 timers/keys to see if enough time has elapsed
166 // Runs the "send string" command if enough time has passed, and resets the timer.
167 void run_diablo_macro_check(void) {
170 for (dtime = 0; dtime < 4; dtime++) {
171 if (check_dtimer(dtime) && diablo_key_time[dtime]) {
172 diablo_timer[dtime] = timer_read();
173 send_diablo_keystroke(dtime);
179 // No global matrix scan code, so just run keymap's matix
181 void matrix_scan_user(void) {
182 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
183 run_diablo_macro_check();
185 matrix_scan_keymap();
188 void led_set_user(uint8_t usb_led) {
189 led_set_keymap(usb_led);
194 float tone_qwerty[][2] = SONG(QWERTY_SOUND);
195 float tone_dvorak[][2] = SONG(DVORAK_SOUND);
196 float tone_colemak[][2] = SONG(COLEMAK_SOUND);
197 float tone_workman[][2] = SONG(PLOVER_SOUND);
201 void persistent_default_layer_set(uint16_t default_layer) {
202 eeconfig_update_default_layer(default_layer);
203 default_layer_set(default_layer);
206 // Defines actions tor my global custom keycodes. Defined in drashna.h file
207 // Then runs the _keymap's recod handier if not processed here
208 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
210 #ifdef CONSOLE_ENABLE
211 xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
216 if (record->event.pressed) {
218 PLAY_SONG(tone_qwerty);
220 persistent_default_layer_set(1UL << _QWERTY);
225 if (record->event.pressed) {
227 PLAY_SONG(tone_colemak);
229 persistent_default_layer_set(1UL << _COLEMAK);
234 if (record->event.pressed) {
236 PLAY_SONG(tone_dvorak);
238 persistent_default_layer_set(1UL << _DVORAK);
243 if (record->event.pressed) {
245 PLAY_SONG(tone_workman);
247 persistent_default_layer_set(1UL << _WORKMAN);
252 if (record->event.pressed) {
254 update_tri_layer(_LOWER, _RAISE, _ADJUST);
258 update_tri_layer(_LOWER, _RAISE, _ADJUST);
263 if (record->event.pressed) {
265 update_tri_layer(_LOWER, _RAISE, _ADJUST);
269 update_tri_layer(_LOWER, _RAISE, _ADJUST);
274 if (record->event.pressed) {
282 #if !(defined(KEYBOARD_orthodox_rev1) || defined(KEYBOARD_ergodox_ez))
284 if (record->event.pressed) {
285 is_overwatch = !is_overwatch;
287 #ifdef RGBLIGHT_ENABLE
288 is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
293 if (!record->event.pressed) {
294 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
295 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
297 SEND_STRING("Salt, salt, salt...");
298 register_code(KC_ENTER);
299 unregister_code(KC_ENTER);
304 if (!record->event.pressed) {
305 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
306 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
308 SEND_STRING("Please sir, can I have some more salt?!");
309 register_code(KC_ENTER);
310 unregister_code(KC_ENTER);
315 if (!record->event.pressed) {
316 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
317 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
319 SEND_STRING("Your salt only makes me harder, and even more aggressive!");
320 register_code(KC_ENTER);
321 unregister_code(KC_ENTER);
326 if (!record->event.pressed) {
327 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
328 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
330 SEND_STRING("Good game, everyone!");
331 register_code(KC_ENTER);
332 unregister_code(KC_ENTER);
337 if (!record->event.pressed) {
338 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
339 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
341 SEND_STRING("Good luck, have fun!!!");
342 register_code(KC_ENTER);
343 unregister_code(KC_ENTER);
348 if (!record->event.pressed) {
349 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
350 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
352 SEND_STRING("Left click to win!");
353 register_code(KC_ENTER);
354 unregister_code(KC_ENTER);
359 if (!record->event.pressed) {
360 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
361 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
363 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.");
364 register_code(KC_ENTER);
365 unregister_code(KC_ENTER);
370 if (!record->event.pressed) {
371 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
372 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
374 SEND_STRING("That was positively riveting!");
375 register_code(KC_ENTER);
376 unregister_code(KC_ENTER);
381 if (!record->event.pressed) {
382 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
383 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
385 SEND_STRING("That aim is absolutely amazing. It's almost like you're a machine!" SS_TAP(X_ENTER));
387 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
388 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
389 SEND_STRING("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!" SS_TAP(X_ENTER));
394 if (!record->event.pressed) {
395 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
396 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
398 SEND_STRING("OMG!!! C9!!!");
399 register_code(KC_ENTER);
400 unregister_code(KC_ENTER);
405 if (!record->event.pressed) {
406 register_code(is_overwatch ? KC_BSPC : KC_ENTER);
407 unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
409 SEND_STRING("That was a fantastic game, though it was a bit easy. Try harder next time!");
410 register_code(KC_ENTER);
411 unregister_code(KC_ENTER);
416 #ifdef TAP_DANCE_ENABLE
417 case KC_DIABLO_CLEAR: // reset all Diable timers, disabling them
418 if (record->event.pressed) {
421 for (dtime = 0; dtime < 4; dtime++) {
422 diablo_key_time[dtime] = diablo_times[0];
429 if (!record->event.pressed) {
430 SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP);
431 #ifndef CATERINA_BOOTLOADER
432 SEND_STRING(":teensy ");
436 #ifdef RGBLIGHT_ENABLE
437 SEND_STRING("RGBLIGHT_ENABLE=yes ");
439 SEND_STRING("RGBLIGHT_ENABLE=no ");
442 SEND_STRING("AUDIO_ENABLE=yes ");
444 SEND_STRING("AUDIO_ENABLE=no ");
446 #ifdef FAUXCLICKY_ENABLE
447 SEND_STRING("FAUXCLICKY_ENABLE=yes ");
449 SEND_STRING("FAUXCLICKY_ENABLE=no ");
451 SEND_STRING(SS_TAP(X_ENTER));
456 if (!record->event.pressed) {
457 #ifdef RGBLIGHT_ENABLE
460 rgblight_setrgb(0xff, 0x00, 0x00);
467 if (record->event.pressed) {
473 if (record->event.pressed) {
474 SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION);
478 case KC_RGB_T: // Because I want the option to go back to normal RGB mode rather than always layer indication
479 if (record->event.pressed) {
480 rgb_layer_change = !rgb_layer_change;
493 case RGB_MODE_BREATHE:
494 case RGB_MODE_RAINBOW:
497 case RGB_MODE_KNIGHT:
499 case RGB_MODE_GRADIENT:
500 if (record->event.pressed) {
501 rgb_layer_change = false;
506 return process_record_keymap(keycode, record);
509 // Runs state check and changes underglow color and animation
510 // on layer change, no matter where the change was initiated
511 // Then runs keymap's layer change check
512 uint32_t layer_state_set_user(uint32_t state) {
513 #ifdef RGBLIGHT_ENABLE
514 uint8_t default_layer = eeconfig_read_default_layer();
515 if (rgb_layer_change) {
516 switch (biton32(state)) {
531 is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
561 if (default_layer & (1UL << _COLEMAK)) {
562 rgblight_set_magenta;
564 else if (default_layer & (1UL << _DVORAK)) {
567 else if (default_layer & (1UL << _WORKMAN)) {
578 return layer_state_set_keymap (state);