1 #ifndef ZACH_COMMON_FUNCTIONS
2 #define ZACH_COMMON_FUNCTIONS
4 #include "action_layer.h"
5 #include "keymap_colemak.h"
6 extern keymap_config_t keymap_config;
8 // Fillers to make layering more clear
9 #define _______ KC_TRNS
12 #define CADKEY RCTL(RALT(KC_DEL))
14 void tap(uint16_t keycode){
15 register_code(keycode);
16 unregister_code(keycode);
19 void persistant_default_layer_set(uint16_t default_layer){
20 eeconfig_update_default_layer(default_layer);
21 default_layer_set(default_layer);
24 // Automatic number generation of important keywords
33 // These use process_record_user()
66 float tone_startup[][2] = SONG(STARTUP_SOUND);
67 float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
68 float tone_colemak[][2] = SONG(COLEMAK_SOUND);
69 float tone_swcole[][2] = SONG(QWERTY_SOUND);
70 float tone_capslock_on[][2] = SONG(CAPS_LOCK_ON_SOUND);
71 float tone_capslock_off[][2] = SONG(CAPS_LOCK_OFF_SOUND);
72 float tone_ctrl_mod[][2] = SONG(COIN_SOUND);
73 float tone_copy[][2] = SONG(SCROLL_LOCK_ON_SOUND);
74 float tone_paste[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
75 float uniwin[][2] = SONG(UNICODE_WINDOWS);
76 float unilin[][2] = SONG(UNICODE_LINUX);
79 #ifdef TAP_DANCE_ENABLE
80 #define TAPPING_TERM 200
82 uint8_t Lstate = 0, Rstate = 0;
83 uint32_t Ltimer = 0, Rtimer = 0;
84 uint32_t Ltimes[3], Rtimes[4]; // Ratio of tap times should be about 1.335 (L/R)
85 void rhythm_parse(void){
86 int L = Ltimes[0] + Ltimes[1] + Ltimes[2]; // Start to end time
87 int R = Rtimes[0] + Rtimes[1] + Rtimes[2] + Rtimes[3];
92 L = (L / 3)*100; // Average time per tap * 100
94 if(abs(abs(L/R)-133) > 1){
105 void dance_raise_press(qk_tap_dance_state_t *state, void *user_data){// Called on each tap
106 switch(state->count){ // Only turn the layer on once
108 layer_off(_UNICODES);
110 update_tri_layer(_LOWER, _RAISE, _ADJUST);
114 void dance_raise_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on release
115 switch(state->count){
116 case 1: // Normal action. Turn off layers
118 update_tri_layer(_LOWER, _RAISE, _ADJUST);
119 layer_off(_UNICODES);
123 /////////////////////////////////////////////////////////////////////
124 void dance_lower_press(qk_tap_dance_state_t *state, void *user_data){// Called on tap
125 switch(state->count){
126 case 1: // Turn on lower
127 layer_off(_UNICODES);
129 update_tri_layer(_LOWER, _RAISE, _ADJUST);
133 void dance_lower_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on release
134 switch(state->count){
135 case 1: // Normal action. Turn off layers
137 update_tri_layer(_LOWER, _RAISE, _ADJUST);
138 layer_off(_UNICODES);
140 case 2: // Turn on _UNICODES layer
142 update_tri_layer(_LOWER, _RAISE, _ADJUST);
145 PLAY_NOTE_ARRAY(tone_ctrl_mod, false, 0);
150 /////////////////////////////////////////////////////////////////////
151 void dance_super_press(qk_tap_dance_state_t *state, void *user_data){ // Called on down
152 if(state->count == 1){
153 register_code(KC_LGUI);
156 void dance_super_done(qk_tap_dance_state_t *state, void *user_data){ // Called on timeout
157 switch(state->count){
159 register_code(KC_LGUI);
161 unregister_code(KC_LGUI);
165 void dance_super_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on up
166 unregister_code(KC_LGUI);
169 qk_tap_dance_action_t tap_dance_actions[] = {
170 [RAI] = ACTION_TAP_DANCE_FN_ADVANCED(dance_raise_press, NULL, dance_raise_lift),
171 [LOW] = ACTION_TAP_DANCE_FN_ADVANCED(dance_lower_press, NULL, dance_lower_lift),
172 [SUP] = ACTION_TAP_DANCE_FN_ADVANCED(dance_super_press, dance_super_done, dance_super_lift)
176 #ifdef UNICODE_ENABLE
178 #define IBANG UC(0x203D)
179 #define RAROW UC(0x2192)
180 #define LAROW UC(0x2190)
181 #define DEGREE UC(0x00B0)
182 #define OMEGA UC(0x03A9)
183 #define WOMEGA UC(0x03C9)
184 #define MICRO UC(0x00B5)
185 #define PLUMIN UC(0x00B1)
186 #define SUPA2 UC(0x00B2)
187 #define ROMAN1 UC(0x2160)
188 #define ROMAN2 UC(0x2161)
189 #define ROMAN3 UC(0x2162)
190 #define ROMAN4 UC(0x2163)
191 #define ROMAN5 UC(0x2164)
192 #define ROMAN6 UC(0x2165)
193 #define ROMAN7 UC(0x2166)
194 #define roman1 UC(0x2170)
195 #define roman2 UC(0x2171)
196 #define roman3 UC(0x2172)
197 #define roman4 UC(0x2173)
198 #define roman5 UC(0x2174)
199 #define roman6 UC(0x2175)
200 #define roman7 UC(0x2176)
202 #ifdef UNICODEMAP_ENABLE // For Unicode characters larger than 0x8000. Send with X(<unicode>)
211 const uint32_t PROGMEM unicode_map[] = {
219 #define PENGY X(PENGUIN)
220 #define BOARY X(BOAR)
221 #define MNKY X(MONKEY)
222 #define DRGN X(DRAGON)
223 #define DUCK X(CHICK)
224 #define TMBL X(TUMBLER)
229 static uint16_t key_timer;
230 static uint8_t caps_status = 0;
231 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
234 if(record->event.pressed){
235 persistant_default_layer_set(1UL<<_COLEMAK);
237 PLAY_NOTE_ARRAY(tone_colemak, false, 0);
243 if(record->event.pressed){
244 persistant_default_layer_set(1UL<<_SWCOLE);
246 PLAY_NOTE_ARRAY(tone_swcole, false, 0);
252 if(record->event.pressed){
254 update_tri_layer(_LOWER, _RAISE, _ADJUST);
257 update_tri_layer(_LOWER, _RAISE, _ADJUST);
262 if(record->event.pressed){
264 update_tri_layer(_LOWER, _RAISE, _ADJUST);
267 update_tri_layer(_LOWER, _RAISE, _ADJUST);
272 if(record->event.pressed){
273 key_timer = timer_read(); // if the key is being pressed, we start the timer.
274 register_code(KC_LSHIFT);
275 } else { // this means the key was just released (tap or "held down")
276 if(timer_elapsed(key_timer) < 152){ // Time in ms, the threshold we pick for counting something as a tap.
278 if(caps_status == 0){
281 PLAY_NOTE_ARRAY(tone_capslock_on, false, 0);
286 PLAY_NOTE_ARRAY(tone_capslock_off, false, 0);
290 unregister_code(KC_LSHIFT);
294 case CTRLB: // Control-B on tap (bold)
295 if(record->event.pressed){
296 key_timer = timer_read(); // if the key is being pressed, we start the timer.
297 register_code(KC_LCTL);
298 } else { // this means the key was just released (tap or "held down")
299 if (timer_elapsed(key_timer) < 152) { // Time in ms, the threshold we pick for counting something as a tap.
302 PLAY_NOTE_ARRAY(tone_ctrl_mod, false, 0);
304 #ifdef BACKLIGHT_BREATHING
305 breathing_speed_set(2);
309 unregister_code(KC_LCTL);
313 case CPYPST: // One key copy/paste
314 if(record->event.pressed){
315 key_timer = timer_read();
317 if (timer_elapsed(key_timer) > 152) { // Hold, copy
318 register_code(KC_LCTL);
320 unregister_code(KC_LCTL);
322 PLAY_NOTE_ARRAY(tone_copy, false, 0);
324 } else { // Tap, paste
325 register_code(KC_LCTL);
327 unregister_code(KC_LCTL);
329 PLAY_NOTE_ARRAY(tone_paste, false, 0);
335 #ifdef UNICODE_ENABLE
337 if(record->event.pressed){
338 set_unicode_input_mode(UC_WIN);
340 PLAY_NOTE_ARRAY(uniwin, false, 0);
346 if(record->event.pressed){
347 set_unicode_input_mode(UC_LNX);
349 PLAY_NOTE_ARRAY(unilin, false, 0);
355 if(record->event.pressed){
356 process_unicode((0x0CA0|QK_UNICODE), record); // Eye
357 register_code(KC_RSFT);
359 unregister_code(KC_RSFT);
360 process_unicode((0x0CA0|QK_UNICODE), record); // Eye
364 case TFLIP: // (╯°□°)╯ ︵ ┻━┻
365 if(record->event.pressed){
366 register_code(KC_RSFT);
368 unregister_code(KC_RSFT);
369 process_unicode((0x256F|QK_UNICODE), record); // Arm
370 process_unicode((0x00B0|QK_UNICODE), record); // Eye
371 process_unicode((0x25A1|QK_UNICODE), record); // Mouth
372 process_unicode((0x00B0|QK_UNICODE), record); // Eye
373 register_code(KC_RSFT);
375 unregister_code(KC_RSFT);
376 process_unicode((0x256F|QK_UNICODE), record); // Arm
378 process_unicode((0x0361|QK_UNICODE), record); // Flippy
380 process_unicode((0x253B|QK_UNICODE), record); // Table
381 process_unicode((0x2501|QK_UNICODE), record); // Table
382 process_unicode((0x253B|QK_UNICODE), record); // Table
386 case TPUT: // ┬──┬ ノ( ゜-゜ノ)
387 if(record->event.pressed){
388 process_unicode((0x252C|QK_UNICODE), record); // Table
389 process_unicode((0x2500|QK_UNICODE), record); // Table
390 process_unicode((0x2500|QK_UNICODE), record); // Table
391 process_unicode((0x252C|QK_UNICODE), record); // Table
393 process_unicode((0x30CE|QK_UNICODE), record); // Arm
394 register_code(KC_RSFT);
396 unregister_code(KC_RSFT);
398 process_unicode((0x309C|QK_UNICODE), record); // Eye
400 process_unicode((0x309C|QK_UNICODE), record); // Eye
401 process_unicode((0x30CE|QK_UNICODE), record); // Arm
402 register_code(KC_RSFT);
404 unregister_code(KC_RSFT);
408 case SHRUG: // ¯\_(ツ)_/¯
409 if(record->event.pressed){
410 process_unicode((0x00AF|QK_UNICODE), record); // Hand
412 register_code(KC_RSFT);
414 tap(KC_LPRN); // Head
415 unregister_code(KC_RSFT);
416 process_unicode((0x30C4|QK_UNICODE), record); // Face
417 register_code(KC_RSFT);
418 tap(KC_RPRN); // Head
420 unregister_code(KC_RSFT);
422 process_unicode((0x00AF|QK_UNICODE), record); // Hand
428 if(record->event.pressed){
429 register_code(KC_RSFT);
431 unregister_code(KC_RSFT);
433 register_code(KC_RSFT);
437 unregister_code(KC_RSFT);
442 if (record->event.pressed) {
451 void matrix_init_user(void){ // Run once at startup
453 _delay_ms(50); // gets rid of tick
454 PLAY_NOTE_ARRAY(tone_startup, false, 0);
459 void play_goodbye_tone(void){
460 PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
464 void shutdown_user(){
465 PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
470 void music_on_user(void){ // Run when the music layer is turned on
471 PLAY_NOTE_ARRAY(tone_startup, false, 0);
474 void music_off_user(void){ // Run when music is turned off
475 PLAY_NOTE_ARRAY(tone_goodbye, false, 0);