#include QMK_KEYBOARD_H
typedef struct {
bool is_press_action;
int state;
} tap;
enum {
SINGLE_TAP = 1,
SINGLE_HOLD = 2,
DOUBLE_TAP = 3,
TRIPLE_TAP = 4
};
enum {
TAPPY_KEY = 0
};
int cur_dance(qk_tap_dance_state_t *state);
void tk_finished(qk_tap_dance_state_t *state, void *user_data);
void tk_reset(qk_tap_dance_state_t *state, void *user_data);
#define INDICATOR_LED B5
#define TX_LED D5
#define RX_LED B0
#define _FN0 1
#define _ML1 2
#define _CL0 3
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
TD(TAPPY_KEY),KC_HOME, KC_PGUP,
KC_DEL, KC_END, KC_PGDN,
KC_UP,
KC_LEFT, KC_DOWN, KC_RIGHT),
[_FN0] = LAYOUT(
KC_TRNS, KC_PAUS, KC_VOLU,
KC_ENTER, KC_SLCK, KC_VOLD,
KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS),
[_ML1] = LAYOUT(
KC_TRNS, KC_TRNS, KC_VOLU,
KC_MUTE, KC_TRNS, KC_VOLD,
KC_SPC,
KC_MRWD, KC_MPLY, KC_MFFD),
[_CL0] = LAYOUT(
KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS,
LCTL(KC_UP),
LCTL(KC_LEFT), LCTL(KC_DOWN), LCTL(KC_RIGHT) ),
};
void matrix_init_user(void) {
setPinOutput(TX_LED);
setPinOutput(RX_LED);
writePinHigh(TX_LED);
writePinHigh(RX_LED);
}
int cur_dance (qk_tap_dance_state_t *state){
if(state->count == 1){
if(!state->pressed){
return SINGLE_TAP;
} else {
return SINGLE_HOLD;
}
} else if(state->count == 2){
return DOUBLE_TAP;
} else if(state->count == 3){
return TRIPLE_TAP;
} else {
return 8;
}
}
static tap tk_tap_state = {
.is_press_action = true,
.state = 0
};
void tk_finished(qk_tap_dance_state_t *state, void *user_data){
tk_tap_state.state = cur_dance(state);
switch(tk_tap_state.state){
case SINGLE_TAP:
if(layer_state_is(_CL0)){
layer_off(_CL0);
writePinHigh(TX_LED);
writePinHigh(RX_LED);
} else {
layer_on(_CL0);
writePinLow(TX_LED);
writePinLow(RX_LED);
}
break;
case SINGLE_HOLD:
layer_on(_FN0);
break;
case DOUBLE_TAP:
if(layer_state_is(_ML1)){
layer_off(_ML1);
writePinHigh(INDICATOR_LED);
} else {
layer_on(_ML1);
writePinLow(INDICATOR_LED);
}
break;
case TRIPLE_TAP:
layer_clear();
writePinHigh(TX_LED);
writePinHigh(RX_LED);
writePinHigh(INDICATOR_LED);
break;
}
}
void tk_reset(qk_tap_dance_state_t *state, void *user_data){
if(tk_tap_state.state == SINGLE_HOLD){
layer_off(_FN0);
}
tk_tap_state.state = 0;
}
qk_tap_dance_action_t tap_dance_actions[] = {
[TAPPY_KEY] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, tk_finished, tk_reset, 275)
};