diff options
author | Chris Browne <cbbrowne@hpaq.int.linuxdatabases.info> | 2016-10-10 17:18:15 -0400 |
---|---|---|
committer | Chris Browne <cbbrowne@hpaq.int.linuxdatabases.info> | 2016-10-10 17:18:15 -0400 |
commit | 4b682ea63e2b3dd0bc1132917be7985ce0da57a6 (patch) | |
tree | 6d79874c5542148c27907511ecdb2e9e5e12b24b /quantum/process_keycode/process_tap_dance.h | |
parent | 04759d63ef9b520fc41d76de64bb65198448fc1c (diff) | |
parent | a9df99b81c787862dc3fa11bd854fe39e704da81 (diff) |
Merge branch 'master' of github.com:cbbrowne/qmk_firmware
Diffstat (limited to 'quantum/process_keycode/process_tap_dance.h')
-rw-r--r-- | quantum/process_keycode/process_tap_dance.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h new file mode 100644 index 0000000000..f753cbba66 --- /dev/null +++ b/quantum/process_keycode/process_tap_dance.h @@ -0,0 +1,72 @@ +#ifndef PROCESS_TAP_DANCE_H +#define PROCESS_TAP_DANCE_H + +#ifdef TAP_DANCE_ENABLE + +#include <stdbool.h> +#include <inttypes.h> + +typedef struct +{ + uint8_t count; + uint16_t keycode; + uint16_t timer; + bool interrupted; + bool pressed; + bool finished; +} qk_tap_dance_state_t; + +#define TD(n) (QK_TAP_DANCE + n) + +typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state, void *user_data); + +typedef struct +{ + struct { + qk_tap_dance_user_fn_t on_each_tap; + qk_tap_dance_user_fn_t on_dance_finished; + qk_tap_dance_user_fn_t on_reset; + } fn; + qk_tap_dance_state_t state; + void *user_data; +} qk_tap_dance_action_t; + +typedef struct +{ + uint16_t kc1; + uint16_t kc2; +} qk_tap_dance_pair_t; + +#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \ + .fn = { NULL, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset }, \ + .user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }), \ + } + +#define ACTION_TAP_DANCE_FN(user_fn) { \ + .fn = { NULL, user_fn, NULL }, \ + .user_data = NULL, \ + } + +#define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) { \ + .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset }, \ + .user_data = NULL, \ + } + +extern qk_tap_dance_action_t tap_dance_actions[]; + +/* To be used internally */ + +bool process_tap_dance(uint16_t keycode, keyrecord_t *record); +void matrix_scan_tap_dance (void); +void reset_tap_dance (qk_tap_dance_state_t *state); + +void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data); +void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data); + +#else + +#define TD(n) KC_NO + +#endif + +#endif |