Skip to content

Commit

Permalink
[master] Add enemies dance groups, fix language time lag
Browse files Browse the repository at this point in the history
  • Loading branch information
zored committed Mar 9, 2020
1 parent 66f1000 commit 08fb3e5
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 26 deletions.
28 changes: 25 additions & 3 deletions compiler/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function main () {
)
const files = new KeymapFiles(keyboard)

const { comboCount } = compileKeymap(layers, keyboard, files, keyFactory)
const { comboCount } = compileKeymap(layers, keyboard, files, keyFactory, config.dance_enemies)
compileSettings(keyboard, files, {
COMBO_COUNT: comboCount
})
Expand Down Expand Up @@ -486,7 +486,7 @@ function getLayersTemplateData (layers, keyboard) {
return { keys, names }
}

function compileKeymap (layers, keyboard, files, keyFactory) {
function compileKeymap (layers, keyboard, files, keyFactory, danceEnemies) {
const Mustache = require('mustache')

const { combos, comboCount } = getCombos(keyboard.config.combos, keyFactory)
Expand All @@ -495,13 +495,35 @@ function compileKeymap (layers, keyboard, files, keyFactory) {
unicode: getUnicodeTemplateData(layers),
layers: getLayersTemplateData(layers, keyboard),
functions: getFunctions(),
combos
combos,
danceEnemies: getDanceEnemies(danceEnemies, keyFactory),
}, keyboard.getTemplateData(layers)))
files.add('keymap.c', result)

return { comboCount }
}

function getDanceEnemies(danceEnemies, keyFactory) {
const getCodeName = k => keyFactory.create(k).codeName;
const cases = _.flatMap(danceEnemies, ([a,b], name) => [[a,b],[b,a]].flatMap(([left,right], i) => `
// Enemies ${name} #${i}
${left.map(getCodeName).map(c => `case ${c}:`).join('\n')}
if (
${right.map(getCodeName).map(c => `dance_key_states[${c}] == 0`).join(' && \n')}
) {
return;
}
break;
`)).join('\n');

return `
${cases}
default:
return;
`
}

function getCombos (combosConfig, keyFactory) {
const KEYS = [
['we', 'rt', 'yu', 'io'],
Expand Down
40 changes: 36 additions & 4 deletions compiler/template/zored_keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,26 @@ void run_advanced (uint8_t command) {
tap_code(KC_ENTER);
break;
case DO_NEXT_LANGUAGE:
; // empty statement.
uint8_t hold = 0;
uint8_t tap = 0;
uint32_t timeout = 40;

switch (zored_os) {
case OS_WINDOWS:
tap_code16(A(KC_LSHIFT));
hold = KC_LALT;
tap = KC_LSHIFT;
break;
case OS_MACOS:
tap_code16(G(KC_SPC));
hold = KC_LGUI;
tap = KC_SPC;
break;
}
register_code(hold);
wait_ms(timeout);
tap_code(tap);
wait_ms(timeout);
unregister_code(hold);
break;
case DO_EMOJI_PANEL:
switch (zored_os) {
Expand Down Expand Up @@ -244,12 +256,32 @@ enum dance_action_names {

static int dance_key_states[{{{dance.count}}}] = {0};

void on_dance(qk_tap_dance_state_t *state, void *user_data) {
void dance_tap_on_enemy_hold(qk_tap_dance_state_t *state) {
{{#danceEnemies}}
if (state->count == 0) {
return;
}

uint16_t dance_key = state->keycode - QK_TAP_DANCE;

switch(dance_key) {
{{{danceEnemies}}}
}

state->timer = 0;
state->pressed = false;
{{/danceEnemies}}
}

void on_dance_each_tap(qk_tap_dance_state_t *state, void *user_data) {
dance_tap_on_enemy_hold(state);
}

void on_dance_finished(qk_tap_dance_state_t *state, void *user_data) {
if (state->count == 0) {
return;
}
uint16_t dance_key = state->keycode - QK_TAP_DANCE;

switch (dance_key) {
{{{dance.onDance}}}
Expand All @@ -271,7 +303,7 @@ void on_dance_reset(qk_tap_dance_state_t *state, void *user_data) {
.user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }), \
.custom_tapping_term = tap_specific_tapping_term, \
}
#define DANCE_MODIFIER() ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, on_dance, on_dance_reset, TAPPING_TERM_TAP_DANCE)
#define DANCE_MODIFIER() ACTION_TAP_DANCE_FN_ADVANCED_TIME(on_dance_each_tap, on_dance_finished, on_dance_reset, TAPPING_TERM_TAP_DANCE)
#define DANCE_TWO(k1,k11) ACTION_TAP_DANCE_DOUBLE_TIME(k1, k11, TAPPING_TERM_TAP_DANCE)

qk_tap_dance_action_t tap_dance_actions[] = {
Expand Down
12 changes: 8 additions & 4 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ keyboards:
FORCE_NKRO: ''
LEADER_TIMEOUT: 300
MOUSEKEY_DELAY: 0
MOUSEKEY_INTERVAL: 20
MOUSEKEY_MAX_SPEED: 11
MOUSEKEY_TIME_TO_MAX: 60
MOUSEKEY_INTERVAL: 16
MOUSEKEY_MAX_SPEED: 13
MOUSEKEY_TIME_TO_MAX: 100
MOUSEKEY_WHEEL_DELAY: 0
MOUSEKEY_WHEEL_MAX_SPEED: 4
MOUSEKEY_WHEEL_TIME_TO_MAX: 150
MOUSEKEY_WHEEL_TIME_TO_MAX: 180
TAPPING_TERM: 110
TAPPING_TERM_TAP_DANCE: 270
UNICODE_SELECTED_MODES: 'UC_OSX, UC_WINC'
Expand Down Expand Up @@ -374,6 +374,10 @@ keys:
- [holdEmoji]
- [holdEmoji, lCtrl]
- [holdEmoji, lCtrl, lAlt]
dance_enemies: # holding one group means you must tap the other one.
modifiers:
- [zDance, xDance, cDance]
- [commaDance, dotDance, slashDance]
map:
keys:
"'": QUOT
Expand Down
8 changes: 4 additions & 4 deletions example/ergodox_ez/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
#define MOUSEKEY_DELAY 0

#undef MOUSEKEY_INTERVAL
#define MOUSEKEY_INTERVAL 20
#define MOUSEKEY_INTERVAL 16

#undef MOUSEKEY_MAX_SPEED
#define MOUSEKEY_MAX_SPEED 11
#define MOUSEKEY_MAX_SPEED 13

#undef MOUSEKEY_TIME_TO_MAX
#define MOUSEKEY_TIME_TO_MAX 60
#define MOUSEKEY_TIME_TO_MAX 100

#undef MOUSEKEY_WHEEL_DELAY
#define MOUSEKEY_WHEEL_DELAY 0
Expand All @@ -33,7 +33,7 @@
#define MOUSEKEY_WHEEL_MAX_SPEED 4

#undef MOUSEKEY_WHEEL_TIME_TO_MAX
#define MOUSEKEY_WHEEL_TIME_TO_MAX 150
#define MOUSEKEY_WHEEL_TIME_TO_MAX 180

#undef TAPPING_TERM
#define TAPPING_TERM 110
Expand Down
74 changes: 64 additions & 10 deletions example/ergodox_ez/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,26 @@ void run_advanced (uint8_t command) {
tap_code(KC_ENTER);
break;
case DO_NEXT_LANGUAGE:
; // empty statement.
uint8_t hold = 0;
uint8_t tap = 0;
uint32_t timeout = 40;

switch (zored_os) {
case OS_WINDOWS:
tap_code16(A(KC_LSHIFT));
hold = KC_LALT;
tap = KC_LSHIFT;
break;
case OS_MACOS:
tap_code16(G(KC_SPC));
hold = KC_LGUI;
tap = KC_SPC;
break;
}
register_code(hold);
wait_ms(timeout);
tap_code(tap);
wait_ms(timeout);
unregister_code(hold);
break;
case DO_EMOJI_PANEL:
switch (zored_os) {
Expand Down Expand Up @@ -500,12 +512,60 @@ enum dance_action_names {

static int dance_key_states[91] = {0};

void on_dance(qk_tap_dance_state_t *state, void *user_data) {
void dance_tap_on_enemy_hold(qk_tap_dance_state_t *state) {
if (state->count == 0) {
return;
}

uint16_t dance_key = state->keycode - QK_TAP_DANCE;

switch(dance_key) {


case DANCE_KC_ZDANCE:
case DANCE_KC_XDANCE:
case DANCE_KC_CDANCE:
if (
dance_key_states[DANCE_KC_COMMADANCE] == 0 &&
dance_key_states[DANCE_KC_DOTDANCE] == 0 &&
dance_key_states[DANCE_KC_SLASHDANCE] == 0
) {
return;
}
break;


case DANCE_KC_COMMADANCE:
case DANCE_KC_DOTDANCE:
case DANCE_KC_SLASHDANCE:
if (
dance_key_states[DANCE_KC_ZDANCE] == 0 &&
dance_key_states[DANCE_KC_XDANCE] == 0 &&
dance_key_states[DANCE_KC_CDANCE] == 0
) {
return;
}
break;


default:
return;

}

state->timer = 0;
state->pressed = false;
}

void on_dance_each_tap(qk_tap_dance_state_t *state, void *user_data) {
dance_tap_on_enemy_hold(state);
}

void on_dance_finished(qk_tap_dance_state_t *state, void *user_data) {
if (state->count == 0) {
return;
}
uint16_t dance_key = state->keycode - QK_TAP_DANCE;

switch (dance_key) {

Expand Down Expand Up @@ -1907,7 +1967,7 @@ void on_dance_reset(qk_tap_dance_state_t *state, void *user_data) {
.user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }), \
.custom_tapping_term = tap_specific_tapping_term, \
}
#define DANCE_MODIFIER() ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, on_dance, on_dance_reset, TAPPING_TERM_TAP_DANCE)
#define DANCE_MODIFIER() ACTION_TAP_DANCE_FN_ADVANCED_TIME(on_dance_each_tap, on_dance_finished, on_dance_reset, TAPPING_TERM_TAP_DANCE)
#define DANCE_TWO(k1,k11) ACTION_TAP_DANCE_DOUBLE_TIME(k1, k11, TAPPING_TERM_TAP_DANCE)

qk_tap_dance_action_t tap_dance_actions[] = {
Expand Down Expand Up @@ -1949,8 +2009,6 @@ enum custom_keycodes {
DYNAMIC_MACRO_RANGE,
};

#include "dynamic_macro.h"

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

[LAYER_DEFAULT] = LAYOUT_ergodox(
Expand Down Expand Up @@ -2115,10 +2173,6 @@ void matrix_scan_user(void) {
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (!process_record_dynamic_macro(keycode, record)) {
return false;
}

bool complete = false;

switch (keycode) {
Expand Down
2 changes: 2 additions & 0 deletions example/ergodox_ez/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ COMMAND_ENABLE = no

EXTRAKEY_ENABLE = yes

DYNAMIC_MACRO_ENABLE = yes

NKRO_ENABLE = yes

KEY_LOCK_ENABLE = yes
Expand Down
2 changes: 1 addition & 1 deletion example/planck/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define MOUSEKEY_DELAY 0

#undef MOUSEKEY_INTERVAL
#define MOUSEKEY_INTERVAL 20
#define MOUSEKEY_INTERVAL 16

#undef MOUSEKEY_MAX_SPEED
#define MOUSEKEY_MAX_SPEED 11
Expand Down

0 comments on commit 08fb3e5

Please sign in to comment.