From 89357b96d40f6f8189da09c3d15131e22991ed4c Mon Sep 17 00:00:00 2001 From: Fred Silberberg Date: Mon, 6 Nov 2017 09:09:01 -0800 Subject: 333fred layout update (#1971) * Set up tap dance for layers on the lower button. * Refactored code to share in the users directory between my two keyboard layouts. * Small keyboard layout change. * Updated documentation on oneshot usage in macros/tap dance. --- users/333fred/333fred.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ users/333fred/333fred.h | 22 +++++++++++++++++ users/333fred/rules.mk | 2 ++ 3 files changed, 87 insertions(+) create mode 100644 users/333fred/333fred.c create mode 100644 users/333fred/333fred.h create mode 100644 users/333fred/rules.mk (limited to 'users/333fred') diff --git a/users/333fred/333fred.c b/users/333fred/333fred.c new file mode 100644 index 0000000000..ef2d741e5b --- /dev/null +++ b/users/333fred/333fred.c @@ -0,0 +1,63 @@ +#include "333fred.h" +#include "quantum.h" +#include "action.h" + +typedef enum { + SINGLE_TAP, SINGLE_HOLD, DOUBLE +} tap_dance_state_enum; + +static tap_dance_state_enum tap_dance_state; +static bool tap_dance_active = false; + +void tap_dance_layer_finished(qk_tap_dance_state_t *state, void *user_data) { + // Determine the current state + if (state->count == 1) { + if (state->interrupted || state->pressed == 0) tap_dance_state = SINGLE_TAP; + else tap_dance_state = SINGLE_HOLD; + } else { + // Handle any number of other taps as a VIM movement hold + tap_dance_state = DOUBLE; + } + + switch (tap_dance_state) { + case SINGLE_TAP: + if (tap_dance_active) { + reset_oneshot_layer(); + tap_dance_active = false; + } else { + set_oneshot_layer(SYMB, ONESHOT_START); + tap_dance_active = true; + } + break; + case SINGLE_HOLD: + layer_on(SYMB); + break; + case DOUBLE: + layer_on(VIM); + } +} + + +void tap_dance_layer_reset(qk_tap_dance_state_t *state, void *user_data) { + switch(tap_dance_state) { + case SINGLE_TAP: + clear_oneshot_layer_state(ONESHOT_PRESSED); + break; + case SINGLE_HOLD: + layer_off(SYMB); + break; + case DOUBLE: + layer_off(VIM); + break; + } +} + +qk_tap_dance_action_t tap_dance_actions[] = { + [TD_SYM_VIM] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, tap_dance_layer_finished, tap_dance_layer_reset) +}; + +void tap_dance_process_record(uint16_t keycode) { + if (tap_dance_state == SINGLE_TAP && keycode != TD(TD_SYM_VIM)) { + tap_dance_active = false; + } +} diff --git a/users/333fred/333fred.h b/users/333fred/333fred.h new file mode 100644 index 0000000000..4a0462b7a2 --- /dev/null +++ b/users/333fred/333fred.h @@ -0,0 +1,22 @@ +#ifndef FRED_333 +#define FRED_333 + +#include "quantum.h" + +#define BASE 0 +#define CODE 1 // code layer +#define SYMB 2 +#define MDIA 3 // media keys +#define VIM 4 +#define GAME 5 + +// Tap dance config shared between my keyboards +enum tap_dance_declarations { + TD_SYM_VIM = 0 +}; + +void tap_dance_layer_finished(qk_tap_dance_state_t*, void*); +void tap_dance_layer_reset(qk_tap_dance_state_t*, void*); +void tap_dance_process_record(uint16_t); + +#endif diff --git a/users/333fred/rules.mk b/users/333fred/rules.mk new file mode 100644 index 0000000000..3160ac2e69 --- /dev/null +++ b/users/333fred/rules.mk @@ -0,0 +1,2 @@ + +SRC += 333fred.c -- cgit v1.2.3