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.

145 lines
3.3 KiB

  1. /*
  2. Copyright (c) 2020 Fred Silberberg
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #include QMK_KEYBOARD_H
  20. typedef enum {
  21. SINGLE_TAP, SINGLE_HOLD, DOUBLE, TRIPLE, QUAD
  22. } tap_dance_state_enum;
  23. enum {
  24. TD_KEY = 0
  25. };
  26. static tap_dance_state_enum tap_dance_state;
  27. static bool tap_dance_active = false;
  28. static uint16_t timer;
  29. void dance_cycle(bool override_timer) {
  30. if (tap_dance_active)
  31. {
  32. if (timer_elapsed(timer) > 100 || override_timer)
  33. {
  34. switch (tap_dance_state)
  35. {
  36. case SINGLE_HOLD:
  37. {
  38. rgblight_increase_hue_noeeprom();
  39. break;
  40. }
  41. case DOUBLE:
  42. {
  43. rgblight_step_noeeprom();
  44. break;
  45. }
  46. case TRIPLE:
  47. {
  48. rgblight_toggle_noeeprom();
  49. break;
  50. }
  51. default:
  52. // Not needed
  53. break;
  54. }
  55. timer = timer_read();
  56. }
  57. }
  58. }
  59. void dance_finished(qk_tap_dance_state_t *state, void* user_data) {
  60. // Determine the current state
  61. switch (state->count)
  62. {
  63. case 1:
  64. {
  65. if (state->interrupted || state->pressed == 0) tap_dance_state = SINGLE_TAP;
  66. else tap_dance_state = SINGLE_HOLD;
  67. break;
  68. }
  69. case 2:
  70. {
  71. tap_dance_state = DOUBLE;
  72. break;
  73. }
  74. case 3:
  75. {
  76. tap_dance_state = TRIPLE;
  77. break;
  78. }
  79. default:
  80. {
  81. tap_dance_state = QUAD;
  82. break;
  83. }
  84. }
  85. switch (tap_dance_state)
  86. {
  87. case SINGLE_TAP:
  88. {
  89. // VS Build: CTRL+SHIFT+B
  90. send_string_with_delay_P(PSTR(SS_DOWN(X_LCTRL) SS_DOWN(X_LSHIFT) "b" SS_UP(X_LSHIFT) SS_UP(X_LCTRL)), 10);
  91. tap_dance_active = false;
  92. break;
  93. }
  94. case SINGLE_HOLD:
  95. case DOUBLE:
  96. case TRIPLE:
  97. {
  98. // These are handled by the matrix_scan, which will register the appropriate rgb
  99. // functions every scan
  100. tap_dance_active = true;
  101. timer = timer_read();
  102. dance_cycle(true);
  103. break;
  104. }
  105. case QUAD:
  106. {
  107. // Reprogram
  108. reset_keyboard();
  109. break;
  110. }
  111. }
  112. }
  113. void dance_reset(qk_tap_dance_state_t *state, void* user_data)
  114. {
  115. tap_dance_active = false;
  116. }
  117. qk_tap_dance_action_t tap_dance_actions[] = {
  118. [TD_KEY] = ACTION_TAP_DANCE_FN_ADVANCED (NULL, dance_finished, dance_reset)
  119. };
  120. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  121. [0] = LAYOUT(TD(TD_KEY))
  122. };
  123. void matrix_scan_user(void) {
  124. dance_cycle(false);
  125. }