tap_dances.c 2.4 KB

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