#include QMK_KEYBOARD_H
typedef struct {
bool is_press_action;
int state;
} tap;
enum {
SINGLE_TAP = 1,
SINGLE_HOLD = 2,
};
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 _FN0 1
#define _ML1 2
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),
};
int cur_dance (qk_tap_dance_state_t *state){
if(state->count == 1){
if(!state->pressed){
return SINGLE_TAP;
} else {
return SINGLE_HOLD;
}
} 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(_ML1)){
layer_off(_ML1);
writePinHigh(INDICATOR_LED);
} else {
layer_on(_ML1);
writePinLow(INDICATOR_LED);
}
break;
case SINGLE_HOLD:
layer_on(_FN0);
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)
};