Skip to content

Commit

Permalink
explore tap dance
Browse files Browse the repository at this point in the history
very intersting
keychron:
tap qmk#5#1 -> ctrl-e hold -> ctrl
  • Loading branch information
paradoxskin committed Jul 12, 2024
1 parent c965d6e commit e30b1b5
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ compile_commands.json

# VIA(L) json files that don't belong in QMK repo
via*.json
.ccls-cache
2 changes: 1 addition & 1 deletion keyboards/keychron/v4/ansi/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
#define RGB_MATRIX_LED_COUNT DRIVER_1_LED_TOTAL

/* Enable CapsLcok LED*/
#define CAPS_LOCK_LED_INDEX 28
#define CAPS_LOCK_LED_INDEX 0
100 changes: 79 additions & 21 deletions keyboards/keychron/v4/ansi/keymaps/paradoxskin/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,74 @@ enum layers {
WIN_BASE,
_FN1,
_FN2,
_FN3,
_FNX,
_FNY,
_TN1,
_TN2,
_TNG,
_TN3,
};

typedef struct {
uint16_t tap;
uint16_t hold;
uint16_t held;
} tap_dance_tap_hold_t;

#define KC_TASK LGUI(KC_TAB)
#define KC_FLXP LGUI(KC_E)
#define QK_TAP_DANCE_GET_INDEX(kc) ((kc)&0xFF)

enum {
TD_C_CE,
TD_R_BK,
TD_TH_CE_C,
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
tap_dance_action_t *action;

switch (keycode) {
case TD(TD_TH_CE_C): // list all tap dance keycodes with tap-hold configurations
action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(keycode)];
if (!record->event.pressed && action->state.count && !action->state.finished) {
tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)action->user_data;
tap_code16(tap_hold->tap);
}
}
return true;
}

//#include "print.h"

void tap_dance_tap_hold_finished(tap_dance_state_t *state, void *user_data) {
tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)user_data;

if (state->pressed) {
//uprintf("F%d %d %d %d\n", state->count, state->interrupted, state->pressed, state->finished);
if (state->count > 0) {
register_code16(tap_hold->hold);
tap_hold->held = tap_hold->hold;
}
//else {
// register_code16(tap_hold->tap);
// tap_hold->held = tap_hold->tap;
//}
}
}

void tap_dance_tap_hold_reset(tap_dance_state_t *state, void *user_data) {
tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)user_data;
//uprintf("R%d %d %d %d\n", state->count, state->interrupted, state->pressed, state->finished);

if (tap_hold->held) {
unregister_code16(tap_hold->held);
tap_hold->held = 0;
}
}

#define ACTION_TAP_DANCE_TAP_HOLD(tap, hold) \
{ .fn = {NULL, tap_dance_tap_hold_finished, tap_dance_tap_hold_reset}, .user_data = (void *)&((tap_dance_tap_hold_t){tap, hold, 0}), }

tap_dance_action_t tap_dance_actions[] = {
[TD_C_CE] = ACTION_TAP_DANCE_DOUBLE(KC_LCTL, C(KC_E)),
[TD_R_BK] = ACTION_TAP_DANCE_LAYER_MOVE(KC_RIGHT, WIN_BASE)
[TD_TH_CE_C] = ACTION_TAP_DANCE_TAP_HOLD(C(KC_E), KC_LCTL)
};

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
Expand All @@ -48,24 +99,23 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS,
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
KC_LCTL, KC_LOPT, KC_LCMD, KC_SPC, KC_RCMD, MO(_FN1), MO(_FN3), KC_RCTL
KC_LCTL, KC_LOPT, KC_LCMD, KC_SPC, KC_RCMD, XXXXXXX, XXXXXXX, KC_RCTL
),

// TODO design some interesting layer (lock) from _FN3
[WIN_BASE] = LAYOUT_ansi_61(
KC_GRAVE, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS,
LT(_FN1,KC_ESC), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, RSFT_T(KC_UP),
TD(TD_C_CE), MO(_FN2), KC_LGUI, MT(MOD_LALT,KC_SPC), KC_RALT, LT(_FN1,KC_LEFT), LT(_FN2,KC_DOWN), LT(_FN3,KC_RIGHT)
TD(TD_TH_CE_C), MO(_FN2), KC_LGUI, MT(MOD_LALT,KC_SPC), KC_RALT, LT(_FN1,KC_LEFT), LT(_FN2,KC_DOWN), LT(_FNX,KC_RIGHT)
),

[_FN1] = LAYOUT_ansi_61(
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
XXXXXXX, KC_BTN1, KC_MS_U, KC_BTN2, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_HUI, RGB_SAI, RGB_VAI,
XXXXXXX, KC_MS_L, KC_MS_D, KC_MS_R, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_SPI, RGB_MOD,
KC_LSFT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_TOG,
XXXXXXX, XXXXXXX, KC_PSCR, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, TO(WIN_BASE)
XXXXXXX, XXXXXXX, KC_PSCR, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
),

[_FN2] = LAYOUT_ansi_61(
Expand All @@ -76,12 +126,20 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_MUTE, XXXXXXX, KC_MPLY, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
),

[_FN3] = LAYOUT_ansi_61(
TO(_TN2), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
TO(_TNG), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
TO(_TN1), _______, _______, _______, _______, _______, _______, _______
[_FNX] = LAYOUT_ansi_61(
KC_CAPS, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, TO(_TN1),
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, TO(_TN2),
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, TO(_TN3),
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______
),

[_FNY] = LAYOUT_ansi_61(
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
KC_ESC, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, TO(WIN_BASE), _______
),

// TO layer
Expand All @@ -90,22 +148,22 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_7, KC_8, KC_9, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
KC_4, KC_5, KC_6, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
KC_1, KC_2, KC_3, _______, _______, _______, _______, _______, _______, _______, _______, _______,
KC_0, KC_0, KC_0, _______, _______, _______, _______, TD(TD_R_BK)
KC_0, KC_0, KC_0, _______, _______, _______, _______, LT(_FNY, KC_RIGHT)
),

[_TN2] = LAYOUT_ansi_61(
_______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, TD(TD_R_BK)
_______, _______, _______, _______, _______, _______, _______, LT(_FNY, KC_RIGHT)
),
[_TNG] = LAYOUT_ansi_61(
[_TN3] = LAYOUT_ansi_61(
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_ESC, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
KC_P, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
KC_LCTL, _______, _______, KC_SPACE, _______, _______, _______, TD(TD_R_BK)
KC_LCTL, _______, _______, KC_SPACE, _______, _______, _______, LT(_FNY, KC_RIGHT)
),
};
/* TEMPLATE:
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ QMK is developed and maintained by Jack Humbert of OLKB with contributions from
### Keychron:

* Build: `qmk compile -kb keychron/v4/ansi -km paradoxskin` => `keychron_v4_ansi_paradoxskin.bin`
* DFU: Hold reset button under L5#4 while replugin USB
* Flash: Just use qmk-toolbox
* DFU: Hold reset button under L5#4 while replugin USB / Hold L1#1 while replugin USB
* Flash: `qmk flash xxx.bin`

### AP2:

Expand Down

0 comments on commit e30b1b5

Please sign in to comment.