]> git.donarmstrong.com Git - qmk_firmware.git/blob - users/drashna/drashna.c
Update to drashna keymaps (#2381)
[qmk_firmware.git] / users / drashna / drashna.c
1 /*
2 Copyright 2017 Christopher Courtney <drashna@live.com> @drashna
3
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.
8
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.
13
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/>.
16 */
17
18 #include "drashna.h"
19 #include "version.h"
20
21 #if (__has_include("secrets.h"))
22 #include "secrets.h"
23 #else
24 // `PROGMEM const char secret[][x]` may work better, but it takes up more space in the firmware
25 // And I'm not familar enough to know which is better or why...
26 PROGMEM const char secret[][64] = {
27   "test1",
28   "test2",
29   "test3",
30   "test4",
31   "test5"
32 };
33 #endif
34
35 #ifdef FAUXCLICKY_ENABLE
36 float fauxclicky_pressed_note[2]  = MUSICAL_NOTE(_A6, 2);  // (_D4, 0.25);
37 float fauxclicky_released_note[2] = MUSICAL_NOTE(_A6, 2); // (_C4, 0.125);
38 #else
39 float fauxclicky_pressed[][2]             = SONG(E__NOTE(_A6)); // change to your tastes
40 float fauxclicky_released[][2]             = SONG(E__NOTE(_A6)); // change to your tastes
41 #endif 
42 bool faux_click_enabled = true;
43
44 #ifdef TAP_DANCE_ENABLE
45 //define diablo macro timer variables
46 static uint16_t diablo_timer[4];
47 static uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 };
48 static uint8_t diablo_key_time[4];
49
50
51 bool check_dtimer(uint8_t dtimer) {
52   // has the correct number of seconds elapsed (as defined by diablo_times)
53   return (timer_elapsed(diablo_timer[dtimer]) < (diablo_key_time[dtimer] * 1000)) ? false : true;
54 };
55
56
57
58
59 // Cycle through the times for the macro, starting at 0, for disabled.
60 // Max of six values, so don't exceed
61 void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data, uint8_t diablo_key) {
62   if (state->count >= 7) {
63     diablo_key_time[diablo_key] = diablo_times[0];
64     reset_tap_dance(state);
65   }
66   else {
67     diablo_key_time[diablo_key] = diablo_times[state->count - 1];
68   }
69 }
70
71
72 // Would rather have one function for all of this, but no idea how to do that...
73 void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) {
74   diablo_tapdance_master(state, user_data, 0);
75 }
76
77 void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) {
78   diablo_tapdance_master(state, user_data, 1);
79 }
80
81 void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) {
82   diablo_tapdance_master(state, user_data, 2);
83 }
84
85 void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) {
86   diablo_tapdance_master(state, user_data, 3);
87 }
88
89
90
91 //Tap Dance Definitions
92 qk_tap_dance_action_t tap_dance_actions[] = {
93   // tap once to disable, and more to enable timed micros
94   [TD_D3_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1),
95   [TD_D3_2] = ACTION_TAP_DANCE_FN(diablo_tapdance2),
96   [TD_D3_3] = ACTION_TAP_DANCE_FN(diablo_tapdance3),
97   [TD_D3_4] = ACTION_TAP_DANCE_FN(diablo_tapdance4),
98
99 };
100 #endif
101
102 #ifdef AUDIO_ENABLE
103 float tone_qwerty[][2]       = SONG(QWERTY_SOUND);
104 float tone_dvorak[][2]       = SONG(DVORAK_SOUND);
105 float tone_colemak[][2]      = SONG(COLEMAK_SOUND);
106 float tone_workman[][2]      = SONG(PLOVER_SOUND);
107 float tone_hackstartup[][2]  = SONG(ONE_UP_SOUND);
108 #endif
109
110
111 // Add reconfigurable functions here, for keymap customization
112 // This allows for a global, userspace functions, and continued
113 // customization of the keymap.  Use _keymap instead of _user
114 // functions in the keymaps
115 __attribute__ ((weak))
116 void matrix_init_keymap(void) {}
117
118 __attribute__ ((weak))
119 void matrix_scan_keymap(void) {}
120
121 __attribute__ ((weak))
122 bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
123   return true;
124 }
125
126 __attribute__ ((weak))
127 uint32_t layer_state_set_keymap (uint32_t state) {
128   return state;
129 }
130
131 __attribute__ ((weak))
132 void led_set_keymap(uint8_t usb_led) {}
133
134 bool is_overwatch = false;
135 #ifdef RGBLIGHT_ENABLE
136 bool rgb_layer_change = true;
137 #endif
138
139
140
141
142 // Call user matrix init, set default RGB colors and then
143 // call the keymap's init function
144 void matrix_init_user(void) {
145 #ifdef RGBLIGHT_ENABLE
146   uint8_t default_layer = eeconfig_read_default_layer();
147
148   rgblight_enable();
149
150   if (true) {
151     if (default_layer & (1UL << _COLEMAK)) {
152       rgblight_set_magenta;
153     }
154     else if (default_layer & (1UL << _DVORAK)) {
155       rgblight_set_green;
156     }
157     else if (default_layer & (1UL << _WORKMAN)) {
158       rgblight_set_purple;
159     }
160     else {
161       rgblight_set_teal;
162     }
163   }
164   else
165   {
166     rgblight_set_red;
167     rgblight_mode(5);
168   }
169 #endif
170 #ifdef AUDIO_ENABLE
171 //  wait_ms(21); // gets rid of tick
172 //  stop_all_notes();
173 //  PLAY_SONG(tone_hackstartup);
174 #endif
175   matrix_init_keymap();
176 }
177 #ifdef TAP_DANCE_ENABLE
178
179 // Sends the key press to system, but only if on the Diablo layer
180 void send_diablo_keystroke(uint8_t diablo_key) {
181   if (biton32(layer_state) == _DIABLO) {
182     switch (diablo_key) {
183     case 0:
184       SEND_STRING("1");
185       break;
186     case 1:
187       SEND_STRING("2");
188       break;
189     case 2:
190       SEND_STRING("3");
191       break;
192     case 3:
193       SEND_STRING("4");
194       break;
195     }
196   }
197 }
198
199 // Checks each of the 4 timers/keys to see if enough time has elapsed
200 // Runs the "send string" command if enough time has passed, and resets the timer.
201 void run_diablo_macro_check(void) {
202   uint8_t dtime;
203
204   for (dtime = 0; dtime < 4; dtime++) {
205     if (check_dtimer(dtime) && diablo_key_time[dtime]) {
206       diablo_timer[dtime] = timer_read();
207       send_diablo_keystroke(dtime);
208     }
209   }
210
211 }
212 #endif
213 // No global matrix scan code, so just run keymap's matix
214 // scan function
215 void matrix_scan_user(void) {
216 #ifdef TAP_DANCE_ENABLE  // Run Diablo 3 macro checking code.
217   run_diablo_macro_check();
218 #endif
219   matrix_scan_keymap();
220 }
221
222 void led_set_user(uint8_t usb_led) {
223   led_set_keymap(usb_led);
224 }
225
226 void send_game_macro(const char *str) {
227   register_code(is_overwatch ? KC_BSPC : KC_ENTER);
228   unregister_code(is_overwatch ? KC_BSPC : KC_ENTER);
229   wait_ms(50);
230   send_string(str);
231   register_code(KC_ENTER);
232   unregister_code(KC_ENTER);
233 }
234
235 void persistent_default_layer_set(uint16_t default_layer) {
236   eeconfig_update_default_layer(default_layer);
237   default_layer_set(default_layer);
238 }
239
240 // Defines actions tor my global custom keycodes. Defined in drashna.h file
241 // Then runs the _keymap's recod handier if not processed here
242 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
243
244 #ifdef CONSOLE_ENABLE
245   xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
246 #endif
247
248 #ifdef AUDIO_ENABLE
249   if (faux_click_enabled) {
250     if (record->event.pressed) {
251       PLAY_SONG(fauxclicky_pressed);
252     } else {
253       stop_note(NOTE_A6);
254       PLAY_SONG(fauxclicky_released);
255     }
256   }
257 #endif
258
259   switch (keycode) {
260   case KC_QWERTY:
261     if (record->event.pressed) {
262 #ifdef AUDIO_ENABLE
263       PLAY_SONG(tone_qwerty);
264 #endif
265       persistent_default_layer_set(1UL << _QWERTY);
266     }
267     return false;
268     break;
269   case KC_COLEMAK:
270     if (record->event.pressed) {
271 #ifdef AUDIO_ENABLE
272       PLAY_SONG(tone_colemak);
273 #endif
274       persistent_default_layer_set(1UL << _COLEMAK);
275     }
276     return false;
277     break;
278   case KC_DVORAK:
279     if (record->event.pressed) {
280 #ifdef AUDIO_ENABLE
281       PLAY_SONG(tone_dvorak);
282 #endif
283       persistent_default_layer_set(1UL << _DVORAK);
284     }
285     return false;
286     break;
287   case KC_WORKMAN:
288     if (record->event.pressed) {
289 #ifdef AUDIO_ENABLE
290       PLAY_SONG(tone_workman);
291 #endif
292       persistent_default_layer_set(1UL << _WORKMAN);
293     }
294     return false;
295     break;
296   case LOWER:
297     if (record->event.pressed) {
298       layer_on(_LOWER);
299       update_tri_layer(_LOWER, _RAISE, _ADJUST);
300     }
301     else {
302       layer_off(_LOWER);
303       update_tri_layer(_LOWER, _RAISE, _ADJUST);
304     }
305     return false;
306     break;
307   case RAISE:
308     if (record->event.pressed) {
309       layer_on(_RAISE);
310       update_tri_layer(_LOWER, _RAISE, _ADJUST);
311     }
312     else {
313       layer_off(_RAISE);
314       update_tri_layer(_LOWER, _RAISE, _ADJUST);
315     }
316     return false;
317     break;
318   case ADJUST:
319     if (record->event.pressed) {
320       layer_on(_ADJUST);
321     }
322     else {
323       layer_off(_ADJUST);
324     }
325     return false;
326     break;
327 #if !(defined(KEYBOARD_orthodox_rev1) || defined(KEYBOARD_orthodox_rev3) || defined(KEYBOARD_ergodox_ez))
328   case KC_OVERWATCH:
329     if (record->event.pressed) {
330       is_overwatch = !is_overwatch;
331     }
332 #ifdef RGBLIGHT_ENABLE
333     is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
334 #endif
335     return false;
336     break;
337   case KC_SALT:
338     if (!record->event.pressed) {
339       send_game_macro("Salt, salt, salt...");
340     }
341     return false;
342     break;
343   case KC_MORESALT:
344     if (!record->event.pressed) {
345       send_game_macro("Please sir, can I have some more salt?!");
346     }
347     return false;
348     break;
349   case KC_SALTHARD:
350     if (!record->event.pressed) {
351       send_game_macro("Your salt only makes me harder, and even more aggressive!");
352     }
353     return false;
354     break;
355   case KC_GOODGAME:
356     if (!record->event.pressed) {
357       send_game_macro("Good game, everyone!");
358     }
359     return false;
360     break;
361   case KC_GLHF:
362     if (!record->event.pressed) {
363       send_game_macro("Good luck, have fun!!!");
364     }
365     return false;
366     break;
367   case KC_SYMM:
368     if (!record->event.pressed) {
369       send_game_macro("Left click to win!");
370     }
371     return false;
372     break;
373   case KC_JUSTGAME:
374     if (!record->event.pressed) {
375       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.");
376     }
377     return false;
378     break;
379   case KC_TORB:
380     if (!record->event.pressed) {
381       send_game_macro("That was positively riveting!");
382     }
383     return false;
384     break;
385   case KC_AIM:
386     if (!record->event.pressed) {
387       send_game_macro("That aim is absolutely amazing. It's almost like you're a machine!");
388       wait_ms(3000);
389       send_game_macro("Wait! That aim is TOO good!  You're clearly using an aim hack! CHEATER!");
390     }
391     return false;
392     break;
393   case KC_C9:
394     if (!record->event.pressed) {
395       send_game_macro("OMG!!!  C9!!!");
396     }
397     return false;
398     break;
399   case KC_GGEZ:
400     if (!record->event.pressed) {
401       send_game_macro("That was a fantastic game, though it was a bit easy. Try harder next time!");
402     }
403     return false;
404     break;
405 #endif
406 #ifdef TAP_DANCE_ENABLE
407   case KC_DIABLO_CLEAR:  // reset all Diable timers, disabling them
408     if (record->event.pressed) {
409       uint8_t dtime;
410
411       for (dtime = 0; dtime < 4; dtime++) {
412         diablo_key_time[dtime] = diablo_times[0];
413       }
414     }
415     return false;
416     break;
417 #endif
418   case KC_MAKE:
419     if (!record->event.pressed) {
420       SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP
421 #if  (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
422        ":dfu"
423 #elif defined(BOOTLOADER_HALFKAY)
424       ":teensy"
425 //#elif defined(BOOTLOADER_CATERINA)
426 //       ":avrdude"
427 #endif
428         SS_TAP(X_ENTER));
429     }
430     return false;
431     break;
432   case KC_RESET:
433     if (!record->event.pressed) {
434 #ifdef RGBLIGHT_ENABLE
435       rgblight_enable();
436       rgblight_mode(1);
437       rgblight_setrgb(0xff, 0x00, 0x00);
438 #endif
439       reset_keyboard();
440     }
441     return false;
442     break;
443   case EPRM:
444     if (record->event.pressed) {
445       eeconfig_init();
446     }
447     return false;
448     break;
449   case VRSN:
450     if (record->event.pressed) {
451       SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION);
452     }
453     return false;
454     break;
455   case KC_SECRET_1 ... KC_SECRET_5:
456     if (!record->event.pressed) {
457       send_string_P(secret[keycode - KC_SECRET_1]);
458     }
459     return false;
460     break;
461   case KC_FXCL:
462     if (!record->event.pressed) {
463       faux_click_enabled = !faux_click_enabled;
464     }
465     return false;
466     break;
467   case KC_RGB_T:  // Because I want the option to go back to normal RGB mode rather than always layer indication
468 #ifdef RGBLIGHT_ENABLE
469     if (record->event.pressed) {
470       rgb_layer_change = !rgb_layer_change;
471     }
472 #endif
473     return false;
474     break;
475 #ifdef RGBLIGHT_ENABLE
476   case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
477     if (record->event.pressed) { //This disrables layer indication, as it's assumed that if you're changing this ... you want that disabled
478       rgb_layer_change = false;
479     }
480     return true;
481     break;
482 #endif
483   }
484   return process_record_keymap(keycode, record);
485 }
486
487 // Runs state check and changes underglow color and animation
488 // on layer change, no matter where the change was initiated
489 // Then runs keymap's layer change check
490 uint32_t layer_state_set_user(uint32_t state) {
491 #ifdef RGBLIGHT_ENABLE
492   uint8_t default_layer = eeconfig_read_default_layer();
493   if (rgb_layer_change) {
494     switch (biton32(state)) {
495     case _NAV:
496       rgblight_set_blue;
497       rgblight_mode(1);
498       break;
499     case _SYMB:
500       rgblight_set_blue;
501       rgblight_mode(2);
502       break;
503     case _MOUS:
504       rgblight_set_yellow;
505       rgblight_mode(1);
506       break;
507     case _MACROS:
508       rgblight_set_orange;
509       is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
510       break;
511     case _MEDIA:
512       rgblight_set_chartreuse;
513       rgblight_mode(22);
514       break;
515     case _GAMEPAD:
516       rgblight_set_orange;
517       rgblight_mode(17);
518       break;
519     case _DIABLO:
520       rgblight_set_red;
521       rgblight_mode(5);
522       break;
523     case _RAISE:
524       rgblight_set_yellow;
525       rgblight_mode(5);
526       break;
527     case _LOWER:
528       rgblight_set_orange;
529       rgblight_mode(5);
530       break;
531     case _ADJUST:
532       rgblight_set_red;
533       rgblight_mode(23);
534       break;
535     case _COVECUBE:
536       rgblight_set_green;
537       rgblight_mode(2);
538       break;
539     default:
540       if (default_layer & (1UL << _COLEMAK)) {
541         rgblight_set_magenta;
542       }
543       else if (default_layer & (1UL << _DVORAK)) {
544         rgblight_set_green;
545       }
546       else if (default_layer & (1UL << _WORKMAN)) {
547         rgblight_set_goldenrod;
548       }
549       else {
550         rgblight_set_teal;
551       }
552       if (biton32(state) == _MODS) {
553         rgblight_mode(2);
554       } else {
555         rgblight_mode(1);
556       }
557       break;
558     }
559   }
560 #endif
561   return layer_state_set_keymap (state);
562 }
563
564