commit
62a6d3a6f5
|
@ -22,10 +22,29 @@ static void _process_tap_dance_action_pair (qk_tap_dance_state_t *state,
|
||||||
static void _process_tap_dance_action_fn (qk_tap_dance_state_t *state,
|
static void _process_tap_dance_action_fn (qk_tap_dance_state_t *state,
|
||||||
qk_tap_dance_user_fn_t fn)
|
qk_tap_dance_user_fn_t fn)
|
||||||
{
|
{
|
||||||
fn(state);
|
if (fn) {
|
||||||
|
fn(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_tap_dance_action (uint16_t keycode)
|
void process_tap_dance_action_on_each_tap (uint16_t keycode)
|
||||||
|
{
|
||||||
|
uint16_t idx = keycode - QK_TAP_DANCE;
|
||||||
|
qk_tap_dance_action_t action;
|
||||||
|
|
||||||
|
action = tap_dance_actions[idx];
|
||||||
|
|
||||||
|
switch (action.type) {
|
||||||
|
case QK_TAP_DANCE_TYPE_FN:
|
||||||
|
_process_tap_dance_action_fn (&qk_tap_dance_state, action.fn.on_each_tap);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void process_tap_dance_action_on_dance_finished (uint16_t keycode)
|
||||||
{
|
{
|
||||||
uint16_t idx = keycode - QK_TAP_DANCE;
|
uint16_t idx = keycode - QK_TAP_DANCE;
|
||||||
qk_tap_dance_action_t action;
|
qk_tap_dance_action_t action;
|
||||||
|
@ -38,7 +57,7 @@ void process_tap_dance_action (uint16_t keycode)
|
||||||
action.pair.kc1, action.pair.kc2);
|
action.pair.kc1, action.pair.kc2);
|
||||||
break;
|
break;
|
||||||
case QK_TAP_DANCE_TYPE_FN:
|
case QK_TAP_DANCE_TYPE_FN:
|
||||||
_process_tap_dance_action_fn (&qk_tap_dance_state, action.fn);
|
_process_tap_dance_action_fn (&qk_tap_dance_state, action.fn.on_dance_finished);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -51,8 +70,9 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
|
||||||
switch(keycode) {
|
switch(keycode) {
|
||||||
case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
|
case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
|
||||||
|
process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode);
|
||||||
if (qk_tap_dance_state.keycode && qk_tap_dance_state.keycode != keycode) {
|
if (qk_tap_dance_state.keycode && qk_tap_dance_state.keycode != keycode) {
|
||||||
process_tap_dance_action (qk_tap_dance_state.keycode);
|
process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
|
||||||
} else {
|
} else {
|
||||||
r = false;
|
r = false;
|
||||||
}
|
}
|
||||||
|
@ -66,8 +86,9 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (qk_tap_dance_state.keycode) {
|
if (qk_tap_dance_state.keycode) {
|
||||||
process_tap_dance_action (qk_tap_dance_state.keycode);
|
// if we are here, the tap dance was interrupted by a different key
|
||||||
|
process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode);
|
||||||
|
process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
|
||||||
reset_tap_dance (&qk_tap_dance_state);
|
reset_tap_dance (&qk_tap_dance_state);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -78,13 +99,28 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
|
||||||
void matrix_scan_tap_dance () {
|
void matrix_scan_tap_dance () {
|
||||||
if (qk_tap_dance_state.keycode && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) {
|
if (qk_tap_dance_state.keycode && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) {
|
||||||
process_tap_dance_action (qk_tap_dance_state.keycode);
|
// if we are here, the tap dance was timed out
|
||||||
|
process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
|
||||||
reset_tap_dance (&qk_tap_dance_state);
|
reset_tap_dance (&qk_tap_dance_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_tap_dance (qk_tap_dance_state_t *state) {
|
void reset_tap_dance (qk_tap_dance_state_t *state) {
|
||||||
|
uint16_t idx = state->keycode - QK_TAP_DANCE;
|
||||||
|
qk_tap_dance_action_t action;
|
||||||
|
|
||||||
|
action = tap_dance_actions[idx];
|
||||||
|
switch (action.type) {
|
||||||
|
case QK_TAP_DANCE_TYPE_FN:
|
||||||
|
if (action.fn.on_reset) {
|
||||||
|
action.fn.on_reset(state);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
state->keycode = 0;
|
state->keycode = 0;
|
||||||
state->count = 0;
|
state->count = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,18 +31,27 @@ typedef struct
|
||||||
uint16_t kc1;
|
uint16_t kc1;
|
||||||
uint16_t kc2;
|
uint16_t kc2;
|
||||||
} pair;
|
} pair;
|
||||||
qk_tap_dance_user_fn_t fn;
|
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_action_t;
|
} qk_tap_dance_action_t;
|
||||||
|
|
||||||
#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
|
#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
|
||||||
.type = QK_TAP_DANCE_TYPE_PAIR, \
|
.type = QK_TAP_DANCE_TYPE_PAIR, \
|
||||||
.pair = { kc1, kc2 } \
|
.pair = { kc1, kc2 } \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ACTION_TAP_DANCE_FN(user_fn) { \
|
#define ACTION_TAP_DANCE_FN(user_fn) { \
|
||||||
.type = QK_TAP_DANCE_TYPE_FN, \
|
.type = QK_TAP_DANCE_TYPE_FN, \
|
||||||
.fn = user_fn \
|
.fn = { NULL, user_fn, NULL } \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset) { \
|
||||||
|
.type = QK_TAP_DANCE_TYPE_FN, \
|
||||||
|
.fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset } \
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const qk_tap_dance_action_t tap_dance_actions[];
|
extern const qk_tap_dance_action_t tap_dance_actions[];
|
||||||
|
|
48
readme.md
48
readme.md
|
@ -372,10 +372,11 @@ But lets start with how to use it, first!
|
||||||
|
|
||||||
First, you will need `TAP_DANCE_ENABLE=yes` in your `Makefile`, because the feature is disabled by default. This adds a little less than 1k to the firmware size. Next, you will want to define some tap-dance keys, which is easiest to do with the `TD()` macro, that - similar to `F()`, takes a number, which will later be used as an index into the `tap_dance_actions` array.
|
First, you will need `TAP_DANCE_ENABLE=yes` in your `Makefile`, because the feature is disabled by default. This adds a little less than 1k to the firmware size. Next, you will want to define some tap-dance keys, which is easiest to do with the `TD()` macro, that - similar to `F()`, takes a number, which will later be used as an index into the `tap_dance_actions` array.
|
||||||
|
|
||||||
This array specifies what actions shall be taken when a tap-dance key is in action. Currently, there are two possible options:
|
This array specifies what actions shall be taken when a tap-dance key is in action. Currently, there are three possible options:
|
||||||
|
|
||||||
* `ACTION_TAP_DANCE_DOUBLE(kc1, kc2)`: Sends the `kc1` keycode when tapped once, `kc2` otherwise.
|
* `ACTION_TAP_DANCE_DOUBLE(kc1, kc2)`: Sends the `kc1` keycode when tapped once, `kc2` otherwise.
|
||||||
* `ACTION_TAP_DANCE_FN(fn)`: Calls the specified function - defined in the user keymap - with the current state of the tap-dance action.
|
* `ACTION_TAP_DANCE_FN(fn)`: Calls the specified function - defined in the user keymap - with the final tap count of the tap dance action.
|
||||||
|
* `ACTION_TAP_DANCE_FN_ADVANCED(on_each_tap_fn, on_dance_finished_fn, on_reset_fn)`: Calls the first specified function - defined in the user keymap - on every tap, the second function on when the dance action finishes (like the previous option), and the last function when the tap dance action resets.
|
||||||
|
|
||||||
The first option is enough for a lot of cases, that just want dual roles. For example, `ACTION_TAP_DANCE(KC_SPC, KC_ENT)` will result in `Space` being sent on single-tap, `Enter` otherwise.
|
The first option is enough for a lot of cases, that just want dual roles. For example, `ACTION_TAP_DANCE(KC_SPC, KC_ENT)` will result in `Space` being sent on single-tap, `Enter` otherwise.
|
||||||
|
|
||||||
|
@ -399,7 +400,8 @@ In the end, let's see a full example!
|
||||||
enum {
|
enum {
|
||||||
CT_SE = 0,
|
CT_SE = 0,
|
||||||
CT_CLN,
|
CT_CLN,
|
||||||
CT_EGG
|
CT_EGG,
|
||||||
|
CT_FLSH,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Have the above three on the keymap, TD(CT_SE), etc... */
|
/* Have the above three on the keymap, TD(CT_SE), etc... */
|
||||||
|
@ -424,10 +426,50 @@ void dance_egg (qk_tap_dance_state_t *state) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// on each tap, light up one led, from right to left
|
||||||
|
// on the forth tap, turn them off from right to left
|
||||||
|
void dance_flsh_each(qk_tap_dance_state_t *state) {
|
||||||
|
switch (state->count) {
|
||||||
|
case 1:
|
||||||
|
ergodox_right_led_3_on();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
ergodox_right_led_2_on();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
ergodox_right_led_1_on();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
ergodox_right_led_3_off();
|
||||||
|
_delay_ms(50);
|
||||||
|
ergodox_right_led_2_off();
|
||||||
|
_delay_ms(50);
|
||||||
|
ergodox_right_led_1_off();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// on the fourth tap, set the keyboard on flash state
|
||||||
|
void dance_flsh_finished(qk_tap_dance_state_t *state) {
|
||||||
|
if (state->count >= 4) {
|
||||||
|
reset_keyboard();
|
||||||
|
reset_tap_dance(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the flash state didnt happen, then turn off leds, left to right
|
||||||
|
void dance_flsh_reset(qk_tap_dance_state_t *state) {
|
||||||
|
ergodox_right_led_1_off();
|
||||||
|
_delay_ms(50);
|
||||||
|
ergodox_right_led_2_off();
|
||||||
|
_delay_ms(50);
|
||||||
|
ergodox_right_led_3_off();
|
||||||
|
}
|
||||||
|
|
||||||
const qk_tap_dance_action_t tap_dance_actions[] = {
|
const qk_tap_dance_action_t tap_dance_actions[] = {
|
||||||
[CT_SE] = ACTION_TAP_DANCE_DOUBLE (KC_SPC, KC_ENT)
|
[CT_SE] = ACTION_TAP_DANCE_DOUBLE (KC_SPC, KC_ENT)
|
||||||
,[CT_CLN] = ACTION_TAP_DANCE_FN (dance_cln)
|
,[CT_CLN] = ACTION_TAP_DANCE_FN (dance_cln)
|
||||||
,[CT_EGG] = ACTION_TAP_DANCE_FN (dance_egg)
|
,[CT_EGG] = ACTION_TAP_DANCE_FN (dance_egg)
|
||||||
|
,[CT_FLSH] = ACTION_TAP_DANCE_FN_ADVANCED (dance_flsh_each, dance_flsh_finished, dance_flsh_reset)
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue