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.

148 lines
4.1 KiB

  1. /* Copyright 2021 QMK
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "haptic.h"
  17. #include "process_haptic.h"
  18. #include "quantum_keycodes.h"
  19. #include "action_tapping.h"
  20. __attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) {
  21. switch (keycode) {
  22. #ifdef NO_HAPTIC_MOD
  23. case QK_MOD_TAP ... QK_MOD_TAP_MAX:
  24. if (record->tap.count == 0) return false;
  25. break;
  26. case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
  27. if (record->tap.count != TAPPING_TOGGLE) return false;
  28. break;
  29. case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
  30. if (record->tap.count == 0) return false;
  31. break;
  32. case KC_LCTRL ... KC_RGUI:
  33. case QK_MOMENTARY ... QK_MOMENTARY_MAX:
  34. #endif
  35. #ifdef NO_HAPTIC_FN
  36. case KC_FN0 ... KC_FN31:
  37. #endif
  38. #ifdef NO_HAPTIC_ALPHA
  39. case KC_A ... KC_Z:
  40. #endif
  41. #ifdef NO_HAPTIC_PUNCTUATION
  42. case KC_ENTER:
  43. case KC_ESCAPE:
  44. case KC_BSPACE:
  45. case KC_SPACE:
  46. case KC_MINUS:
  47. case KC_EQUAL:
  48. case KC_LBRACKET:
  49. case KC_RBRACKET:
  50. case KC_BSLASH:
  51. case KC_NONUS_HASH:
  52. case KC_SCOLON:
  53. case KC_QUOTE:
  54. case KC_GRAVE:
  55. case KC_COMMA:
  56. case KC_SLASH:
  57. case KC_DOT:
  58. case KC_NONUS_BSLASH:
  59. #endif
  60. #ifdef NO_HAPTIC_LOCKKEYS
  61. case KC_CAPSLOCK:
  62. case KC_SCROLLLOCK:
  63. case KC_NUMLOCK:
  64. #endif
  65. #ifdef NO_HAPTIC_NAV
  66. case KC_PSCREEN:
  67. case KC_PAUSE:
  68. case KC_INSERT:
  69. case KC_DELETE:
  70. case KC_PGDOWN:
  71. case KC_PGUP:
  72. case KC_LEFT:
  73. case KC_UP:
  74. case KC_RIGHT:
  75. case KC_DOWN:
  76. case KC_END:
  77. case KC_HOME:
  78. #endif
  79. #ifdef NO_HAPTIC_NUMERIC
  80. case KC_1 ... KC_0:
  81. #endif
  82. return false;
  83. }
  84. return true;
  85. }
  86. bool process_haptic(uint16_t keycode, keyrecord_t *record) {
  87. if (record->event.pressed) {
  88. switch (keycode) {
  89. case HPT_ON:
  90. haptic_enable();
  91. break;
  92. case HPT_OFF:
  93. haptic_disable();
  94. break;
  95. case HPT_TOG:
  96. haptic_toggle();
  97. break;
  98. case HPT_RST:
  99. haptic_reset();
  100. break;
  101. case HPT_FBK:
  102. haptic_feedback_toggle();
  103. break;
  104. case HPT_BUZ:
  105. haptic_buzz_toggle();
  106. break;
  107. case HPT_MODI:
  108. haptic_mode_increase();
  109. break;
  110. case HPT_MODD:
  111. haptic_mode_decrease();
  112. break;
  113. case HPT_DWLI:
  114. haptic_dwell_increase();
  115. break;
  116. case HPT_DWLD:
  117. haptic_dwell_decrease();
  118. break;
  119. case HPT_CONT:
  120. haptic_toggle_continuous();
  121. break;
  122. case HPT_CONI:
  123. haptic_cont_increase();
  124. break;
  125. case HPT_COND:
  126. haptic_cont_decrease();
  127. break;
  128. }
  129. }
  130. if (haptic_get_enable()) {
  131. if (record->event.pressed) {
  132. // keypress
  133. if (haptic_get_feedback() < 2 && get_haptic_enabled_key(keycode, record)) {
  134. haptic_play();
  135. }
  136. } else {
  137. // keyrelease
  138. if (haptic_get_feedback() > 0 && get_haptic_enabled_key(keycode, record)) {
  139. haptic_play();
  140. }
  141. }
  142. }
  143. return true;
  144. }