diff options
Diffstat (limited to 'users/bocaj/tap_dances.c')
| -rw-r--r-- | users/bocaj/tap_dances.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/users/bocaj/tap_dances.c b/users/bocaj/tap_dances.c new file mode 100644 index 000000000..10767db45 --- /dev/null +++ b/users/bocaj/tap_dances.c | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | #include "bocaj.h" | ||
| 2 | #include "tap_dances.h" | ||
| 3 | |||
| 4 | |||
| 5 | //define diablo macro timer variables | ||
| 6 | uint16_t diablo_timer[4]; | ||
| 7 | uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 }; | ||
| 8 | uint8_t diablo_key_time[4]; | ||
| 9 | |||
| 10 | // has the correct number of seconds elapsed (as defined by diablo_times) | ||
| 11 | bool check_dtimer(uint8_t dtimer) { return (timer_elapsed(diablo_timer[dtimer]) < (diablo_key_time[dtimer] * 1000)) ? false : true; }; | ||
| 12 | |||
| 13 | // Cycle through the times for the macro, starting at 0, for disabled. | ||
| 14 | // Max of six values, so don't exceed | ||
| 15 | void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data, uint8_t diablo_key) { | ||
| 16 | if (state->count >= 7) { | ||
| 17 | diablo_key_time[diablo_key] = diablo_times[0]; | ||
| 18 | reset_tap_dance(state); | ||
| 19 | } else { | ||
| 20 | diablo_key_time[diablo_key] = diablo_times[state->count - 1]; | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | // Would rather have one function for all of this, but no idea how to do that... | ||
| 25 | void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 0); } | ||
| 26 | void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 1); } | ||
| 27 | void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 2); } | ||
| 28 | void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 3); } | ||
| 29 | |||
| 30 | //Tap Dance Definitions | ||
| 31 | qk_tap_dance_action_t tap_dance_actions[] = { | ||
| 32 | // tap once to disable, and more to enable timed micros | ||
| 33 | [TD_D3_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1), | ||
| 34 | [TD_D3_2] = ACTION_TAP_DANCE_FN(diablo_tapdance2), | ||
| 35 | [TD_D3_3] = ACTION_TAP_DANCE_FN(diablo_tapdance3), | ||
| 36 | [TD_D3_4] = ACTION_TAP_DANCE_FN(diablo_tapdance4), | ||
| 37 | }; | ||
| 38 | |||
| 39 | // Sends the key press to system, but only if on the Diablo layer | ||
| 40 | void send_diablo_keystroke(uint8_t diablo_key) { | ||
| 41 | if (biton32(layer_state) == _DIABLO) { | ||
| 42 | switch (diablo_key) { | ||
| 43 | case 0: | ||
| 44 | tap(KC_1); break; | ||
| 45 | case 1: | ||
| 46 | tap(KC_2); break; | ||
| 47 | case 2: | ||
| 48 | tap(KC_3); break; | ||
| 49 | case 3: | ||
| 50 | tap(KC_4); break; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | // Checks each of the 4 timers/keys to see if enough time has elapsed | ||
| 56 | // Runs the "send string" command if enough time has passed, and resets the timer. | ||
| 57 | void run_diablo_macro_check(void) { | ||
| 58 | uint8_t dtime; | ||
| 59 | for (dtime = 0; dtime < 4; dtime++) { | ||
| 60 | if (check_dtimer(dtime) && diablo_key_time[dtime]) { | ||
| 61 | diablo_timer[dtime] = timer_read(); | ||
| 62 | send_diablo_keystroke(dtime); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
