You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
5.4 KiB

[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
4 years ago
  1. # Diablo Tap Dances
  2. My [Tap Dance](https://github.com/qmk/qmk_firmware/blob/master/users/drashna/tap_dances.c) file includes the tap dance declarations, and everything needed for them.
  3. This is used for making Diablo 3 much easier to plan, especially at high rift levels.
  4. This works by using Tap Dances. The taps don't actually "do anything". Instead, it sets up the interval for how often to send specific keypresses. As you can tell, this makes automating things very easy.
  5. For critics that think this is cheating, just search "[diablo 3 num lock auto cast](http://lmgtfy.com/?q=diablo+3+numlock+autocast)". This is just a simpler method, that doesn't require a numpad.
  6. ## Custom Tap Dance Type
  7. The real fun here is that the tap dances use a custom defined Tap Dance type:
  8. ```c
  9. #define ACTION_TAP_DANCE_DIABLO(index, keycode) { \
  10. .fn = { NULL, (void *)diablo_tapdance_master, NULL }, \
  11. .user_data = (void *)&((diable_keys_t) { index, keycode }), \
  12. }
  13. ```
  14. This lets me set an index and keycode for the tap dance. This isn't the cool part yet, but this allows for the really cool stuff.
  15. The Index is needed because I don't know how to handle it otherwise.
  16. ## The Actual Dances
  17. These are the custom defined dances that I'm using. It sets up everything for later, using the above custom dance type.
  18. ```c
  19. //Tap Dance Definitions, sets the index and the keycode.
  20. qk_tap_dance_action_t tap_dance_actions[] = {
  21. // tap once to disable, and more to enable timed micros
  22. [TD_D3_1] = ACTION_TAP_DANCE_DIABLO(0, KC_1),
  23. [TD_D3_2] = ACTION_TAP_DANCE_DIABLO(1, KC_2),
  24. [TD_D3_3] = ACTION_TAP_DANCE_DIABLO(2, KC_3),
  25. [TD_D3_4] = ACTION_TAP_DANCE_DIABLO(3, KC_4),
  26. };
  27. ```
  28. ## Custom Data Structures
  29. First, to get this all working, there are a couple of things that need to be set up. In a header file (or you could put it into the keymap), you need to create a couple of custom structures:
  30. ```c
  31. typedef struct {
  32. uint16_t timer;
  33. uint8_t key_interval;
  34. uint8_t keycode;
  35. } diablo_timer_t;
  36. typedef struct {
  37. uint8_t index;
  38. uint8_t keycode;
  39. } diable_keys_t;
  40. ```
  41. The first structure is for tracking each key that is being used. The second is to pass data from the Tap Dance action array to the actual function that we will need.
  42. ## Custom Arrays
  43. To facilitate things, you will need a couple of arrays in your `c` file.
  44. ```c
  45. //define diablo macro timer variables
  46. diablo_timer_t diablo_timer[4];
  47. // Set the default intervals. Always start with 0 so that it will disable on first hit.
  48. // Otherwise, you will need to hit a bunch of times, or hit the "clear" command
  49. uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 };
  50. ```
  51. The first one (`diablo_timer`) is what keeps track of the timer used for the keys, the interval that it uses, and the actual keycode. This makes managing it a lot easier.
  52. The second array is a list of predefined intervals, in seconds. You can add more here, or remove entries. It doesn't matter how long the array is, as this is computed automatically.
  53. ## The Magic - Part 1: Master function
  54. The first part of the magic here is the `diablo_tapdance_master` function. The Tap Dance feature calls this function, directly, and passes some data to the function. Namely, it passes the array of the index and the keycode (`diablo_keys_t` from above). This sets the keycode and the interval for the specific index of `diabolo_timer` based on the number of taps. If you hit it more than the number of items in the array, then it zeroes out the interval, disabling it.
  55. ```c
  56. // Cycle through the times for the macro, starting at 0, for disabled.
  57. void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data) {
  58. diable_keys_t *diablo_keys = (diable_keys_t *)user_data;
  59. // Sets the keycode based on the index
  60. diablo_timer[diablo_keys->index].keycode = diablo_keys->keycode;
  61. // if the tapdance is hit more than the number of elemints in the array, reset
  62. if (state->count >= (sizeof(diablo_times) / sizeof(uint8_t) ) ) {
  63. diablo_timer[diablo_keys->index].key_interval = 0;
  64. reset_tap_dance(state);
  65. } else { // else set the interval (tapdance count starts at 1, array starts at 0, so offset by one)
  66. diablo_timer[diablo_keys->index].key_interval = diablo_times[state->count - 1];
  67. }
  68. }
  69. ```
  70. ## The Magic - Part 2: The Coup de Grace
  71. The real core here is the `run_diablo_macro_check()` function. You need to call this from `matrix_scan_user`, as this handles the timer check.
  72. Specifically, it runs a check for each index of the timer. It checks to see if it's enabled, and if enough time has passed. If enough time has passed, it resets the timer, and will tap the keycode that you set for that index, but only if the Diablo layer is enabled.
  73. ```c
  74. // Checks each of the 4 timers/keys to see if enough time has elapsed
  75. void run_diablo_macro_check(void) {
  76. for (uint8_t index = 0; index < NUM_OF_DIABLO_KEYS; index++) {
  77. // if key_interval is 0, it's disabled, so only run if it's set. If it's set, check the timer.
  78. if ( diablo_timer[index].key_interval && timer_elapsed( diablo_timer[index].timer ) > ( diablo_timer[index].key_interval * 1000 ) ) {
  79. // reset the timer, since enough time has passed
  80. diablo_timer[index].timer = timer_read();
  81. // send keycode ONLY if we're on the diablo layer.
  82. if (IS_LAYER_ON(_DIABLO)) {
  83. tap_code(diablo_timer[index].keycode);
  84. }
  85. }
  86. }
  87. }
  88. ```