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
13 #define CADKEY RCTL(RALT(KC_DEL))
15 void tap(uint16_t keycode){
16 register_code(keycode);
17 unregister_code(keycode);
20 void persistent_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()
58 float tone_startup[][2] = SONG(STARTUP_SOUND);
59 float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
60 float tone_colemak[][2] = SONG(COLEMAK_SOUND);
61 float tone_swcole[][2] = SONG(QWERTY_SOUND);
62 float tone_capslock_on[][2] = SONG(CAPS_LOCK_ON_SOUND);
63 float tone_capslock_off[][2] = SONG(CAPS_LOCK_OFF_SOUND);
64 float tone_ctrl_mod[][2] = SONG(COIN_SOUND);
65 float tone_copy[][2] = SONG(SCROLL_LOCK_ON_SOUND);
66 float tone_paste[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
67 float uniwin[][2] = SONG(UNICODE_WINDOWS);
68 float unilin[][2] = SONG(UNICODE_LINUX);
71 #ifdef TAP_DANCE_ENABLE
72 #define TAPPING_TERM 200
74 void dance_raise_press(qk_tap_dance_state_t *state, void *user_data){// Called on each tap
75 switch(state->count){ // Only turn the layer on once
79 update_tri_layer(_LOWER, _RAISE, _ADJUST);
83 void dance_raise_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on release
85 case 1: // Normal action. Turn off layers
87 update_tri_layer(_LOWER, _RAISE, _ADJUST);
92 /////////////////////////////////////////////////////////////////////
93 void dance_lower_press(qk_tap_dance_state_t *state, void *user_data){// Called on tap
95 case 1: // Turn on lower
98 update_tri_layer(_LOWER, _RAISE, _ADJUST);
102 void dance_lower_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on release
103 switch(state->count){
104 case 1: // Normal action. Turn off layers
106 update_tri_layer(_LOWER, _RAISE, _ADJUST);
107 layer_off(_UNICODES);
109 case 2: // Turn on _UNICODES layer
111 update_tri_layer(_LOWER, _RAISE, _ADJUST);
114 PLAY_SONG(tone_ctrl_mod);
119 /////////////////////////////////////////////////////////////////////
120 void dance_super_press(qk_tap_dance_state_t *state, void *user_data){ // Called on down
121 if(state->count == 1){
122 register_code(KC_LGUI);
125 void dance_super_done(qk_tap_dance_state_t *state, void *user_data){ // Called on timeout
126 switch(state->count){
128 register_code(KC_LGUI);
130 unregister_code(KC_LGUI);
134 void dance_super_lift(qk_tap_dance_state_t *state, void *user_data){ // Called on up
135 unregister_code(KC_LGUI);
138 qk_tap_dance_action_t tap_dance_actions[] = {
139 [RAI] = ACTION_TAP_DANCE_FN_ADVANCED(dance_raise_press, NULL, dance_raise_lift),
140 [LOW] = ACTION_TAP_DANCE_FN_ADVANCED(dance_lower_press, NULL, dance_lower_lift),
141 [SUP] = ACTION_TAP_DANCE_FN_ADVANCED(dance_super_press, dance_super_done, dance_super_lift)
145 //#ifdef UNICODE_ENABLE
147 #define IBANG X(0x203D)
148 #define RAROW X(0x2192)
149 #define LAROW X(0x2190)
150 #define DEGREE X(0x00B0)
151 #define OMEGA X(0x03A9)
152 #define WOMEGA X(0x03C9)
153 #define MICRO X(0x00B5)
154 #define PLUMIN X(0x00B1)
155 #define SUPA2 X(0x00B2)
156 #define ROMAN1 X(0x2160)
157 #define ROMAN2 X(0x2161)
158 #define ROMAN3 X(0x2162)
159 #define ROMAN4 X(0x2163)
160 #define ROMAN5 X(0x2164)
161 #define ROMAN6 X(0x2165)
162 #define ROMAN7 X(0x2166)
163 #define roman1 X(0x2170)
164 #define roman2 X(0x2171)
165 #define roman3 X(0x2172)
166 #define roman4 X(0x2173)
167 #define roman5 X(0x2174)
168 #define roman6 X(0x2175)
169 #define roman7 X(0x2176)
171 #ifdef UNICODEMAP_ENABLE // For Unicode characters larger than 0x8000. Send with X(<unicode>)
180 const uint32_t PROGMEM unicode_map[] = {
188 #define PENGY X(PENGUIN)
189 #define BOARY X(BOAR)
190 #define MNKY X(MONKEY)
191 #define DRGN X(DRAGON)
192 #define DUCK X(CHICK)
193 #define TMBL X(TUMBLER)
198 static uint16_t key_timer;
199 static uint8_t caps_status = 0;
200 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
203 if(record->event.pressed){
204 persistent_default_layer_set(1UL<<_COLEMAK);
206 PLAY_SONG(tone_colemak);
212 if(record->event.pressed){
213 persistent_default_layer_set(1UL<<_SWCOLE);
215 PLAY_SONG(tone_swcole);
221 if(record->event.pressed){
223 update_tri_layer(_LOWER, _RAISE, _ADJUST);
226 update_tri_layer(_LOWER, _RAISE, _ADJUST);
231 if(record->event.pressed){
233 update_tri_layer(_LOWER, _RAISE, _ADJUST);
236 update_tri_layer(_LOWER, _RAISE, _ADJUST);
241 if(record->event.pressed){
242 key_timer = timer_read(); // if the key is being pressed, we start the timer.
243 register_code(KC_LSHIFT);
244 } else { // this means the key was just released (tap or "held down")
245 if(timer_elapsed(key_timer) < 152){ // Time in ms, the threshold we pick for counting something as a tap.
247 if(caps_status == 0){
250 PLAY_SONG(tone_capslock_on);
255 PLAY_SONG(tone_capslock_off);
259 unregister_code(KC_LSHIFT);
263 case CTRLB: // Control-B on tap (bold)
264 if(record->event.pressed){
265 key_timer = timer_read(); // if the key is being pressed, we start the timer.
266 register_code(KC_LCTL);
267 } else { // this means the key was just released (tap or "held down")
268 if (timer_elapsed(key_timer) < 152) { // Time in ms, the threshold we pick for counting something as a tap.
271 PLAY_SONG(tone_ctrl_mod);
273 #ifdef BACKLIGHT_BREATHING
274 breathing_period_set(2);
278 unregister_code(KC_LCTL);
282 case CPYPST: // One key copy/paste
283 if(record->event.pressed){
284 key_timer = timer_read();
286 if (timer_elapsed(key_timer) > 152) { // Hold, copy
287 register_code(KC_LCTL);
289 unregister_code(KC_LCTL);
291 PLAY_SONG(tone_copy);
293 } else { // Tap, paste
294 register_code(KC_LCTL);
296 unregister_code(KC_LCTL);
298 PLAY_SONG(tone_paste);
304 #ifdef UNICODE_ENABLE
306 if(record->event.pressed){
307 set_unicode_input_mode(UC_WIN);
315 if(record->event.pressed){
316 set_unicode_input_mode(UC_LNX);
324 if(record->event.pressed){
325 process_unicode((0x0CA0|QK_UNICODE), record); // Eye
326 register_code(KC_RSFT);
328 unregister_code(KC_RSFT);
329 process_unicode((0x0CA0|QK_UNICODE), record); // Eye
333 case TFLIP: // (╯°□°)╯ ︵ ┻━┻
334 if(record->event.pressed){
335 register_code(KC_RSFT);
337 unregister_code(KC_RSFT);
338 process_unicode((0x256F|QK_UNICODE), record); // Arm
339 process_unicode((0x00B0|QK_UNICODE), record); // Eye
340 process_unicode((0x25A1|QK_UNICODE), record); // Mouth
341 process_unicode((0x00B0|QK_UNICODE), record); // Eye
342 register_code(KC_RSFT);
344 unregister_code(KC_RSFT);
345 process_unicode((0x256F|QK_UNICODE), record); // Arm
347 process_unicode((0x0361|QK_UNICODE), record); // Flippy
349 process_unicode((0x253B|QK_UNICODE), record); // Table
350 process_unicode((0x2501|QK_UNICODE), record); // Table
351 process_unicode((0x253B|QK_UNICODE), record); // Table
355 case TPUT: // ┬──┬ ノ( ゜-゜ノ)
356 if(record->event.pressed){
357 process_unicode((0x252C|QK_UNICODE), record); // Table
358 process_unicode((0x2500|QK_UNICODE), record); // Table
359 process_unicode((0x2500|QK_UNICODE), record); // Table
360 process_unicode((0x252C|QK_UNICODE), record); // Table
362 process_unicode((0x30CE|QK_UNICODE), record); // Arm
363 register_code(KC_RSFT);
365 unregister_code(KC_RSFT);
367 process_unicode((0x309C|QK_UNICODE), record); // Eye
369 process_unicode((0x309C|QK_UNICODE), record); // Eye
370 process_unicode((0x30CE|QK_UNICODE), record); // Arm
371 register_code(KC_RSFT);
373 unregister_code(KC_RSFT);
377 case SHRUG: // ¯\_(ツ)_/¯
378 if(record->event.pressed){
379 process_unicode((0x00AF|QK_UNICODE), record); // Hand
381 register_code(KC_RSFT);
383 tap(KC_LPRN); // Head
384 unregister_code(KC_RSFT);
385 process_unicode((0x30C4|QK_UNICODE), record); // Face
386 register_code(KC_RSFT);
387 tap(KC_RPRN); // Head
389 unregister_code(KC_RSFT);
391 process_unicode((0x00AF|QK_UNICODE), record); // Hand
397 if(record->event.pressed){
398 register_code(KC_RSFT);
400 unregister_code(KC_RSFT);
402 register_code(KC_RSFT);
406 unregister_code(KC_RSFT);
411 if (record->event.pressed) {
420 void matrix_init_user(void){ // Run once at startup
422 _delay_ms(50); // gets rid of tick
423 PLAY_SONG(tone_startup);
428 void play_goodbye_tone(void){
429 PLAY_SONG(tone_goodbye);
433 void shutdown_user(){
434 PLAY_SONG(tone_goodbye);
439 void music_on_user(void){ // Run when the music layer is turned on
440 PLAY_SONG(tone_startup);
443 void music_off_user(void){ // Run when music is turned off
444 PLAY_SONG(tone_goodbye);