]> git.donarmstrong.com Git - qmk_firmware.git/blob - users/drashna/tap_dances.c
[Keymap] Drashna's Feature madness (#6128)
[qmk_firmware.git] / users / drashna / tap_dances.c
1 #include "tap_dances.h"
2
3 #define NUM_OF_DIABLO_KEYS 4
4 // define diablo macro timer variables
5 diablo_timer_t diablo_timer[NUM_OF_DIABLO_KEYS];
6
7 // Set the default intervals.  Always start with 0 so that it will disable on first hit.
8 // Otherwise, you will need to hit a bunch of times, or hit the "clear" command
9 uint8_t diablo_times[] = {0, 1, 3, 5, 10, 30};
10
11 // Cycle through the times for the macro, starting at 0, for disabled.
12 void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data) {
13     diable_keys_t *diablo_keys = (diable_keys_t *)user_data;
14     // Sets the keycode based on the index
15     diablo_timer[diablo_keys->index].keycode = diablo_keys->keycode;
16
17     // if the tapdance is hit more than the number of elemints in the array, reset
18     if (state->count >= (sizeof(diablo_times) / sizeof(uint8_t))) {
19         diablo_timer[diablo_keys->index].key_interval = 0;
20         reset_tap_dance(state);
21     } else {  // else set the interval (tapdance count starts at 1, array starts at 0, so offset by one)
22         diablo_timer[diablo_keys->index].key_interval = diablo_times[state->count - 1];
23     }
24 }
25
26 // clang-format off
27 // One function to rule them all!!  Where the Magic Sauce lies
28 #define ACTION_TAP_DANCE_DIABLO(index, keycode) {  \
29     .fn = { NULL, (void *)diablo_tapdance_master, NULL }, \
30     .user_data = (void *)&((diable_keys_t) { index, keycode }),  \
31   }
32 // clang-format on
33
34 // Tap Dance Definitions, sets the index and the keycode.
35 qk_tap_dance_action_t tap_dance_actions[] = {
36     // tap once to disable, and more to enable timed micros
37     [TD_D3_1] = ACTION_TAP_DANCE_DIABLO(0, KC_1),
38     [TD_D3_2] = ACTION_TAP_DANCE_DIABLO(1, KC_2),
39     [TD_D3_3] = ACTION_TAP_DANCE_DIABLO(2, KC_3),
40     [TD_D3_4] = ACTION_TAP_DANCE_DIABLO(3, KC_4),
41 };
42
43 // Checks each of the 4 timers/keys to see if enough time has elapsed
44 void run_diablo_macro_check(void) {
45     for (uint8_t index = 0; index < NUM_OF_DIABLO_KEYS; index++) {
46         // if key_interval is 0, it's disabled, so only run if it's set.  If it's set, check the timer.
47         if (diablo_timer[index].key_interval && timer_elapsed(diablo_timer[index].timer) > (diablo_timer[index].key_interval * 1000)) {
48             // reset the timer, since enough time has passed
49             diablo_timer[index].timer = timer_read();
50             // send keycode ONLY if we're on the diablo layer.
51             if (IS_LAYER_ON(_DIABLO)) {
52                 tap_code(diablo_timer[index].keycode);
53             }
54         }
55     }
56 }