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 #include "tap_dances.h"
22 #include "rgb_stuff.h"
25 float tone_copy[][2] = SONG(SCROLL_LOCK_ON_SOUND);
26 float tone_paste[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
28 static uint16_t copy_paste_timer;
29 userspace_config_t userspace_config;
34 // This block is for all of the gaming macros, as they were all doing
35 // the same thing, but with differring text sent.
36 bool send_game_macro(const char *str, keyrecord_t *record, bool override) {
37 if (!record->event.pressed || override) {
39 tap(userspace_config.is_overwatch ? KC_BSPC : KC_ENTER);
45 if (override) wait_ms(3000);
49 void tap(uint16_t keycode){ register_code(keycode); unregister_code(keycode); };
52 // Add reconfigurable functions here, for keymap customization
53 // This allows for a global, userspace functions, and continued
54 // customization of the keymap. Use _keymap instead of _user
55 // functions in the keymaps
56 __attribute__ ((weak))
57 void matrix_init_keymap(void) {}
59 __attribute__ ((weak))
60 void matrix_scan_keymap(void) {}
62 __attribute__ ((weak))
63 bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
67 __attribute__ ((weak))
68 bool process_record_secrets(uint16_t keycode, keyrecord_t *record) {
72 __attribute__ ((weak))
73 uint32_t layer_state_set_keymap (uint32_t state) {
77 __attribute__ ((weak))
78 void led_set_keymap(uint8_t usb_led) {}
81 // Call user matrix init, set default RGB colors and then
82 // call the keymap's init function
83 void matrix_init_user(void) {
84 userspace_config.raw = eeprom_read_byte(EECONFIG_USERSPACE);
87 clicky_enable = userspace_config.clicky_enable;
90 #ifdef BOOTLOADER_CATERINA
99 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
100 set_unicode_input_mode(UC_WINC);
101 #endif //UNICODE_ENABLE
103 matrix_init_keymap();
107 // No global matrix scan code, so just run keymap's matrix
109 void matrix_scan_user(void) {
111 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
112 run_diablo_macro_check();
113 #endif // TAP_DANCE_ENABLE
115 #ifdef RGBLIGHT_ENABLE
117 #endif // RGBLIGHT_ENABLE
119 matrix_scan_keymap();
125 // Defines actions tor my global custom keycodes. Defined in drashna.h file
126 // Then runs the _keymap's record handier if not processed here
127 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
129 // If console is enabled, it will print the matrix position and status of each key pressed
130 #ifdef KEYLOGGER_ENABLE
131 xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
132 #endif //KEYLOGGER_ENABLE
136 if (record->event.pressed) {
137 set_single_persistent_default_layer(_QWERTY);
142 if (record->event.pressed) {
143 set_single_persistent_default_layer(_COLEMAK);
148 if (record->event.pressed) {
149 set_single_persistent_default_layer(_DVORAK);
154 if (record->event.pressed) {
155 set_single_persistent_default_layer(_WORKMAN);
161 case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
162 if (!record->event.pressed) {
163 SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP
164 #if (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
166 #elif defined(BOOTLOADER_HALFKAY)
168 #elif defined(BOOTLOADER_CATERINA)
170 #endif // bootloader options
177 case KC_RESET: // Custom RESET code that sets RGBLights to RED
178 if (!record->event.pressed) {
179 #ifdef RGBLIGHT_ENABLE
180 rgblight_enable_noeeprom();
181 rgblight_mode_noeeprom(1);
182 rgblight_setrgb_red();
183 #endif // RGBLIGHT_ENABLE
190 case EPRM: // Resets EEPROM
191 if (record->event.pressed) {
193 default_layer_set(1UL<<eeconfig_read_default_layer());
194 layer_state_set(layer_state);
198 case VRSN: // Prints firmware version
199 if (record->event.pressed) {
200 SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE);
205 /* Code has been depreciated
206 case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
207 if (!record->event.pressed) {
208 clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
209 send_string(decoy_secret[keycode - KC_SECRET_1]);
215 // These are a serious of gaming macros.
216 // Only enables for the viterbi, basically,
217 // to save on firmware space, since it's limited.
218 #ifdef MACROS_ENABLED
219 case KC_OVERWATCH: // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
220 if (record->event.pressed) { userspace_config.is_overwatch ^= 1; eeprom_update_byte(EECONFIG_USERSPACE, userspace_config.raw); }
221 #ifdef RGBLIGHT_ENABLE
222 userspace_config.is_overwatch ? rgblight_mode_noeeprom(17) : rgblight_mode_noeeprom(18);
223 #endif //RGBLIGHT_ENABLE
226 return send_game_macro("Salt, salt, salt...", record, false);
228 return send_game_macro("Please sir, can I have some more salt?!", record, false);
230 return send_game_macro("Your salt only makes me harder, and even more aggressive!", record, false);
232 return send_game_macro("Good game, everyone!", record, false);
234 return send_game_macro("Good luck, have fun!!!", record, false);
236 return send_game_macro("Left click to win!", record, false);
238 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);
240 return send_game_macro("That was positively riveting!", record, false);
242 send_game_macro("That aim is absolutely amazing. It's almost like you're a machine!", record, true);
243 return send_game_macro("Wait! That aim is TOO good! You're clearly using an aim hack! CHEATER!", record, false);
245 return send_game_macro("OMG!!! C9!!!", record, false);
247 return send_game_macro("That was a fantastic game, though it was a bit easy. Try harder next time!", record, false);
248 #endif // MACROS_ENABLED
251 case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
252 #ifdef TAP_DANCE_ENABLE
253 if (record->event.pressed) {
255 for (dtime = 0; dtime < 4; dtime++) {
256 diablo_key_time[dtime] = diablo_times[0];
259 #endif // TAP_DANCE_ENABLE#endif
263 case KC_CCCV: // One key copy/paste
264 if(record->event.pressed){
265 copy_paste_timer = timer_read();
267 if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy
268 register_code(KC_LCTL);
270 unregister_code(KC_LCTL);
272 PLAY_SONG(tone_copy);
274 } else { // Tap, paste
275 register_code(KC_LCTL);
277 unregister_code(KC_LCTL);
279 PLAY_SONG(tone_paste);
287 userspace_config.clicky_enable = clicky_enable;
288 eeprom_update_byte(EECONFIG_USERSPACE, userspace_config.raw);
291 #ifdef UNICODE_ENABLE
292 case UC_FLIP: // (╯°□°)╯ ︵ ┻━┻
293 if (record->event.pressed) {
294 register_code(KC_RSFT);
296 unregister_code(KC_RSFT);
297 process_unicode((0x256F | QK_UNICODE), record); // Arm
298 process_unicode((0x00B0 | QK_UNICODE), record); // Eye
299 process_unicode((0x25A1 | QK_UNICODE), record); // Mouth
300 process_unicode((0x00B0 | QK_UNICODE), record); // Eye
301 register_code(KC_RSFT);
303 unregister_code(KC_RSFT);
304 process_unicode((0x256F | QK_UNICODE), record); // Arm
306 process_unicode((0x0361 | QK_UNICODE), record); // Flippy
308 process_unicode((0x253B | QK_UNICODE), record); // Table
309 process_unicode((0x2501 | QK_UNICODE), record); // Table
310 process_unicode((0x253B | QK_UNICODE), record); // Table
314 #endif // UNICODE_ENABLE
317 return process_record_keymap(keycode, record) && process_record_secrets(keycode, record) && process_record_user_rgb(keycode, record);
322 // Runs state check and changes underglow color and animation
323 // on layer change, no matter where the change was initiated
324 // Then runs keymap's layer change check
325 uint32_t layer_state_set_user(uint32_t state) {
326 state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
327 #ifdef RGBLIGHT_ENABLE
328 state = layer_state_set_rgb(state);
329 #endif // RGBLIGHT_ENABLE
330 return layer_state_set_keymap (state);
334 // Any custom LED code goes here.
335 // So far, I only have keyboard specific code,
336 // So nothing goes here.
337 void led_set_user(uint8_t usb_led) {
338 led_set_keymap(usb_led);