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()
57 float tone_startup[][2] = SONG(STARTUP_SOUND);
58 float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
59 float tone_colemak[][2] = SONG(COLEMAK_SOUND);
60 float tone_swcole[][2] = SONG(QWERTY_SOUND);
61 float tone_capslock_on[][2] = SONG(CAPS_LOCK_ON_SOUND);
62 float tone_capslock_off[][2] = SONG(CAPS_LOCK_OFF_SOUND);
63 float tone_ctrl_mod[][2] = SONG(COIN_SOUND);
64 float tone_copy[][2] = SONG(SCROLL_LOCK_ON_SOUND);
65 float tone_paste[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
66 float uniwin[][2] = SONG(UNICODE_WINDOWS);
67 float unilin[][2] = SONG(UNICODE_LINUX);
70 #ifdef TAP_DANCE_ENABLE
71 #define TAPPING_TERM 200
73 uint8_t Lstate = 0, Rstate = 0;
74 uint32_t Ltimer = 0, Rtimer = 0;
75 uint32_t Ltimes[3], Rtimes[4]; // Ratio of tap times should be about 1.335 (L/R)
76 void rhythm_parse(void){
77 int L = Ltimes[0] + Ltimes[1] + Ltimes[2]; // Start to end time
78 int R = Rtimes[0] + Rtimes[1] + Rtimes[2] + Rtimes[3];
83 L = (L / 3)*100; // Average time per tap * 100
85 if(abs(abs(L/R)-133) > 1){
96 void dance_raise_press(qk_tap_dance_state_t *state, void *user_data){// Called on each tap
97 switch(state->count){ // Only turn the layer on once
101 update_tri_layer(_LOWER, _RAISE, _ADJUST);
105 void dance_raise_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on release
106 switch(state->count){
107 case 1: // Normal action. Turn off layers
109 update_tri_layer(_LOWER, _RAISE, _ADJUST);
110 layer_off(_UNICODES);
114 /////////////////////////////////////////////////////////////////////
115 void dance_lower_press(qk_tap_dance_state_t *state, void *user_data){// Called on tap
116 switch(state->count){
117 case 1: // Turn on lower
118 layer_off(_UNICODES);
120 update_tri_layer(_LOWER, _RAISE, _ADJUST);
124 void dance_lower_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on release
125 switch(state->count){
126 case 1: // Normal action. Turn off layers
128 update_tri_layer(_LOWER, _RAISE, _ADJUST);
129 layer_off(_UNICODES);
131 case 2: // Turn on _UNICODES layer
133 update_tri_layer(_LOWER, _RAISE, _ADJUST);
136 PLAY_NOTE_ARRAY(tone_ctrl_mod, false, 0);
141 /////////////////////////////////////////////////////////////////////
142 void dance_super_press(qk_tap_dance_state_t *state, void *user_data){ // Called on down
143 if(state->count == 1){
144 register_code(KC_LGUI);
147 void dance_super_done(qk_tap_dance_state_t *state, void *user_data){ // Called on timeout
148 switch(state->count){
150 register_code(KC_LGUI);
152 unregister_code(KC_LGUI);
156 void dance_super_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on up
157 unregister_code(KC_LGUI);
160 qk_tap_dance_action_t tap_dance_actions[] = {
161 [RAI] = ACTION_TAP_DANCE_FN_ADVANCED(dance_raise_press, NULL, dance_raise_lift),
162 [LOW] = ACTION_TAP_DANCE_FN_ADVANCED(dance_lower_press, NULL, dance_lower_lift),
163 [SUP] = ACTION_TAP_DANCE_FN_ADVANCED(dance_super_press, dance_super_done, dance_super_lift)
167 #ifdef UNICODE_ENABLE
169 #define IBANG UC(0x203D)
170 #define RAROW UC(0x2192)
171 #define LAROW UC(0x2190)
172 #define DEGREE UC(0x00B0)
173 #define OMEGA UC(0x03A9)
174 #define WOMEGA UC(0x03C9)
175 #define MICRO UC(0x00B5)
176 #define PLUMIN UC(0x00B1)
177 #define SUPA2 UC(0x00B2)
178 #define ROMAN1 UC(0x2160)
179 #define ROMAN2 UC(0x2161)
180 #define ROMAN3 UC(0x2162)
181 #define ROMAN4 UC(0x2163)
182 #define ROMAN5 UC(0x2164)
183 #define ROMAN6 UC(0x2165)
184 #define ROMAN7 UC(0x2166)
185 #define roman1 UC(0x2170)
186 #define roman2 UC(0x2171)
187 #define roman3 UC(0x2172)
188 #define roman4 UC(0x2173)
189 #define roman5 UC(0x2174)
190 #define roman6 UC(0x2175)
191 #define roman7 UC(0x2176)
193 #ifdef UNICODEMAP_ENABLE // For Unicode characters larger than 0x8000. Send with X(<unicode>)
202 const uint32_t PROGMEM unicode_map[] = {
210 #define PENGY X(PENGUIN)
211 #define BOARY X(BOAR)
212 #define MNKY X(MONKEY)
213 #define DRGN X(DRAGON)
214 #define DUCK X(CHICK)
215 #define TMBL X(TUMBLER)
220 static uint16_t key_timer;
221 static uint8_t caps_status = 0;
222 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
225 if(record->event.pressed){
226 persistant_default_layer_set(1UL<<_COLEMAK);
228 PLAY_NOTE_ARRAY(tone_colemak, false, 0);
234 if(record->event.pressed){
235 persistant_default_layer_set(1UL<<_SWCOLE);
237 PLAY_NOTE_ARRAY(tone_swcole, false, 0);
243 if(record->event.pressed){
245 update_tri_layer(_LOWER, _RAISE, _ADJUST);
248 update_tri_layer(_LOWER, _RAISE, _ADJUST);
253 if(record->event.pressed){
255 update_tri_layer(_LOWER, _RAISE, _ADJUST);
258 update_tri_layer(_LOWER, _RAISE, _ADJUST);
263 if(record->event.pressed){
264 key_timer = timer_read(); // if the key is being pressed, we start the timer.
265 register_code(KC_LSHIFT);
266 } else { // this means the key was just released (tap or "held down")
267 if(timer_elapsed(key_timer) < 152){ // Time in ms, the threshold we pick for counting something as a tap.
269 if(caps_status == 0){
272 PLAY_NOTE_ARRAY(tone_capslock_on, false, 0);
277 PLAY_NOTE_ARRAY(tone_capslock_off, false, 0);
281 unregister_code(KC_LSHIFT);
285 case CTRLB: // Control-B on tap (bold)
286 if(record->event.pressed){
287 key_timer = timer_read(); // if the key is being pressed, we start the timer.
288 register_code(KC_LCTL);
289 } else { // this means the key was just released (tap or "held down")
290 if (timer_elapsed(key_timer) < 152) { // Time in ms, the threshold we pick for counting something as a tap.
293 PLAY_NOTE_ARRAY(tone_ctrl_mod, false, 0);
295 #ifdef BACKLIGHT_BREATHING
296 breathing_speed_set(2);
300 unregister_code(KC_LCTL);
304 case CPYPST: // One key copy/paste
305 if(record->event.pressed){
306 key_timer = timer_read();
308 if (timer_elapsed(key_timer) > 152) { // Hold, copy
309 register_code(KC_LCTL);
311 unregister_code(KC_LCTL);
313 PLAY_NOTE_ARRAY(tone_copy, false, 0);
315 } else { // Tap, paste
316 register_code(KC_LCTL);
318 unregister_code(KC_LCTL);
320 PLAY_NOTE_ARRAY(tone_paste, false, 0);
326 #ifdef UNICODE_ENABLE
328 if(record->event.pressed){
329 set_unicode_input_mode(UC_WIN);
331 PLAY_NOTE_ARRAY(uniwin, false, 0);
337 if(record->event.pressed){
338 set_unicode_input_mode(UC_LNX);
340 PLAY_NOTE_ARRAY(unilin, false, 0);
346 if(record->event.pressed){
347 process_unicode((0x0CA0|QK_UNICODE), record); // Eye
348 register_code(KC_RSFT);
350 unregister_code(KC_RSFT);
351 process_unicode((0x0CA0|QK_UNICODE), record); // Eye
355 case TFLIP: // (╯°□°)╯ ︵ ┻━┻
356 if(record->event.pressed){
357 register_code(KC_RSFT);
359 unregister_code(KC_RSFT);
360 process_unicode((0x256F|QK_UNICODE), record); // Arm
361 process_unicode((0x00B0|QK_UNICODE), record); // Eye
362 process_unicode((0x25A1|QK_UNICODE), record); // Mouth
363 process_unicode((0x00B0|QK_UNICODE), record); // Eye
364 register_code(KC_RSFT);
366 unregister_code(KC_RSFT);
367 process_unicode((0x256F|QK_UNICODE), record); // Arm
369 process_unicode((0x0361|QK_UNICODE), record); // Flippy
371 process_unicode((0x253B|QK_UNICODE), record); // Table
372 process_unicode((0x2501|QK_UNICODE), record); // Table
373 process_unicode((0x253B|QK_UNICODE), record); // Table
377 case TPUT: // ┬──┬ ノ( ゜-゜ノ)
378 if(record->event.pressed){
379 process_unicode((0x252C|QK_UNICODE), record); // Table
380 process_unicode((0x2500|QK_UNICODE), record); // Table
381 process_unicode((0x2500|QK_UNICODE), record); // Table
382 process_unicode((0x252C|QK_UNICODE), record); // Table
384 process_unicode((0x30CE|QK_UNICODE), record); // Arm
385 register_code(KC_RSFT);
387 unregister_code(KC_RSFT);
389 process_unicode((0x309C|QK_UNICODE), record); // Eye
391 process_unicode((0x309C|QK_UNICODE), record); // Eye
392 process_unicode((0x30CE|QK_UNICODE), record); // Arm
393 register_code(KC_RSFT);
395 unregister_code(KC_RSFT);
399 case SHRUG: // ¯\_(ツ)_/¯
400 if(record->event.pressed){
401 process_unicode((0x00AF|QK_UNICODE), record); // Hand
403 register_code(KC_RSFT);
405 tap(KC_LPRN); // Head
406 unregister_code(KC_RSFT);
407 process_unicode((0x30C4|QK_UNICODE), record); // Face
408 register_code(KC_RSFT);
409 tap(KC_RPRN); // Head
411 unregister_code(KC_RSFT);
413 process_unicode((0x00AF|QK_UNICODE), record); // Hand
419 if(record->event.pressed){
420 register_code(KC_RSFT);
422 unregister_code(KC_RSFT);
424 register_code(KC_RSFT);
428 unregister_code(KC_RSFT);
433 if (record->event.pressed) {
442 void matrix_init_user(void){ // Run once at startup
444 _delay_ms(50); // gets rid of tick
445 PLAY_NOTE_ARRAY(tone_startup, false, 0);
450 void play_goodbye_tone(void){
451 PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
455 void shutdown_user(){
456 PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
461 void music_on_user(void){ // Run when the music layer is turned on
462 PLAY_NOTE_ARRAY(tone_startup, false, 0);
465 void music_off_user(void){ // Run when music is turned off
466 PLAY_NOTE_ARRAY(tone_goodbye, false, 0);