4 Current Layout and Keeb:
5 https://github.com/arkag/qmk_firmware/blob/master/keyboards/mechmini/v2/keymaps/arkag/keymap.c
10 // Start: Written by Chris Lewis
12 #define MIN(a,b) (((a)<(b))?(a):(b))
15 #define MAX(a,b) (((a)>(b))?(a):(b))
18 #define TYPING_SPEED_MAX_VALUE 200
19 uint8_t typing_speed = 0;
21 void velocikey_accelerate() {
22 if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 50);
25 void velocikey_decelerate() {
26 static uint16_t decay_timer = 0;
28 if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) {
29 if (typing_speed > 0) typing_speed -= 1;
30 //Decay a little faster at half of max speed
31 if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1;
32 //Decay even faster at 3/4 of max speed
33 if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 3;
34 decay_timer = timer_read();
38 uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) {
39 return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
41 // End: Written by Chris Lewis
46 num_extra_flashes_off = 0;
51 flashState flash_state = no_flash;
52 fadeState fade_state = add_fade;
53 activityState state = boot;
54 bool aesthetic = false,
57 void set_color (Color new, bool update) {
58 rgblight_sethsv_eeprom_helper(new.h, new.s, new.v, update);
61 void save_color(Color to_save) {
62 saved_color = to_save;
65 void reset_color(void) {
66 underglow = saved_color;
69 Color mod_color(Color current_color, bool should_add, uint8_t change_amount) {
70 save_color(underglow);
71 int addlim = 359 - change_amount;
72 int sublim = change_amount;
75 if (current_color.h <= addlim) {
76 current_color.h += change_amount;
78 leftovers = (359 + change_amount) % 359;
79 current_color.h = 0 + leftovers;
82 if (current_color.h >= sublim) {
83 current_color.h -= change_amount;
85 leftovers = change_amount - current_color.h;
86 current_color.h = 359 - leftovers;
92 void check_state (void) {
93 static uint16_t active_timer;
94 if (!active_timer) {active_timer = timer_read();}
95 static bool activated, deactivated, slept;
99 if (slept) {rgblight_mode_noeeprom(1);}
104 fade_interval = velocikey_match_speed(1, 25);
105 if (timer_elapsed(active_timer) < INACTIVE_DELAY) {return;}
106 active_timer = timer_read();
116 velocikey_decelerate();
117 fade_interval = velocikey_match_speed(1, 25);
118 if (timer_elapsed(active_timer) < SLEEP_DELAY) {return;}
124 rgblight_mode_noeeprom(5);
136 void fade_rgb (void) {
137 static uint16_t fade_timer;
138 if (state == boot) {return;}
139 if (!fade_timer) {fade_timer = timer_read();}
140 if (timer_elapsed(fade_timer) < fade_interval) {return;}
141 switch (fade_state) {
143 if (underglow.h == 359) {
144 fade_state = sub_fade;
147 underglow.h = underglow.h + 1;
151 if (underglow.h == 0) {
152 fade_state = add_fade;
155 underglow.h = underglow.h - 1;
158 fade_timer = timer_read();
159 if (flash_state == no_flash) {
160 set_color(underglow, false);
164 void flash_rgb (void) {
165 static uint16_t flash_timer;
166 switch(flash_state) {
171 if (!flash_timer) {flash_timer = timer_read();}
172 if (timer_elapsed(flash_timer) >= LED_FLASH_DELAY) {
173 set_color(hsv_none, false);
174 flash_timer = timer_read();
175 flash_state = flash_on;
180 if (timer_elapsed(flash_timer) >= LED_FLASH_DELAY) {
181 set_color(flash_color, false);
182 flash_timer = timer_read();
183 if (num_extra_flashes_off > 0) {
184 flash_state = flash_off;
185 num_extra_flashes_off--;
187 set_color(underglow, false);
188 flash_state = no_flash;
195 void set_os (uint8_t os, bool update) {
198 eeprom_update_byte(EECONFIG_USERSPACE, current_os);
202 set_unicode_input_mode(UC_OSX);
203 underglow = (Color){ 300, 255, 255 };
204 mod_primary_mask = MOD_GUI_MASK;
207 set_unicode_input_mode(UC_WINC);
208 underglow = (Color){ 180, 255, 255 };
209 mod_primary_mask = MOD_CTL_MASK;
212 set_unicode_input_mode(UC_LNX);
213 underglow = (Color){ 60, 255, 255 };
214 mod_primary_mask = MOD_CTL_MASK;
217 underglow = (Color){ 0, 0, 255 };
218 mod_primary_mask = MOD_CTL_MASK;
220 set_color(underglow, update);
221 flash_color = underglow;
222 flash_state = flash_off;
224 num_extra_flashes_off = 1;
227 // register GUI if Mac or Ctrl if other
228 void pri_mod(bool press) {
230 if (current_os == OS_MAC) {
231 register_code(KC_LGUI);
233 register_code(KC_LCTL);
236 if (current_os == OS_MAC) {
237 unregister_code(KC_LGUI);
239 unregister_code(KC_LCTL);
244 // register Ctrl if Mac or GUI if other
245 void sec_mod(bool press) {
247 if (current_os == OS_MAC) {
248 register_code(KC_LCTL);
250 register_code(KC_LGUI);
253 if (current_os == OS_MAC) {
254 unregister_code(KC_LCTL);
256 unregister_code(KC_LGUI);
261 void surround_type(uint8_t num_of_chars, uint16_t keycode, bool use_shift) {
263 register_code(KC_LSFT);
265 for (int i = 0; i < num_of_chars; i++) {
269 unregister_code(KC_LSFT);
271 for (int i = 0; i < (num_of_chars/2); i++) {
276 void long_keystroke(size_t num_of_keys, uint16_t keys[]) {
277 for (int i = 0; i < num_of_keys-1; i++) {
278 register_code(keys[i]);
280 tap_code(keys[num_of_keys-1]);
281 for (int i = 0; i < num_of_keys-1; i++) {
282 unregister_code(keys[i]);
286 void dance_grv (qk_tap_dance_state_t *state, void *user_data) {
287 if (state->count == 1) {
292 } else if (state->count == 2) {
293 surround_type(2, KC_GRAVE, false);
295 surround_type(6, KC_GRAVE, false);
299 void dance_quot (qk_tap_dance_state_t *state, void *user_data) {
300 if (state->count == 1) {
305 } else if (state->count == 2) {
306 surround_type(2, KC_QUOTE, false);
307 } else if (state->count == 3) {
308 surround_type(2, KC_QUOTE, true);
312 void dance_hyph (qk_tap_dance_state_t *state, void *user_data) {
313 if (state->count == 1) {
318 } else if (state->count == 2) {
319 register_code(KC_LSFT);
324 unregister_code(KC_LSFT);
325 } else if (state->count == 3) {
326 send_unicode_hex_string("2014");
330 void dance_obrck (qk_tap_dance_state_t *state, void *user_data) {
331 if (state->count == 1) {
336 } else if (state->count == 2) {
337 register_code(KC_LSFT);
342 unregister_code(KC_LSFT);
346 void dance_cbrck (qk_tap_dance_state_t *state, void *user_data) {
347 if (state->count == 1) {
352 } else if (state->count == 2) {
353 register_code(KC_LSFT);
358 unregister_code(KC_LSFT);
362 void dance_game (qk_tap_dance_state_t *state, void *user_data) {
363 if (state->count == 1) {
365 } else if (state->count == 2) {
367 } else if (state->count == 3) {
368 uint8_t layer = biton32(layer_state);
369 if (layer == _QWERTY) {
373 rgblight_mode_noeeprom(12);
377 rgblight_mode_noeeprom(1);
382 void matrix_init_user(void) {
383 current_os = eeprom_read_byte(EECONFIG_USERSPACE);
384 set_os(current_os, false);
389 void matrix_scan_user(void) {
393 LEADER_DICTIONARY() {
397 // begin OS functions
398 SEQ_TWO_KEYS(KC_P, KC_B) {
399 if (current_os == OS_WIN) {
400 long_keystroke(2, (uint16_t[]){KC_LGUI, KC_PAUSE});
405 SEQ_TWO_KEYS(KC_LSFT, M_PMOD) {
406 if (current_os == OS_WIN) {
407 long_keystroke(3, (uint16_t[]){KC_LCTL, KC_LSFT, KC_ESC});
411 SEQ_TWO_KEYS(KC_S, KC_S) {
412 if (current_os == OS_MAC) {
413 long_keystroke(3, (uint16_t[]){KC_LGUI, KC_LSFT, KC_4});
414 } else if (current_os == OS_WIN) {
415 long_keystroke(3, (uint16_t[]){KC_LGUI, KC_LSFT, KC_S});
420 SEQ_THREE_KEYS(KC_C, KC_A, KC_D) {
421 if (current_os == OS_WIN) {
422 long_keystroke(3, (uint16_t[]){KC_LCTL, KC_LALT, KC_DEL});
426 SEQ_FOUR_KEYS(KC_C, KC_A, KC_L, KC_C) {
427 if (current_os == OS_WIN) {
428 SEND_STRING(SS_TAP(X_CALCULATOR));
429 } else if (current_os == OS_MAC) {
430 SEND_STRING(SS_DOWN(X_LGUI) SS_TAP(X_SPACE) SS_UP(X_LGUI) "calculator" SS_TAP(X_ENTER));
435 // begin format functions
437 surround_type(4, KC_8, true);
440 surround_type(2, KC_8, true);
443 surround_type(4, KC_MINS, true);
446 surround_type(4, KC_GRAVE, true);
449 send_unicode_hex_string("00E7");
451 SEQ_TWO_KEYS(KC_C, KC_C) {
452 surround_type(2, KC_GRAVE, false);
454 SEQ_THREE_KEYS(KC_C, KC_C, KC_C) {
455 surround_type(6, KC_GRAVE, false);
458 send_unicode_hex_string("00E8");
460 SEQ_TWO_KEYS(KC_E, KC_E) {
461 send_unicode_hex_string("00E9");
463 // end format functions
465 // start fancy functions
466 SEQ_THREE_KEYS(KC_C, KC_C, KC_ENT) {
467 surround_type(6, KC_GRAVE, false);
476 // end fancy functions
478 // start typing functions
479 SEQ_TWO_KEYS(KC_T, KC_M) {
481 send_unicode_hex_string("2122");
483 SEQ_TWO_KEYS(KC_D, KC_D) {
484 SEND_STRING(".\\Administrator");
486 SEQ_THREE_KEYS(KC_L, KC_O, KC_D) {
488 send_unicode_hex_string("0CA0 005F 005F 0CA0");
490 SEQ_FOUR_KEYS(KC_R, KC_E, KC_P, KC_O) {
491 SEND_STRING("https://github.com/qmk/qmk_firmware/tree/master/users/arkag");
493 SEQ_FOUR_KEYS(KC_F, KC_L, KC_I, KC_P) {
495 send_unicode_hex_string("0028 256F 2035 0414 2032 0029 256F 5F61 253B 2501 253B");
497 SEQ_FIVE_KEYS(KC_U, KC_F, KC_L, KC_I, KC_P) {
499 send_unicode_hex_string("252C 2500 252C 30CE 0028 0020 00BA 0020 005F 0020 00BA 0020 30CE 0029");
501 SEQ_FIVE_KEYS(KC_L, KC_E, KC_N, KC_N, KC_Y) {
503 send_unicode_hex_string("0028 0020 0361 00B0 0020 035C 0296 0020 0361 00B0 0029");
505 SEQ_FIVE_KEYS(KC_S, KC_H, KC_R, KC_U, KC_G) {
507 send_unicode_hex_string("00AF 005C 005F 0028 30C4 0029 005F 002F 00AF");
509 // end typing functions
514 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
518 case KC_SPACE ... KC_SLASH:
519 if (record->event.pressed) {
521 velocikey_accelerate();
528 if (record->event.pressed) {
530 velocikey_accelerate();
535 default: // Do nothing
543 if (record->event.pressed) {
544 int shift = rand() % 2;
546 velocikey_accelerate();
548 register_code(KC_LSFT);
552 unregister_code(KC_LSFT);
557 if (record->event.pressed) {
559 velocikey_accelerate();
563 default: // Do nothing
570 pri_mod(record->event.pressed);
574 sec_mod(record->event.pressed);
578 if (record->event.pressed){
579 set_os((current_os+1) % _OS_COUNT, true);
585 if(record->event.pressed){
588 rgblight_mode_noeeprom(1);
593 rgblight_mode_noeeprom(20);
599 if(record->event.pressed){
602 rgblight_mode_noeeprom(1);
607 rgblight_mode_noeeprom(23);
613 if (record->event.pressed) {
615 velocikey_accelerate();
621 //Tap Dance Definitions
622 qk_tap_dance_action_t tap_dance_actions[] = {
623 [TD_GRV_3GRV] = ACTION_TAP_DANCE_FN (dance_grv),
624 [TD_SING_DOUB] = ACTION_TAP_DANCE_FN (dance_quot),
625 [TD_HYPH_UNDR] = ACTION_TAP_DANCE_FN (dance_hyph),
626 [TD_BRCK_PARN_O] = ACTION_TAP_DANCE_FN (dance_obrck),
627 [TD_BRCK_PARN_C] = ACTION_TAP_DANCE_FN (dance_cbrck),
628 [TD_LALT_RALT] = ACTION_TAP_DANCE_DOUBLE (KC_LALT, KC_RALT),
629 [TD_GAME] = ACTION_TAP_DANCE_FN (dance_game),