1 #ifndef ZACH_COMMON_FUNCTIONS
2 #define ZACH_COMMON_FUNCTIONS
4 #include "action_layer.h"
5 #include "keymap_colemak.h"
6 #include "extra_functions.c"
7 extern keymap_config_t keymap_config;
9 // Fillers to make layering more clear
10 #define _______ KC_TRNS
13 #define CADKEY RCTL(RALT(KC_DEL))
15 void tap(uint16_t keycode){
16 register_code(keycode);
17 unregister_code(keycode);
20 void persistant_default_layer_set(uint16_t default_layer){
21 eeconfig_update_default_layer(default_layer);
22 default_layer_set(default_layer);
25 // Automatic number generation of important keywords
34 // These use process_record_user()
67 float tone_startup[][2] = SONG(STARTUP_SOUND);
68 float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
69 float tone_colemak[][2] = SONG(COLEMAK_SOUND);
70 float tone_swcole[][2] = SONG(QWERTY_SOUND);
71 float tone_capslock_on[][2] = SONG(CAPS_LOCK_ON_SOUND);
72 float tone_capslock_off[][2] = SONG(CAPS_LOCK_OFF_SOUND);
73 float tone_ctrl_mod[][2] = SONG(COIN_SOUND);
74 float tone_copy[][2] = SONG(SCROLL_LOCK_ON_SOUND);
75 float tone_paste[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
76 float uniwin[][2] = SONG(UNICODE_WINDOWS);
77 float unilin[][2] = SONG(UNICODE_LINUX);
80 #ifdef TAP_DANCE_ENABLE
81 #define TAPPING_TERM 200
83 uint8_t Lstate = 0, Rstate = 0;
84 uint32_t Ltimer = 0, Rtimer = 0;
85 uint32_t Ltimes[3], Rtimes[4]; // Ratio of tap times should be about 1.335 (L/R)
86 void rhythm_parse(void){
87 int L = Ltimes[0] + Ltimes[1] + Ltimes[2]; // Start to end time
88 int R = Rtimes[0] + Rtimes[1] + Rtimes[2] + Rtimes[3];
93 L = (L / 3)*100; // Average time per tap * 100
95 if(abs(abs(L/R)-133) > 1){
100 tap(KC_O); tap(KC_K);
106 void dance_raise_press(qk_tap_dance_state_t *state, void *user_data){// Called on each tap
107 switch(state->count){ // Only turn the layer on once
109 layer_off(_UNICODES);
111 update_tri_layer(_LOWER, _RAISE, _ADJUST);
115 void dance_raise_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on release
116 switch(state->count){
117 case 1: // Normal action. Turn off layers
119 update_tri_layer(_LOWER, _RAISE, _ADJUST);
120 layer_off(_UNICODES);
124 /////////////////////////////////////////////////////////////////////
125 void dance_lower_press(qk_tap_dance_state_t *state, void *user_data){// Called on tap
126 switch(state->count){
127 case 1: // Turn on lower
128 layer_off(_UNICODES);
130 update_tri_layer(_LOWER, _RAISE, _ADJUST);
134 void dance_lower_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on release
135 switch(state->count){
136 case 1: // Normal action. Turn off layers
138 update_tri_layer(_LOWER, _RAISE, _ADJUST);
139 layer_off(_UNICODES);
141 case 2: // Turn on _UNICODES layer
143 update_tri_layer(_LOWER, _RAISE, _ADJUST);
146 PLAY_NOTE_ARRAY(tone_ctrl_mod, false, 0);
151 /////////////////////////////////////////////////////////////////////
152 void dance_super_press(qk_tap_dance_state_t *state, void *user_data){ // Called on down
153 if(state->count == 1){
154 register_code(KC_LGUI);
157 void dance_super_done(qk_tap_dance_state_t *state, void *user_data){ // Called on timeout
158 switch(state->count){
160 register_code(KC_LGUI);
162 unregister_code(KC_LGUI);
166 void dance_super_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on up
167 unregister_code(KC_LGUI);
170 qk_tap_dance_action_t tap_dance_actions[] = {
171 [RAI] = ACTION_TAP_DANCE_FN_ADVANCED(dance_raise_press, NULL, dance_raise_lift),
172 [LOW] = ACTION_TAP_DANCE_FN_ADVANCED(dance_lower_press, NULL, dance_lower_lift),
173 [SUP] = ACTION_TAP_DANCE_FN_ADVANCED(dance_super_press, dance_super_done, dance_super_lift)
177 #ifdef UNICODE_ENABLE
179 #define IBANG UC(0x203D)
180 #define RAROW UC(0x2192)
181 #define LAROW UC(0x2190)
182 #define DEGREE UC(0x00B0)
183 #define OMEGA UC(0x03A9)
184 #define WOMEGA UC(0x03C9)
185 #define MICRO UC(0x00B5)
186 #define PLUMIN UC(0x00B1)
187 #define SUPA2 UC(0x00B2)
188 #define ROMAN1 UC(0x2160)
189 #define ROMAN2 UC(0x2161)
190 #define ROMAN3 UC(0x2162)
191 #define ROMAN4 UC(0x2163)
192 #define ROMAN5 UC(0x2164)
193 #define ROMAN6 UC(0x2165)
194 #define ROMAN7 UC(0x2166)
195 #define roman1 UC(0x2170)
196 #define roman2 UC(0x2171)
197 #define roman3 UC(0x2172)
198 #define roman4 UC(0x2173)
199 #define roman5 UC(0x2174)
200 #define roman6 UC(0x2175)
201 #define roman7 UC(0x2176)
203 #ifdef UNICODEMAP_ENABLE // For Unicode characters larger than 0x8000. Send with X(<unicode>)
212 const uint32_t PROGMEM unicode_map[] = {
220 #define PENGY X(PENGUIN)
221 #define BOARY X(BOAR)
222 #define MNKY X(MONKEY)
223 #define DRGN X(DRAGON)
224 #define DUCK X(CHICK)
225 #define TMBL X(TUMBLER)
230 static uint16_t key_timer;
231 static uint8_t caps_status = 0;
232 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
235 if(record->event.pressed){
236 persistant_default_layer_set(1UL<<_COLEMAK);
238 PLAY_NOTE_ARRAY(tone_colemak, false, 0);
244 if(record->event.pressed){
245 persistant_default_layer_set(1UL<<_SWCOLE);
247 PLAY_NOTE_ARRAY(tone_swcole, false, 0);
252 #ifndef TAP_DANCE_ENABLE
254 if(record->event.pressed){
256 update_tri_layer(_LOWER, _RAISE, _ADJUST);
259 update_tri_layer(_LOWER, _RAISE, _ADJUST);
264 if(record->event.pressed){
266 update_tri_layer(_LOWER, _RAISE, _ADJUST);
269 update_tri_layer(_LOWER, _RAISE, _ADJUST);
275 if(record->event.pressed){
276 key_timer = timer_read(); // if the key is being pressed, we start the timer.
277 register_code(KC_LSHIFT);
278 } else { // this means the key was just released (tap or "held down")
279 if(timer_elapsed(key_timer) < 152){ // Time in ms, the threshold we pick for counting something as a tap.
281 if(caps_status == 0){
284 PLAY_NOTE_ARRAY(tone_capslock_on, false, 0);
289 PLAY_NOTE_ARRAY(tone_capslock_off, false, 0);
293 unregister_code(KC_LSHIFT);
297 case CTRLB: // Control-B on tap (bold)
298 if(record->event.pressed){
299 key_timer = timer_read(); // if the key is being pressed, we start the timer.
300 register_code(KC_LCTL);
301 } else { // this means the key was just released (tap or "held down")
302 if (timer_elapsed(key_timer) < 152) { // Time in ms, the threshold we pick for counting something as a tap.
305 PLAY_NOTE_ARRAY(tone_ctrl_mod, false, 0);
307 #ifdef BACKLIGHT_BREATHING
308 breathing_speed_set(2);
312 unregister_code(KC_LCTL);
316 case CPYPST: // One key copy/paste
317 if(record->event.pressed){
318 key_timer = timer_read();
320 if (timer_elapsed(key_timer) > 152) { // Hold, copy
321 register_code(KC_LCTL);
323 unregister_code(KC_LCTL);
325 PLAY_NOTE_ARRAY(tone_copy, false, 0);
327 } else { // Tap, paste
328 register_code(KC_LCTL);
330 unregister_code(KC_LCTL);
332 PLAY_NOTE_ARRAY(tone_paste, false, 0);
338 #ifdef UNICODE_ENABLE
340 if(record->event.pressed){
341 set_unicode_input_mode(UC_WIN);
343 PLAY_NOTE_ARRAY(uniwin, false, 0);
349 if(record->event.pressed){
350 set_unicode_input_mode(UC_LNX);
352 PLAY_NOTE_ARRAY(unilin, false, 0);
358 if(record->event.pressed){
359 process_unicode((0x0CA0|QK_UNICODE), record); // Eye
360 register_code(KC_RSFT);
362 unregister_code(KC_RSFT);
363 process_unicode((0x0CA0|QK_UNICODE), record); // Eye
367 case TFLIP: // (╯°□°)╯ ︵ ┻━┻
368 if(record->event.pressed){
369 register_code(KC_RSFT);
371 unregister_code(KC_RSFT);
372 process_unicode((0x256F|QK_UNICODE), record); // Arm
373 process_unicode((0x00B0|QK_UNICODE), record); // Eye
374 process_unicode((0x25A1|QK_UNICODE), record); // Mouth
375 process_unicode((0x00B0|QK_UNICODE), record); // Eye
376 register_code(KC_RSFT);
378 unregister_code(KC_RSFT);
379 process_unicode((0x256F|QK_UNICODE), record); // Arm
381 process_unicode((0x0361|QK_UNICODE), record); // Flippy
383 process_unicode((0x253B|QK_UNICODE), record); // Table
384 process_unicode((0x2501|QK_UNICODE), record); // Table
385 process_unicode((0x253B|QK_UNICODE), record); // Table
389 case TPUT: // ┬──┬ ノ( ゜-゜ノ)
390 if(record->event.pressed){
391 process_unicode((0x252C|QK_UNICODE), record); // Table
392 process_unicode((0x2500|QK_UNICODE), record); // Table
393 process_unicode((0x2500|QK_UNICODE), record); // Table
394 process_unicode((0x252C|QK_UNICODE), record); // Table
396 process_unicode((0x30CE|QK_UNICODE), record); // Arm
397 register_code(KC_RSFT);
399 unregister_code(KC_RSFT);
401 process_unicode((0x309C|QK_UNICODE), record); // Eye
403 process_unicode((0x309C|QK_UNICODE), record); // Eye
404 process_unicode((0x30CE|QK_UNICODE), record); // Arm
405 register_code(KC_RSFT);
407 unregister_code(KC_RSFT);
411 case SHRUG: // ¯\_(ツ)_/¯
412 if(record->event.pressed){
413 process_unicode((0x00AF|QK_UNICODE), record); // Hand
415 register_code(KC_RSFT);
417 tap(KC_LPRN); // Head
418 unregister_code(KC_RSFT);
419 process_unicode((0x30C4|QK_UNICODE), record); // Face
420 register_code(KC_RSFT);
421 tap(KC_RPRN); // Head
423 unregister_code(KC_RSFT);
425 process_unicode((0x00AF|QK_UNICODE), record); // Hand
431 if(record->event.pressed){
432 register_code(KC_RSFT);
434 unregister_code(KC_RSFT);
436 register_code(KC_RSFT);
440 unregister_code(KC_RSFT);
444 #ifdef TAP_DANCE_ENABLE
446 if(record->event.pressed){
447 if(timer_elapsed32(Rtimer) > 1052){
452 Rtimer = timer_read32();
456 Rtimes[0] = timer_elapsed32(Rtimer);
457 Rtimer = timer_read32();
461 Rtimes[1] = timer_elapsed32(Rtimer);
462 Rtimer = timer_read32();
466 Rtimes[2] = timer_elapsed32(Rtimer);
470 if(Rstate == 0 && Lstate == 0) rhythm_parse();
475 if(record->event.pressed){
476 if(timer_elapsed32(Ltimer) > 1052){
481 Ltimer = timer_read32();
485 Ltimes[0] = timer_elapsed32(Ltimer);
486 Ltimer = timer_read32();
490 Ltimes[1] = timer_elapsed32(Ltimer);
494 if(Rstate == 0 && Lstate == 0) rhythm_parse();
501 if (record->event.pressed) {
511 void matrix_init_user(void){ // Run once at startup
513 _delay_ms(50); // gets rid of tick
514 PLAY_NOTE_ARRAY(tone_startup, false, 0);
518 void play_goodbye_tone(void){
519 PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
523 void shutdown_user(){
524 PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
529 void music_on_user(void){ // Run when the music layer is turned on
530 PLAY_NOTE_ARRAY(tone_startup, false, 0);
533 void music_off_user(void){ // Run when music is turned off
534 PLAY_NOTE_ARRAY(tone_goodbye, false, 0);