]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/handwired/woodpad/keymaps/drashna/keymap.c
Updated personal keymaps (#1945)
[qmk_firmware.git] / keyboards / handwired / woodpad / keymaps / drashna / keymap.c
1 /* Copyright 2017 REPLACE_WITH_YOUR_NAME
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16 #include "woodpad.h"
17
18 // Each layer gets a name for readability, which is then used in the keymap matrix below.
19 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
20 // Layer names don't all need to be of the same length, obviously, and you can also skip them
21 // entirely and just use numbers.
22 #define _NUMLOCK 0
23 #define _NAV 1
24 #define _DIABLO 2
25 #define _MACROS 3
26 #define _MEDIA 4
27
28 // Fillers to make layering more clear
29 #define _______ KC_TRNS
30 #define XXXXXXX KC_NO
31
32 #ifdef RGBLIGHT_ENABLE
33 #define rgblight_set_blue        rgblight_sethsv (0xFF,  0xFF, 0xFF);
34 #define rgblight_set_red         rgblight_sethsv (0x00,  0xFF, 0xFF);
35 #define rgblight_set_green       rgblight_sethsv (0x78,  0xFF, 0xFF);
36 #define rgblight_set_orange      rgblight_sethsv (0x1E,  0xFF, 0xFF);
37 #define rgblight_set_teal        rgblight_sethsv (0xC3,  0xFF, 0xFF);
38 #define rgblight_set_magenta     rgblight_sethsv (0x12C, 0xFF, 0xFF);
39 #define rgblight_set_yellow      rgblight_sethsv (0x3C,  0xFF, 0xFF);
40 #define rgblight_set_purple      rgblight_sethsv (0x10E, 0xFF, 0xFF);
41 #endif
42
43 //define layer change stuff for underglow indicator
44 bool skip_leds = false;
45
46 bool is_overwatch = false;
47
48
49 #ifdef TAP_DANCE_ENABLE
50 //define diablo macro timer variables
51 static uint16_t diablo_timer[4];
52 static uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 };
53 static uint8_t diablo_key_time[4];
54
55
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;
59 };
60 #endif
61
62
63 enum custom_keycodes {
64     PLACEHOLDER = SAFE_RANGE, // can always be here
65     KC_DIABLO_CLEAR,
66     KC_OVERWATCH,
67     KC_SALT,
68     KC_MORESALT,
69     KC_SALTHARD,
70     KC_GOODGAME,
71     KC_SYMM,
72     KC_DOOMFIST,
73     KC_JUSTGAME,
74     KC_GLHF,
75     KC_TORB,
76     KC_MAKE
77 };
78
79 #ifdef TAP_DANCE_ENABLE
80 enum {
81     TD_DIABLO_1 = 0,
82     TD_DIABLO_2,
83     TD_DIABLO_3,
84     TD_DIABLO_4
85 };
86
87
88 // Cycle through the times for the macro, starting at 0, for disabled.
89 // Max of six values, so don't exceed
90 void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data, uint8_t diablo_key) {
91     if (state->count >= 7) {
92         diablo_key_time[diablo_key] = diablo_times[0];
93         reset_tap_dance(state);
94     }
95     else {
96         diablo_key_time[diablo_key] = diablo_times[state->count - 1];
97     }
98 }
99
100
101 // Would rather have one function for all of this, but no idea how to do that...
102 void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) {
103     diablo_tapdance_master(state, user_data, 0);
104 }
105
106 void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) {
107     diablo_tapdance_master(state, user_data, 1);
108 }
109
110 void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) {
111     diablo_tapdance_master(state, user_data, 2);
112 }
113
114 void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) {
115     diablo_tapdance_master(state, user_data, 3);
116 }
117
118
119
120 //Tap Dance Definitions
121 qk_tap_dance_action_t tap_dance_actions[] = {
122     // tap once to disable, and more to enable timed micros
123     [TD_DIABLO_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1),
124     [TD_DIABLO_2] = ACTION_TAP_DANCE_FN(diablo_tapdance2),
125     [TD_DIABLO_3] = ACTION_TAP_DANCE_FN(diablo_tapdance3),
126     [TD_DIABLO_4] = ACTION_TAP_DANCE_FN(diablo_tapdance4),
127
128 };
129 #endif
130
131 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
132 [_NUMLOCK] = KEYMAP( /* Base */
133     TG(_NAV), TG(_DIABLO), TG(_MACROS), KC_PSLS,\
134     KC_P7,  KC_P8, KC_P9, KC_PAST,   \
135     KC_P4,  KC_P5, KC_P6, KC_PMNS,   \
136     KC_P1,  KC_P2, KC_P3, KC_PPLS,   \
137     LT(_MEDIA,KC_P0), KC_PDOT, KC_COLN, KC_PENT   \
138 ),
139 [_NAV] = KEYMAP( /* Base */
140     _______, _______, _______, _______,\
141     KC_HOME,  KC_UP, KC_PGUP, _______,   \
142     KC_LEFT,  XXXXXXX, KC_RIGHT, _______,   \
143     KC_END,  KC_DOWN, KC_PGDN, _______,   \
144     KC_INS, KC_DEL, _______, _______   \
145 ),
146 #ifdef TAP_DANCE_ENABLE
147 [_DIABLO] = KEYMAP( /* Base */
148     KC_ESC, _______, _______, _______,\
149     KC_S, KC_F, KC_I, KC_M,   \
150     KC_1, KC_2, KC_3, KC_4, \
151     TD(TD_DIABLO_1), TD(TD_DIABLO_2), TD(TD_DIABLO_3), TD(TD_DIABLO_4), \
152     _______, KC_DIABLO_CLEAR, KC_Q, SFT_T(KC_SPACE)  \
153 ),
154 #else
155 [_DIABLO] = KEYMAP( /* Base */
156     KC_ESC, _______, _______, _______,\
157     KC_S, KC_F, KC_I, KC_M,   \
158     KC_1, KC_2, KC_3, KC_4, \
159     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
160     _______, KC_DIABLO_CLEAR, KC_Q, SFT_T(KC_SPACE)  \
161 ),
162
163 #endif
164
165 [_MACROS] = KEYMAP( /* Base */
166     KC_OVERWATCH, _______, _______, XXXXXXX,\
167     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,   \
168     XXXXXXX, XXXXXXX, XXXXXXX, KC_JUSTGAME,   \
169     KC_SYMM,  KC_DOOMFIST, KC_TORB, KC_GOODGAME,   \
170     KC_SALT,  KC_MORESALT, KC_SALTHARD, KC_GLHF   \
171 ),
172 [_MEDIA] = KEYMAP( /* Base */
173     RESET, KC_MUTE, KC_VOLD, KC_VOLU,\
174     KC_MAKE, _______, RGB_HUI, RGB_HUD,   \
175     KC_MPLY, KC_MSTP, KC_MPRV, KC_MNXT,   \
176     RGB_TOG, RGB_MOD, RGB_SAI, RGB_VAI,   \
177     _______, _______, RGB_SAD, RGB_VAD   \
178 ),
179
180 };
181
182
183 void numlock_led_on(void) {
184   PORTF |= (1<<7);
185 }
186
187 void numlock_led_off(void) {
188   PORTF &= ~(1<<7);
189 }
190
191
192 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
193     uint16_t kc;
194     if (is_overwatch) {
195         kc = KC_BSPC;
196     } else {
197         kc = KC_ENTER;
198     }
199     switch (keycode) {
200 #ifdef TAP_DANCE_ENABLE
201     case KC_DIABLO_CLEAR:  // reset all Diable timers, disabling them
202             if (record->event.pressed) {
203                 uint8_t dtime;
204
205                 for (dtime = 0; dtime < 4; dtime++) {
206                     diablo_key_time[dtime] = diablo_times[0];
207                 }
208             }
209             return false;
210             break;
211 #endif
212         case KC_OVERWATCH:
213             if (record->event.pressed) {
214                 is_overwatch = !is_overwatch;
215             }
216 #ifdef RGBLIGHT_ENABLE
217             is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
218 #endif
219             return false;
220             break;
221         case KC_SALT:
222             if (!record->event.pressed) {
223                 register_code(kc);
224                 unregister_code(kc);
225                 _delay_ms(50);
226                 SEND_STRING("Salt, salt, salt...");
227                 register_code(KC_ENTER);
228                 unregister_code(KC_ENTER);
229             }
230             return false;
231             break;
232         case KC_MORESALT:
233             if (!record->event.pressed) {
234                 register_code(kc);
235                 unregister_code(kc);
236                 _delay_ms(50);
237                 SEND_STRING("Please sir, can I have some more salt?!");
238                 register_code(KC_ENTER);
239                 unregister_code(KC_ENTER);
240             }
241             return false;
242             break;
243         case KC_SALTHARD:
244             if (!record->event.pressed) {
245                 register_code(kc);
246                 unregister_code(kc);
247                 _delay_ms(50);
248                 SEND_STRING("Your salt only makes my penis that much harder, and even more aggressive!");
249                 register_code(KC_ENTER);
250                 unregister_code(KC_ENTER);
251             }
252             return false;
253             break;
254         case KC_GOODGAME:
255             if (!record->event.pressed) {
256                 register_code(kc);
257                 unregister_code(kc);
258                 _delay_ms(50);
259                 SEND_STRING("Good game, everyone!");
260                 register_code(KC_ENTER);
261                 unregister_code(KC_ENTER);
262             }
263             return false;
264             break;
265         case KC_GLHF:
266             if (!record->event.pressed) {
267                 register_code(kc);
268                 unregister_code(kc);
269                 _delay_ms(50);
270                 SEND_STRING("Good luck, have fun!!!");
271                 register_code(KC_ENTER);
272                 unregister_code(KC_ENTER);
273             }
274             return false;
275             break;
276         case KC_SYMM:
277             if (!record->event.pressed) {
278                 register_code(kc);
279                 unregister_code(kc);
280                 _delay_ms(50);
281                 SEND_STRING("Left click to win!");
282                 register_code(KC_ENTER);
283                 unregister_code(KC_ENTER);
284             }
285             return false;
286             break;
287         case KC_DOOMFIST:
288             if (!record->event.pressed) {
289                 register_code(kc);
290                 unregister_code(kc);
291                 _delay_ms(50);
292                 SEND_STRING("Hey, look at me.  I'm Doomfist, and I'm overpowered!  All I do is spam punches all day!   I'm DPS, tank and defense, rolled into one! All I need is team healing to be complete!");
293                 register_code(KC_ENTER);
294                 unregister_code(KC_ENTER);
295             }
296             return false;
297             break;
298         case KC_JUSTGAME:
299
300             if (!record->event.pressed) {
301                 register_code(kc);
302                 unregister_code(kc);
303                 _delay_ms(50);
304                 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.");
305                 register_code(KC_ENTER);
306                 unregister_code(KC_ENTER);
307             }
308             return false;
309             break;
310         case KC_TORB:
311
312             if (!record->event.pressed) {
313                 register_code(kc);
314                 unregister_code(kc);
315                 _delay_ms(50);
316                 SEND_STRING("That was positively riveting!");
317                 register_code(KC_ENTER);
318                 unregister_code(KC_ENTER);
319             }
320             return false;
321             break;
322         case KC_MAKE:
323             if (!record->event.pressed) {
324                 SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP SS_TAP(X_ENTER));
325             }
326             return false;
327             break;
328
329
330   }
331   return true;
332 }
333 #ifdef TAP_DANCE_ENABLE
334
335 // Sends the key press to system, but only if on the Diablo layer
336 void send_diablo_keystroke(uint8_t diablo_key) {
337     if (biton32(layer_state) == _DIABLO) {
338         switch (diablo_key) {
339         case 0:
340             SEND_STRING("1");
341             break;
342         case 1:
343             SEND_STRING("2");
344             break;
345         case 2:
346             SEND_STRING("3");
347             break;
348         case 3:
349             SEND_STRING("4");
350             break;
351         }
352     }
353 }
354
355 // Checks each of the 4 timers/keys to see if enough time has elapsed
356 // Runs the "send string" command if enough time has passed, and resets the timer.
357 void run_diablo_macro_check(void) {
358     uint8_t dtime;
359
360     for (dtime = 0; dtime < 4; dtime++) {
361         if (check_dtimer(dtime) && diablo_key_time[dtime]) {
362             diablo_timer[dtime] = timer_read();
363             send_diablo_keystroke(dtime);
364         }
365     }
366
367 }
368 #endif
369 void matrix_init_user(void) {
370     // set Numlock LED to output and low
371     DDRF |= (1<<7);
372     PORTF &= ~(1<<7);
373
374 #ifdef RGBLIGHT_ENABLE
375     rgblight_enable();
376     rgblight_set_teal;
377     rgblight_mode(1);
378 #endif
379
380     if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) ){
381         register_code(KC_NUMLOCK);
382         unregister_code(KC_NUMLOCK);
383     }
384 }
385
386 void matrix_scan_user(void) {
387     numlock_led_off();
388     if (is_overwatch && biton32(layer_state) == _MACROS) {
389         numlock_led_on();
390     }
391
392     // Run Diablo 3 macro checking code.
393 #ifdef TAP_DANCE_ENABLE
394     run_diablo_macro_check();
395 #endif
396 }
397
398 uint32_t layer_state_set_kb(uint32_t state) {
399 #ifdef RGBLIGHT_ENABLE
400 // Check layer, and apply color if its changed since last check
401     switch (biton32(state)) {
402     case _NAV:
403         rgblight_set_blue;
404         rgblight_mode(1);
405         break;
406     case _MACROS:
407         rgblight_set_orange;
408         is_overwatch ? rgblight_mode(17) : rgblight_mode(18);
409         break;
410     case _DIABLO:
411         rgblight_set_red;
412         rgblight_mode(5);
413         break;
414     case _MEDIA:
415         rgblight_set_green;
416         rgblight_mode(22);
417         break;
418     default:
419         rgblight_set_teal;
420         rgblight_mode(1);
421         break;
422     }
423
424 #endif
425     return state;
426 }
427 void led_set_user(uint8_t usb_led) {
428     
429 }