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;
10 #define CADKEY RCTL(RALT(KC_DEL))
12 void tap(uint16_t keycode){
13 register_code(keycode);
14 unregister_code(keycode);
17 void persistent_default_layer_set(uint16_t default_layer){
18 eeconfig_update_default_layer(default_layer);
19 default_layer_set(default_layer);
22 // Automatic number generation of important keywords
31 // These use process_record_user()
55 float tone_startup[][2] = SONG(STARTUP_SOUND);
56 float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
57 float tone_colemak[][2] = SONG(COLEMAK_SOUND);
58 float tone_swcole[][2] = SONG(QWERTY_SOUND);
59 float tone_capslock_on[][2] = SONG(CAPS_LOCK_ON_SOUND);
60 float tone_capslock_off[][2] = SONG(CAPS_LOCK_OFF_SOUND);
61 float tone_ctrl_mod[][2] = SONG(COIN_SOUND);
62 float tone_copy[][2] = SONG(SCROLL_LOCK_ON_SOUND);
63 float tone_paste[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
64 float uniwin[][2] = SONG(UNICODE_WINDOWS);
65 float unilin[][2] = SONG(UNICODE_LINUX);
68 #ifdef TAP_DANCE_ENABLE
69 #define TAPPING_TERM 200
71 void dance_raise_press(qk_tap_dance_state_t *state, void *user_data){// Called on each tap
72 switch(state->count){ // Only turn the layer on once
76 update_tri_layer(_LOWER, _RAISE, _ADJUST);
80 void dance_raise_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on release
82 case 1: // Normal action. Turn off layers
84 update_tri_layer(_LOWER, _RAISE, _ADJUST);
89 /////////////////////////////////////////////////////////////////////
90 void dance_lower_press(qk_tap_dance_state_t *state, void *user_data){// Called on tap
92 case 1: // Turn on lower
95 update_tri_layer(_LOWER, _RAISE, _ADJUST);
99 void dance_lower_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on release
100 switch(state->count){
101 case 1: // Normal action. Turn off layers
103 update_tri_layer(_LOWER, _RAISE, _ADJUST);
104 layer_off(_UNICODES);
106 case 2: // Turn on _UNICODES layer
108 update_tri_layer(_LOWER, _RAISE, _ADJUST);
111 PLAY_SONG(tone_ctrl_mod);
116 /////////////////////////////////////////////////////////////////////
117 void dance_super_press(qk_tap_dance_state_t *state, void *user_data){ // Called on down
118 if(state->count == 1){
119 register_code(KC_LGUI);
122 void dance_super_done(qk_tap_dance_state_t *state, void *user_data){ // Called on timeout
123 switch(state->count){
125 register_code(KC_LGUI);
127 unregister_code(KC_LGUI);
131 void dance_super_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on up
132 unregister_code(KC_LGUI);
135 qk_tap_dance_action_t tap_dance_actions[] = {
136 [RAI] = ACTION_TAP_DANCE_FN_ADVANCED(dance_raise_press, NULL, dance_raise_lift),
137 [LOW] = ACTION_TAP_DANCE_FN_ADVANCED(dance_lower_press, NULL, dance_lower_lift),
138 [SUP] = ACTION_TAP_DANCE_FN_ADVANCED(dance_super_press, dance_super_done, dance_super_lift)
142 //#ifdef UNICODE_ENABLE
144 #define IBANG X(0x203D)
145 #define RAROW X(0x2192)
146 #define LAROW X(0x2190)
147 #define DEGREE X(0x00B0)
148 #define OMEGA X(0x03A9)
149 #define WOMEGA X(0x03C9)
150 #define MICRO X(0x00B5)
151 #define PLUMIN X(0x00B1)
152 #define SUPA2 X(0x00B2)
153 #define ROMAN1 X(0x2160)
154 #define ROMAN2 X(0x2161)
155 #define ROMAN3 X(0x2162)
156 #define ROMAN4 X(0x2163)
157 #define ROMAN5 X(0x2164)
158 #define ROMAN6 X(0x2165)
159 #define ROMAN7 X(0x2166)
160 #define roman1 X(0x2170)
161 #define roman2 X(0x2171)
162 #define roman3 X(0x2172)
163 #define roman4 X(0x2173)
164 #define roman5 X(0x2174)
165 #define roman6 X(0x2175)
166 #define roman7 X(0x2176)
168 #ifdef UNICODEMAP_ENABLE // For Unicode characters larger than 0x8000. Send with X(<unicode>)
177 const uint32_t PROGMEM unicode_map[] = {
185 #define PENGY X(PENGUIN)
186 #define BOARY X(BOAR)
187 #define MNKY X(MONKEY)
188 #define DRGN X(DRAGON)
189 #define DUCK X(CHICK)
190 #define TMBL X(TUMBLER)
195 static uint16_t key_timer;
196 static uint8_t caps_status = 0;
197 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
200 if(record->event.pressed){
201 persistent_default_layer_set(1UL<<_COLEMAK);
203 PLAY_SONG(tone_colemak);
209 if(record->event.pressed){
210 persistent_default_layer_set(1UL<<_SWCOLE);
212 PLAY_SONG(tone_swcole);
218 if(record->event.pressed){
220 update_tri_layer(_LOWER, _RAISE, _ADJUST);
223 update_tri_layer(_LOWER, _RAISE, _ADJUST);
228 if(record->event.pressed){
230 update_tri_layer(_LOWER, _RAISE, _ADJUST);
233 update_tri_layer(_LOWER, _RAISE, _ADJUST);
238 if(record->event.pressed){
239 key_timer = timer_read(); // if the key is being pressed, we start the timer.
240 register_code(KC_LSHIFT);
241 } else { // this means the key was just released (tap or "held down")
242 if(timer_elapsed(key_timer) < 152){ // Time in ms, the threshold we pick for counting something as a tap.
244 if(caps_status == 0){
247 PLAY_SONG(tone_capslock_on);
252 PLAY_SONG(tone_capslock_off);
256 unregister_code(KC_LSHIFT);
260 case CTRLB: // Control-B on tap (bold)
261 if(record->event.pressed){
262 key_timer = timer_read(); // if the key is being pressed, we start the timer.
263 register_code(KC_LCTL);
264 } else { // this means the key was just released (tap or "held down")
265 if (timer_elapsed(key_timer) < 152) { // Time in ms, the threshold we pick for counting something as a tap.
268 PLAY_SONG(tone_ctrl_mod);
270 #ifdef BACKLIGHT_BREATHING
271 breathing_period_set(2);
275 unregister_code(KC_LCTL);
279 case CPYPST: // One key copy/paste
280 if(record->event.pressed){
281 key_timer = timer_read();
283 if (timer_elapsed(key_timer) > 152) { // Hold, copy
284 register_code(KC_LCTL);
286 unregister_code(KC_LCTL);
288 PLAY_SONG(tone_copy);
290 } else { // Tap, paste
291 register_code(KC_LCTL);
293 unregister_code(KC_LCTL);
295 PLAY_SONG(tone_paste);
301 #ifdef UNICODE_ENABLE
303 if(record->event.pressed){
304 set_unicode_input_mode(UC_WIN);
312 if(record->event.pressed){
313 set_unicode_input_mode(UC_LNX);
321 if(record->event.pressed){
322 process_unicode((0x0CA0|QK_UNICODE), record); // Eye
323 register_code(KC_RSFT);
325 unregister_code(KC_RSFT);
326 process_unicode((0x0CA0|QK_UNICODE), record); // Eye
330 case TFLIP: // (╯°□°)╯ ︵ ┻━┻
331 if(record->event.pressed){
332 register_code(KC_RSFT);
334 unregister_code(KC_RSFT);
335 process_unicode((0x256F|QK_UNICODE), record); // Arm
336 process_unicode((0x00B0|QK_UNICODE), record); // Eye
337 process_unicode((0x25A1|QK_UNICODE), record); // Mouth
338 process_unicode((0x00B0|QK_UNICODE), record); // Eye
339 register_code(KC_RSFT);
341 unregister_code(KC_RSFT);
342 process_unicode((0x256F|QK_UNICODE), record); // Arm
344 process_unicode((0x0361|QK_UNICODE), record); // Flippy
346 process_unicode((0x253B|QK_UNICODE), record); // Table
347 process_unicode((0x2501|QK_UNICODE), record); // Table
348 process_unicode((0x253B|QK_UNICODE), record); // Table
352 case TPUT: // ┬──┬ ノ( ゜-゜ノ)
353 if(record->event.pressed){
354 process_unicode((0x252C|QK_UNICODE), record); // Table
355 process_unicode((0x2500|QK_UNICODE), record); // Table
356 process_unicode((0x2500|QK_UNICODE), record); // Table
357 process_unicode((0x252C|QK_UNICODE), record); // Table
359 process_unicode((0x30CE|QK_UNICODE), record); // Arm
360 register_code(KC_RSFT);
362 unregister_code(KC_RSFT);
364 process_unicode((0x309C|QK_UNICODE), record); // Eye
366 process_unicode((0x309C|QK_UNICODE), record); // Eye
367 process_unicode((0x30CE|QK_UNICODE), record); // Arm
368 register_code(KC_RSFT);
370 unregister_code(KC_RSFT);
374 case SHRUG: // ¯\_(ツ)_/¯
375 if(record->event.pressed){
376 process_unicode((0x00AF|QK_UNICODE), record); // Hand
378 register_code(KC_RSFT);
380 tap(KC_LPRN); // Head
381 unregister_code(KC_RSFT);
382 process_unicode((0x30C4|QK_UNICODE), record); // Face
383 register_code(KC_RSFT);
384 tap(KC_RPRN); // Head
386 unregister_code(KC_RSFT);
388 process_unicode((0x00AF|QK_UNICODE), record); // Hand
394 if(record->event.pressed){
395 register_code(KC_RSFT);
397 unregister_code(KC_RSFT);
399 register_code(KC_RSFT);
403 unregister_code(KC_RSFT);
408 if (record->event.pressed) {
417 void matrix_init_user(void){ // Run once at startup
419 _delay_ms(50); // gets rid of tick
420 PLAY_SONG(tone_startup);
425 void play_goodbye_tone(void){
426 PLAY_SONG(tone_goodbye);
430 void shutdown_user(){
431 PLAY_SONG(tone_goodbye);
436 void music_on_user(void){ // Run when the music layer is turned on
437 PLAY_SONG(tone_startup);
440 void music_off_user(void){ // Run when music is turned off
441 PLAY_SONG(tone_goodbye);