tap_dances.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "tap_dances.h"
  2. //define diablo macro timer variables
  3. uint16_t diablo_timer[4];
  4. uint8_t diablo_times[] = { 0, 1, 3, 5, 10, 30 };
  5. uint8_t diablo_key_time[4];
  6. // has the correct number of seconds elapsed (as defined by diablo_times)
  7. bool check_dtimer(uint8_t dtimer) { return (timer_elapsed(diablo_timer[dtimer]) < (diablo_key_time[dtimer] * 1000)) ? false : true; };
  8. // Cycle through the times for the macro, starting at 0, for disabled.
  9. // Max of six values, so don't exceed
  10. void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data, uint8_t diablo_key) {
  11. if (state->count >= 7) {
  12. diablo_key_time[diablo_key] = diablo_times[0];
  13. reset_tap_dance(state);
  14. } else {
  15. diablo_key_time[diablo_key] = diablo_times[state->count - 1];
  16. }
  17. }
  18. // Would rather have one function for all of this, but no idea how to do that...
  19. void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 0); }
  20. void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 1); }
  21. void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 2); }
  22. void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 3); }
  23. //Tap Dance Definitions
  24. qk_tap_dance_action_t tap_dance_actions[] = {
  25. // tap once to disable, and more to enable timed micros
  26. [TD_D3_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1),
  27. [TD_D3_2] = ACTION_TAP_DANCE_FN(diablo_tapdance2),
  28. [TD_D3_3] = ACTION_TAP_DANCE_FN(diablo_tapdance3),
  29. [TD_D3_4] = ACTION_TAP_DANCE_FN(diablo_tapdance4),
  30. };
  31. // Sends the key press to system, but only if on the Diablo layer
  32. void send_diablo_keystroke(uint8_t diablo_key) {
  33. if (biton32(layer_state) == _DIABLO) {
  34. switch (diablo_key) {
  35. case 0:
  36. tap(KC_1); break;
  37. case 1:
  38. tap(KC_2); break;
  39. case 2:
  40. tap(KC_3); break;
  41. case 3:
  42. tap(KC_4); break;
  43. }
  44. }
  45. }
  46. // Checks each of the 4 timers/keys to see if enough time has elapsed
  47. // Runs the "send string" command if enough time has passed, and resets the timer.
  48. void run_diablo_macro_check(void) {
  49. uint8_t dtime;
  50. for (dtime = 0; dtime < 4; dtime++) {
  51. if (check_dtimer(dtime) && diablo_key_time[dtime]) {
  52. diablo_timer[dtime] = timer_read();
  53. send_diablo_keystroke(dtime);
  54. }
  55. }
  56. }