From d41961c9eddb78591d3b55ea65e6e0baff4bdd69 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 22 Jul 2019 20:22:33 -0700 Subject: [Keymap] Drashna's Feature madness (#6128) * Fix my Tap Dance issues after I broke them * Cleanup and organization of userspace documentation As well as some additional cleanup of functions due to review of documentation. * Enable Tapdance on Glow and remove more animations * Revert to Eager PR debouncing * Add better check for startup animation * Move where RGB Matrix defines are listed * Limit RGB Matrix max val * Update keyboard for Iris Rev 3 conflicts * Enable encoder support on planck ez * Remove is_master check from corne\'s OLED code * Overhaul OLED screens for my Corne * One last removal * Show RGB valu On both sides * Updates for OLED display info * Fix compile issues for rgb config * Disabled Space Cadet for all drashna keymaps * Fix OLED Screen configs * Minor OLED Tweaks * Revert some Iris changes * Fix song include * Handle MAKE macro for the Corne boards better * Add super hacky-hack for eeconfig initialization * Add audio support for Fractal since Elite Cs support it * Add defines for keycode steps * Add White layout * Update Corne RGB info * Add fun effects to layer indication for RGB Matrix enabled boards * Use proper define for product name detection * Update formatting * Use custom timeout mechanism for OLED timeout * Fix up OLED screen HSV code for new HSV structure * Better handle turning off RGB Matrix when sleeping * Disable MultiSplash Animation * Change Iris back to using serial * Why was RGB disabled?!?!?! * Limit val in rgb_matrix_layer_helper function * Remove EECONFIG setting for RGB matrix --- users/drashna/tap_dances.c | 77 ++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 43 deletions(-) (limited to 'users/drashna/tap_dances.c') diff --git a/users/drashna/tap_dances.c b/users/drashna/tap_dances.c index 18ca96e18..65019ab75 100644 --- a/users/drashna/tap_dances.c +++ b/users/drashna/tap_dances.c @@ -1,65 +1,56 @@ #include "tap_dances.h" +#define NUM_OF_DIABLO_KEYS 4 +// define diablo macro timer variables +diablo_timer_t diablo_timer[NUM_OF_DIABLO_KEYS]; -//define diablo macro timer variables -diablo_timer_t diablo_timer[4]; - -uint8_t diablo_times[] = { 0, 0, 1, 3, 5, 10, 30 }; - -// has the correct number of seconds elapsed (as defined by diablo_times) -bool check_dtimer(uint8_t dtimer) { return (timer_elapsed(diablo_timer[dtimer].key_time) < (diablo_timer[dtimer].timer * 1000)) ? false : true; }; +// Set the default intervals. Always start with 0 so that it will disable on first hit. +// Otherwise, you will need to hit a bunch of times, or hit the "clear" command +uint8_t diablo_times[] = {0, 1, 3, 5, 10, 30}; // Cycle through the times for the macro, starting at 0, for disabled. -// Max of six values, so don't exceed void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data) { - int index = (int)user_data; - if (state->count >= 7) { - diablo_timer[index].key_time = diablo_times[0]; + diable_keys_t *diablo_keys = (diable_keys_t *)user_data; + // Sets the keycode based on the index + diablo_timer[diablo_keys->index].keycode = diablo_keys->keycode; + + // if the tapdance is hit more than the number of elemints in the array, reset + if (state->count >= (sizeof(diablo_times) / sizeof(uint8_t))) { + diablo_timer[diablo_keys->index].key_interval = 0; reset_tap_dance(state); - } else { - diablo_timer[index].key_time = diablo_times[state->count]; + } else { // else set the interval (tapdance count starts at 1, array starts at 0, so offset by one) + diablo_timer[diablo_keys->index].key_interval = diablo_times[state->count - 1]; } } -// One funtion to rule them all!! -#define ACTION_TAP_DANCE_DIABLO(arg) { \ +// clang-format off +// One function to rule them all!! Where the Magic Sauce lies +#define ACTION_TAP_DANCE_DIABLO(index, keycode) { \ .fn = { NULL, (void *)diablo_tapdance_master, NULL }, \ - .user_data = (void *)arg, \ + .user_data = (void *)&((diable_keys_t) { index, keycode }), \ } +// clang-format on -//Tap Dance Definitions +// Tap Dance Definitions, sets the index and the keycode. qk_tap_dance_action_t tap_dance_actions[] = { // tap once to disable, and more to enable timed micros - [TD_D3_1] = ACTION_TAP_DANCE_DIABLO(0), - [TD_D3_2] = ACTION_TAP_DANCE_DIABLO(1), - [TD_D3_3] = ACTION_TAP_DANCE_DIABLO(2), - [TD_D3_4] = ACTION_TAP_DANCE_DIABLO(3), + [TD_D3_1] = ACTION_TAP_DANCE_DIABLO(0, KC_1), + [TD_D3_2] = ACTION_TAP_DANCE_DIABLO(1, KC_2), + [TD_D3_3] = ACTION_TAP_DANCE_DIABLO(2, KC_3), + [TD_D3_4] = ACTION_TAP_DANCE_DIABLO(3, KC_4), }; -// Sends the key press to system, but only if on the Diablo layer -void send_diablo_keystroke(uint8_t diablo_key) { - if (IS_LAYER_ON(_DIABLO)) { - switch (diablo_key) { - case 0: - tap_code(KC_1); break; - case 1: - tap_code(KC_2); break; - case 2: - tap_code(KC_3); break; - case 3: - tap_code(KC_4); break; - } - } -} - // Checks each of the 4 timers/keys to see if enough time has elapsed -// Runs the "send string" command if enough time has passed, and resets the timer. void run_diablo_macro_check(void) { - uint8_t dtime; - for (dtime = 0; dtime < 4; dtime++) { - if (check_dtimer(dtime) && diablo_timer[dtime].key_time) { - diablo_timer[dtime].timer = timer_read(); - send_diablo_keystroke(dtime); + for (uint8_t index = 0; index < NUM_OF_DIABLO_KEYS; index++) { + // if key_interval is 0, it's disabled, so only run if it's set. If it's set, check the timer. + if (diablo_timer[index].key_interval && timer_elapsed(diablo_timer[index].timer) > (diablo_timer[index].key_interval * 1000)) { + // reset the timer, since enough time has passed + diablo_timer[index].timer = timer_read(); + // send keycode ONLY if we're on the diablo layer. + if (IS_LAYER_ON(_DIABLO)) { + tap_code(diablo_timer[index].keycode); + } } } } -- cgit v1.2.3