diff options
22 files changed, 7419 insertions, 0 deletions
diff --git a/keyboards/butterstick/keymaps/dennytom/README.md b/keyboards/butterstick/keymaps/dennytom/README.md new file mode 100644 index 0000000000..a75bcc7506 --- /dev/null +++ b/keyboards/butterstick/keymaps/dennytom/README.md @@ -0,0 +1,11 @@ +# # Dennytom's Butterstick Layout + +This keymap is using a custom chording engine. Head out to my (DennyTom) user space to find the source files and details. + +To make a real keymap from the JSON file, run + +```sh +python3 parser.py keymap_def.json keymap.c +``` + +Somehow it fits the whole keyboard on 20 keys. For longer typing sessions, use the ASET NIOP mode.
\ No newline at end of file diff --git a/keyboards/butterstick/keymaps/dennytom/keymap.c b/keyboards/butterstick/keymaps/dennytom/keymap.c new file mode 100644 index 0000000000..bfe0aa2153 --- /dev/null +++ b/keyboards/butterstick/keymaps/dennytom/keymap.c @@ -0,0 +1,1418 @@ +#include QMK_KEYBOARD_H + +#define CHORD_TIMEOUT 100 +#define DANCE_TIMEOUT 200 +#define LEADER_TIMEOUT 750 +#define TAP_TIMEOUT 50 +#define LONG_PRESS_MULTIPLIER 3 +#define DYNAMIC_MACRO_MAX_LENGTH 20 +#define COMMAND_MAX_LENGTH 5 +#define LEADER_MAX_LENGTH 5 +#define HASH_TYPE uint32_t +#define NUMBER_OF_KEYS 20 +#define DEFAULT_PSEUDOLAYER QWERTY + +#define H_TOP1 ((HASH_TYPE) 1 << 0) +#define H_TOP2 ((HASH_TYPE) 1 << 1) +#define H_TOP3 ((HASH_TYPE) 1 << 2) +#define H_TOP4 ((HASH_TYPE) 1 << 3) +#define H_TOP5 ((HASH_TYPE) 1 << 4) +#define H_TOP6 ((HASH_TYPE) 1 << 5) +#define H_TOP7 ((HASH_TYPE) 1 << 6) +#define H_TOP8 ((HASH_TYPE) 1 << 7) +#define H_TOP9 ((HASH_TYPE) 1 << 8) +#define H_TOP0 ((HASH_TYPE) 1 << 9) +#define H_BOT1 ((HASH_TYPE) 1 << 10) +#define H_BOT2 ((HASH_TYPE) 1 << 11) +#define H_BOT3 ((HASH_TYPE) 1 << 12) +#define H_BOT4 ((HASH_TYPE) 1 << 13) +#define H_BOT5 ((HASH_TYPE) 1 << 14) +#define H_BOT6 ((HASH_TYPE) 1 << 15) +#define H_BOT7 ((HASH_TYPE) 1 << 16) +#define H_BOT8 ((HASH_TYPE) 1 << 17) +#define H_BOT9 ((HASH_TYPE) 1 << 18) +#define H_BOT0 ((HASH_TYPE) 1 << 19) + +enum internal_keycodes { + TOP1 = SAFE_RANGE, + TOP2, TOP3, TOP4, TOP5, TOP6, TOP7, TOP8, TOP9, TOP0, BOT1, BOT2, BOT3, BOT4, BOT5, BOT6, BOT7, BOT8, BOT9, BOT0, + FIRST_INTERNAL_KEYCODE = TOP1, + LAST_INTERNAL_KEYCODE = BOT0 +}; + +enum pseudolayers { + ALWAYS_ON, QWERTY, NUM, MOV, MOUSE, ASETNIOP, ASETNIOP_123, ASETNIOP_FN +}; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT_butter(TOP1, TOP2, TOP3, TOP4, TOP5, TOP6, TOP7, TOP8, TOP9, TOP0, BOT1, BOT2, BOT3, BOT4, BOT5, BOT6, BOT7, BOT8, BOT9, BOT0), +}; +size_t keymapsCount = 1; + +uint8_t keycodes_buffer_array[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +uint8_t command_buffer[] = { + 0, 0, 0, 0, 0 +}; + +uint16_t leader_buffer[] = { + 0, 0, 0, 0, 0 +}; + +uint8_t dynamic_macro_buffer[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +enum chord_states { + IDLE, + READY, + ACTIVATED, + DEACTIVATED, + PRESS_FROM_ACTIVE, + FINISHED_FROM_ACTIVE, + IDLE_IN_DANCE, + READY_IN_DANCE, + FINISHED, + LOCKED, + READY_LOCKED, + RESTART, + IN_ONE_SHOT +}; + +struct Chord { + uint32_t keycodes_hash; + uint8_t pseudolayer; + uint8_t* state; + uint8_t* counter; + uint16_t value1; + uint8_t value2; + void (*function) (const struct Chord*); +}; + +uint8_t current_pseudolayer = DEFAULT_PSEUDOLAYER; +bool lock_next = false; +uint16_t chord_timer = 0; +uint16_t dance_timer = 0; +bool autoshift_mode = true; +uint8_t keycode_index = 0; +uint8_t command_mode = 0; +uint8_t command_ind = 0; +bool in_leader_mode = false; +uint8_t leader_ind = 0; +uint16_t leader_timer = 0; +uint8_t dynamic_macro_mode = false; +uint8_t dynamic_macro_ind = 0; +bool a_key_went_through = false; +struct Chord* last_chord = NULL; + +bool handle_US_ANSI_shifted_keys(int16_t keycode, bool in) { + bool is_US_ANSI_shifted = true; + + int16_t regular_keycode = KC_NO; + switch (keycode) { + case KC_TILDE: + regular_keycode = KC_GRAVE; + break; + case KC_EXCLAIM: + regular_keycode = KC_1; + break; + case KC_AT: + regular_keycode = KC_2; + break; + case KC_HASH: + regular_keycode = KC_3; + break; + case KC_DOLLAR: + regular_keycode = KC_4; + break; + case KC_PERCENT: + regular_keycode = KC_5; + break; + case KC_CIRCUMFLEX: + regular_keycode = KC_6; + break; + case KC_AMPERSAND: + regular_keycode = KC_7; + break; + case KC_ASTERISK: + regular_keycode = KC_8; + break; + case KC_LEFT_PAREN: + regular_keycode = KC_9; + break; + case KC_RIGHT_PAREN: + regular_keycode = KC_0; + break; + case KC_UNDERSCORE: + regular_keycode = KC_MINUS; + break; + case KC_PLUS: + regular_keycode = KC_EQUAL; + break; + case KC_LEFT_CURLY_BRACE: + regular_keycode = KC_LBRACKET; + break; + case KC_RIGHT_CURLY_BRACE: + regular_keycode = KC_RBRACKET; + break; + case KC_PIPE: + regular_keycode = KC_BSLASH; + break; + case KC_COLON: + regular_keycode = KC_SCOLON; + break; + case KC_DOUBLE_QUOTE: + regular_keycode = KC_QUOTE; + break; + case KC_LEFT_ANGLE_BRACKET: + regular_keycode = KC_COMMA; + break; + case KC_RIGHT_ANGLE_BRACKET: + regular_keycode = KC_DOT; + break; + case KC_QUESTION: + regular_keycode = KC_SLASH; + break; + default: + is_US_ANSI_shifted = false; + } + if (is_US_ANSI_shifted) { + if (in) { + register_code(KC_LSFT); + register_code(regular_keycode); + } else { + unregister_code(regular_keycode); + unregister_code(KC_LSFT); + } + } + return is_US_ANSI_shifted; +} + +void key_in(int16_t keycode) { + if (command_mode == 1 && command_ind < COMMAND_MAX_LENGTH) { + command_buffer[command_ind] = keycode; + command_ind++; + a_key_went_through = true; + } else if (in_leader_mode && leader_ind < LEADER_MAX_LENGTH) { + leader_buffer[leader_ind] = keycode; + leader_ind++; + a_key_went_through = true; + } else if (dynamic_macro_mode && dynamic_macro_ind < DYNAMIC_MACRO_MAX_LENGTH) { + dynamic_macro_buffer[dynamic_macro_ind] = keycode; + dynamic_macro_ind++; + a_key_went_through = true; + } else { + if (!handle_US_ANSI_shifted_keys(keycode, true)) { + register_code(keycode); + } + send_keyboard_report(); + a_key_went_through = true; + } +} + +void key_out(int16_t keycode) { + if (command_mode == 0) { + if (!handle_US_ANSI_shifted_keys(keycode, false)) { + if (command_mode == 0 && in_leader_mode == false && dynamic_macro_mode == false) { + unregister_code(keycode); + } + } + send_keyboard_report(); + } +} + +void tap_key(int16_t keycode) { + key_in(keycode); + wait_ms(TAP_TIMEOUT); + key_out(keycode); +} +void single_dance(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + key_in(self->value1); + break; + case DEACTIVATED: + key_out(self->value1); + *self->state = IDLE; + break; + case RESTART: + key_out(self->value1); + break; + default: + break; + } +} + +void key_layer_dance(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + current_pseudolayer = self->value2; + a_key_went_through = false; + break; + case DEACTIVATED: + case RESTART: + if (!a_key_went_through) { + tap_key(self->value1); + } + current_pseudolayer = self->pseudolayer; + *self->state = IDLE; // does not have effect if the state was RESTART + break; + default: + break; + } +} + +void key_mod_dance(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + key_in(self->value2); + a_key_went_through = false; + break; + case DEACTIVATED: + case RESTART: + key_out(self->value2); + if (!a_key_went_through) { + tap_key(self->value1); + } + *self->state = IDLE; // does not have effect if the state was RESTART + break; + default: + break; + } +} + +void key_key_dance(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + break; + case DEACTIVATED: + tap_key(self->value1); + *self->state = IDLE; + break; + case FINISHED: + case PRESS_FROM_ACTIVE: + key_in(self->value2); + break; + case RESTART: + key_out(self->value2); + break; + default: + break; + } +} + +void autoshift_dance_impl(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + *self->counter = 0; + break; + case DEACTIVATED: + case RESTART: + tap_key(self->value1); + *self->state = IDLE; + break; + case FINISHED_FROM_ACTIVE: + if (*self->counter == (LONG_PRESS_MULTIPLIER - 2)) { + key_in(KC_LSFT); + tap_key(self->value1); + key_out(KC_LSFT); + *self->state = IDLE; + // the skip to IDLE is usually just a lag optimization, + // in this case it has a logic function, on a short + // press (still longer than a tap) the key does not get shifted + } else { + *self->counter += 1; + *self->state = PRESS_FROM_ACTIVE; + dance_timer = timer_read(); + } + break; + default: + break; + } +} + +void autoshift_dance(const struct Chord* self) { + if (autoshift_mode) { + autoshift_dance_impl(self); + } else { + single_dance(self); + } +} + +void autoshift_toggle(const struct Chord* self){ + if (*self->state == ACTIVATED) { + autoshift_mode = !autoshift_mode; + *self->state = IDLE; + } +} + +void temp_pseudolayer(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + current_pseudolayer = self->value1; + break; + case DEACTIVATED: + current_pseudolayer = self->pseudolayer; + *self->state = IDLE; + break; + case RESTART: + current_pseudolayer = self->pseudolayer; + break; + default: + break; + } +} + +void perm_pseudolayer(const struct Chord* self) { + if (*self->state == ACTIVATED) { + current_pseudolayer = self->value1; + *self->state = IDLE; + } +} + +void switch_layer(const struct Chord* self) { + if (*self->state == ACTIVATED) { + layer_move(self->value1); + *self->state = IDLE; + } +} + +void lock(const struct Chord* self) { + if (*self->state == ACTIVATED) { + lock_next = true; + *self->state = IDLE; + } +} + +void one_shot_key(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + break; + case DEACTIVATED: + key_in(self->value1); + *self->state = IN_ONE_SHOT; + break; + case FINISHED: + case PRESS_FROM_ACTIVE: + key_in(self->value1); + a_key_went_through = false; + break; + case RESTART: + if (a_key_went_through) { + key_out(self->value1); + } else { + *self->state = IN_ONE_SHOT; + } + default: + break; + } +} + +void one_shot_layer(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + break; + case DEACTIVATED: + current_pseudolayer = self->value1; + *self->state = IN_ONE_SHOT; + break; + case FINISHED: + case PRESS_FROM_ACTIVE: + current_pseudolayer = self->value1; + a_key_went_through = false; + break; + case RESTART: + if (a_key_went_through) { + current_pseudolayer = self->pseudolayer; + } else { + *self->state = IN_ONE_SHOT; + } + default: + break; + } +} + +void command(const struct Chord* self) { + if (*self->state == ACTIVATED) { + command_mode++; + *self->state = IDLE; + } +} + +bool identical(uint16_t* buffer1, uint16_t* buffer2) { + bool same = true; + for (int i = 0; i < LEADER_MAX_LENGTH; i++) { + same = same && (buffer1[i] == buffer2[i]); + } + return same; +} + +void leader(const struct Chord* self) { + if (*self->state == ACTIVATED) { + in_leader_mode = true; + *self->state = IDLE; + } +} + +void dynamic_macro_record(const struct Chord* self) { + if (*self->state == ACTIVATED) { + for (int i = 0; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + dynamic_macro_buffer[i] = 0; + } + dynamic_macro_mode = true; + *self->state = IDLE; + } +} + +void dynamic_macro_next(const struct Chord* self) { + if (*self->state == ACTIVATED) { + if (dynamic_macro_mode && dynamic_macro_ind < DYNAMIC_MACRO_MAX_LENGTH) { + dynamic_macro_buffer[dynamic_macro_ind] = 0; + dynamic_macro_ind++; + } + *self->state = IDLE; + } +} + +void dynamic_macro_end(const struct Chord* self) { + if (*self->state == ACTIVATED) { + if (dynamic_macro_mode) { + dynamic_macro_mode = false; + } + *self->state = IDLE; + } +} + +void dynamic_macro_play(const struct Chord* self) { + if (*self->state == ACTIVATED) { + int ind_start = 0; + while (ind_start < DYNAMIC_MACRO_MAX_LENGTH) { + for (int i = ind_start; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + if (dynamic_macro_buffer[i] == 0) { + break; + } + register_code(dynamic_macro_buffer[i]); + } + send_keyboard_report(); + wait_ms(TAP_TIMEOUT); + for (int i = ind_start; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + if (dynamic_macro_buffer[i] == 0) { + ind_start = i + 1; + break; + } + unregister_code(dynamic_macro_buffer[i]); + } + send_keyboard_report(); + } + *self->state = IDLE; + } +} + +void clear(const struct Chord* self); + +void reset_keyboard_kb(void){ +#ifdef WATCHDOG_ENABLE + MCUSR = 0; + wdt_disable(); + wdt_reset(); +#endif + reset_keyboard(); +} + +void reset(const struct Chord* self) { + if (*self->state == ACTIVATED) { + reset_keyboard_kb(); + } +} + +uint8_t state_0 = IDLE; +const struct Chord chord_0 PROGMEM = {H_TOP1 + H_TOP2 + H_BOT1 + H_BOT2, ALWAYS_ON, &state_0, NULL, 0, 0, lock}; +uint8_t state_1 = IDLE; +const struct Chord chord_1 PROGMEM = {H_TOP2 + H_TOP3 + H_BOT2 + H_BOT3, ALWAYS_ON, &state_1, NULL, 0, 0, autoshift_toggle}; +uint8_t state_2 = IDLE; +const struct Chord chord_2 PROGMEM = {H_TOP5 + H_TOP6 + H_BOT5 + H_BOT6, ALWAYS_ON, &state_2, NULL, 0, 0, command}; +uint8_t state_3 = IDLE; +const struct Chord chord_3 PROGMEM = {H_TOP1 + H_TOP2 + H_TOP9 + H_TOP0 + H_BOT1 + H_BOT2 + H_BOT9 + H_BOT0, ALWAYS_ON, &state_3, NULL, 0, 0, clear}; +uint8_t state_4 = IDLE; +uint8_t counter_4 = 0; +const struct Chord chord_4 PROGMEM = {H_TOP1, QWERTY, &state_4, &counter_4, KC_Q, 0, autoshift_dance}; +uint8_t state_5 = IDLE; +uint8_t counter_5 = 0; +const struct Chord chord_5 PROGMEM = {H_TOP2, QWERTY, &state_5, &counter_5, KC_W, 0, autoshift_dance}; +uint8_t state_6 = IDLE; +uint8_t counter_6 = 0; +const struct Chord chord_6 PROGMEM = {H_TOP3, QWERTY, &state_6, &counter_6, KC_E, 0, autoshift_dance}; +uint8_t state_7 = IDLE; +uint8_t counter_7 = 0; +const struct Chord chord_7 PROGMEM = {H_TOP4, QWERTY, &state_7, &counter_7, KC_R, 0, autoshift_dance}; +uint8_t state_8 = IDLE; +uint8_t counter_8 = 0; +const struct Chord chord_8 PROGMEM = {H_TOP5, QWERTY, &state_8, &counter_8, KC_T, 0, autoshift_dance}; +uint8_t state_9 = IDLE; +uint8_t counter_9 = 0; +const struct Chord chord_9 PROGMEM = {H_TOP6, QWERTY, &state_9, &counter_9, KC_Y, 0, autoshift_dance}; +uint8_t state_10 = IDLE; +uint8_t counter_10 = 0; +const struct Chord chord_10 PROGMEM = {H_TOP7, QWERTY, &state_10, &counter_10, KC_U, 0, autoshift_dance}; +uint8_t state_11 = IDLE; +uint8_t counter_11 = 0; +const struct Chord chord_11 PROGMEM = {H_TOP8, QWERTY, &state_11, &counter_11, KC_I, 0, autoshift_dance}; +uint8_t state_12 = IDLE; +uint8_t counter_12 = 0; +const struct Chord chord_12 PROGMEM = {H_TOP9, QWERTY, &state_12, &counter_12, KC_O, 0, autoshift_dance}; +uint8_t state_13 = IDLE; +uint8_t counter_13 = 0; +const struct Chord chord_13 PROGMEM = {H_TOP0, QWERTY, &state_13, &counter_13, KC_P, 0, autoshift_dance}; +uint8_t state_14 = IDLE; +uint8_t counter_14 = 0; +const struct Chord chord_14 PROGMEM = {H_TOP1 + H_BOT1, QWERTY, &state_14, &counter_14, KC_A, 0, autoshift_dance}; +uint8_t state_15 = IDLE; +uint8_t counter_15 = 0; +const struct Chord chord_15 PROGMEM = {H_TOP2 + H_BOT2, QWERTY, &state_15, &counter_15, KC_S, 0, autoshift_dance}; +uint8_t state_16 = IDLE; +uint8_t counter_16 = 0; +const struct Chord chord_16 PROGMEM = {H_TOP3 + H_BOT3, QWERTY, &state_16, &counter_16, KC_D, 0, autoshift_dance}; +uint8_t state_17 = IDLE; +uint8_t counter_17 = 0; +const struct Chord chord_17 PROGMEM = {H_TOP4 + H_BOT4, QWERTY, &state_17, &counter_17, KC_F, 0, autoshift_dance}; +uint8_t state_18 = IDLE; +uint8_t counter_18 = 0; +const struct Chord chord_18 PROGMEM = {H_TOP5 + H_BOT5, QWERTY, &state_18, &counter_18, KC_G, 0, autoshift_dance}; +uint8_t state_19 = IDLE; +uint8_t counter_19 = 0; +const struct Chord chord_19 PROGMEM = {H_TOP6 + H_BOT6, QWERTY, &state_19, &counter_19, KC_H, 0, autoshift_dance}; +uint8_t state_20 = IDLE; +uint8_t counter_20 = 0; +const struct Chord chord_20 PROGMEM = {H_TOP7 + H_BOT7, QWERTY, &state_20, &counter_20, KC_J, 0, autoshift_dance}; +uint8_t state_21 = IDLE; +uint8_t counter_21 = 0; +const struct Chord chord_21 PROGMEM = {H_TOP8 + H_BOT8, QWERTY, &state_21, &counter_21, KC_K, 0, autoshift_dance}; +uint8_t state_22 = IDLE; +uint8_t counter_22 = 0; +const struct Chord chord_22 PROGMEM = {H_TOP9 + H_BOT9, QWERTY, &state_22, &counter_22, KC_L, 0, autoshift_dance}; +uint8_t state_23 = IDLE; +uint8_t counter_23 = 0; +const struct Chord chord_23 PROGMEM = {H_TOP0 + H_BOT0, QWERTY, &state_23, &counter_23, KC_SCOLON, 0, autoshift_dance}; +uint8_t state_24 = IDLE; +uint8_t counter_24 = 0; +const struct Chord chord_24 PROGMEM = {H_BOT1, QWERTY, &state_24, &counter_24, KC_Z, 0, autoshift_dance}; +uint8_t state_25 = IDLE; +uint8_t counter_25 = 0; +const struct Chord chord_25 PROGMEM = {H_BOT2, QWERTY, &state_25, &counter_25, KC_X, 0, autoshift_dance}; +uint8_t state_26 = IDLE; +uint8_t counter_26 = 0; +const struct Chord chord_26 PROGMEM = {H_BOT3, QWERTY, &state_26, &counter_26, KC_C, 0, autoshift_dance}; +uint8_t state_27 = IDLE; +uint8_t counter_27 = 0; +const struct Chord chord_27 PROGMEM = {H_BOT4, QWERTY, &state_27, &counter_27, KC_V, 0, autoshift_dance}; +uint8_t state_28 = IDLE; +uint8_t counter_28 = 0; +const struct Chord chord_28 PROGMEM = {H_BOT5, QWERTY, &state_28, &counter_28, KC_B, 0, autoshift_dance}; +uint8_t state_29 = IDLE; +uint8_t counter_29 = 0; +const struct Chord chord_29 PROGMEM = {H_BOT6, QWERTY, &state_29, &counter_29, KC_N, 0, autoshift_dance}; +uint8_t state_30 = IDLE; +uint8_t counter_30 = 0; +const struct Chord chord_30 PROGMEM = {H_BOT7, QWERTY, &state_30, &counter_30, KC_M, 0, autoshift_dance}; +uint8_t state_31 = IDLE; +uint8_t counter_31 = 0; +const struct Chord chord_31 PROGMEM = {H_BOT8, QWERTY, &state_31, &counter_31, KC_COMMA, 0, autoshift_dance}; +uint8_t state_32 = IDLE; +uint8_t counter_32 = 0; +const struct Chord chord_32 PROGMEM = {H_BOT9, QWERTY, &state_32, &counter_32, KC_DOT, 0, autoshift_dance}; +uint8_t state_33 = IDLE; +uint8_t counter_33 = 0; +const struct Chord chord_33 PROGMEM = {H_BOT0, QWERTY, &state_33, &counter_33, KC_SLASH, 0, autoshift_dance}; +uint8_t state_34 = IDLE; +const struct Chord chord_34 PROGMEM = {H_TOP1 + H_TOP2, QWERTY, &state_34, NULL, KC_ESC, 0, single_dance}; +uint8_t state_35 = IDLE; +const struct Chord chord_35 PROGMEM = {H_TOP2 + H_TOP3, QWERTY, &state_35, NULL, MOV, 0, temp_pseudolayer}; +uint8_t state_36 = IDLE; +const struct Chord chord_36 PROGMEM = {H_TOP3 + H_TOP4, QWERTY, &state_36, NULL, KC_TAB, 0, single_dance}; +uint8_t state_37 = IDLE; +const struct Chord chord_37 PROGMEM = {H_TOP5 + H_TOP6, QWERTY, &state_37, NULL, KC_RGUI, 0, one_shot_key}; +uint8_t state_38 = IDLE; +const struct Chord chord_38 PROGMEM = {H_TOP7 + H_TOP8, QWERTY, &state_38, NULL, KC_INS, 0, single_dance}; +uint8_t state_39 = IDLE; +const struct Chord chord_39 PROGMEM = {H_TOP8 + H_TOP9, QWERTY, &state_39, NULL, KC_DEL, 0, single_dance}; +uint8_t state_40 = IDLE; +const struct Chord chord_40 PROGMEM = {H_TOP9 + H_TOP0, QWERTY, &state_40, NULL, KC_BSPC, 0, single_dance}; +uint8_t state_41 = IDLE; +const struct Chord chord_41 PROGMEM = {H_TOP9 + H_TOP0 + H_BOT9 + H_BOT0, QWERTY, &state_41, NULL, KC_ENTER, 0, single_dance}; +uint8_t state_42 = IDLE; +const struct Chord chord_42 PROGMEM = {H_BOT1 + H_BOT2, QWERTY, &state_42, NULL, KC_LSFT, 0, one_shot_key}; +uint8_t state_43 = IDLE; +const struct Chord chord_43 PROGMEM = {H_BOT2 + H_BOT3, QWERTY, &state_43, NULL, KC_LCTL, 0, one_shot_key}; +uint8_t state_44 = IDLE; +const struct Chord chord_44 PROGMEM = {H_BOT3 + H_BOT4, QWERTY, &state_44, NULL, KC_LALT, 0, one_shot_key}; +uint8_t state_45 = IDLE; +const struct Chord chord_45 PROGMEM = {H_BOT4 + H_BOT5, QWERTY, &state_45, NULL, NUM, 0, one_shot_layer}; +uint8_t state_46 = IDLE; +const struct Chord chord_46 PROGMEM = {H_BOT5 + H_BOT6, QWERTY, &state_46, NULL, KC_LGUI, 0, one_shot_key}; +uint8_t state_47 = IDLE; +const struct Chord chord_47 PROGMEM = {H_BOT6 + H_BOT7, QWERTY, &state_47, NULL, NUM, 0, one_shot_layer}; +uint8_t state_48 = IDLE; +const struct Chord chord_48 PROGMEM = {H_BOT7 + H_BOT8, QWERTY, &state_48, NULL, KC_RALT, 0, one_shot_key}; +uint8_t state_49 = IDLE; +const struct Chord chord_49 PROGMEM = {H_BOT8 + H_BOT9, QWERTY, &state_49, NULL, KC_RCTL, 0, one_shot_key}; +uint8_t state_50 = IDLE; +const struct Chord chord_50 PROGMEM = {H_BOT9 + H_BOT0, QWERTY, &state_50, NULL, KC_RSFT, 0, one_shot_key}; +uint8_t state_51 = IDLE; +const struct Chord chord_51 PROGMEM = {H_BOT1 + H_BOT0, QWERTY, &state_51, NULL, KC_SPACE, 0, single_dance}; +uint8_t state_52 = IDLE; +const struct Chord chord_52 PROGMEM = {H_TOP1 + H_TOP2 + H_TOP3 + H_TOP4, QWERTY, &state_52, NULL, MOUSE, 0, temp_pseudolayer}; +uint8_t state_53 = IDLE; +const struct Chord chord_53 PROGMEM = {H_TOP1 + H_TOP2 + H_TOP3 + H_TOP4, QWERTY, &state_53, NULL, ASETNIOP, 0, perm_pseudolayer}; +uint8_t state_54 = IDLE; +uint8_t counter_54 = 0; +const struct Chord chord_54 PROGMEM = {H_TOP1, NUM, &state_54, &counter_54, KC_1, 0, autoshift_dance}; +uint8_t state_55 = IDLE; +uint8_t counter_55 = 0; +const struct Chord chord_55 PROGMEM = {H_TOP2, NUM, &state_55, &counter_55, KC_2, 0, autoshift_dance}; +uint8_t state_56 = IDLE; +uint8_t counter_56 = 0; +const struct Chord chord_56 PROGMEM = {H_TOP3, NUM, &state_56, &counter_56, KC_3, 0, autoshift_dance}; +uint8_t state_57 = IDLE; +uint8_t counter_57 = 0; +const struct Chord chord_57 PROGMEM = {H_TOP4, NUM, &state_57, &counter_57, KC_4, 0, autoshift_dance}; +uint8_t state_58 = IDLE; +uint8_t counter_58 = 0; +const struct Chord chord_58 PROGMEM = {H_TOP5, NUM, &state_58, &counter_58, KC_5, 0, autoshift_dance}; +uint8_t state_59 = IDLE; +uint8_t counter_59 = 0; +const struct Chord chord_59 PROGMEM = {H_TOP6, NUM, &state_59, &counter_59, KC_6, 0, autoshift_dance}; +uint8_t state_60 = IDLE; +uint8_t counter_60 = 0; +const struct Chord chord_60 PROGMEM = {H_TOP7, NUM, &state_60, &counter_60, KC_7, 0, autoshift_dance}; +uint8_t state_61 = IDLE; +uint8_t counter_61 = 0; +const struct Chord chord_61 PROGMEM = {H_TOP8, NUM, &state_61, &counter_61, KC_8, 0, autoshift_dance}; +uint8_t state_62 = IDLE; +uint8_t counter_62 = 0; +const struct Chord chord_62 PROGMEM = {H_TOP9, NUM, &state_62, &counter_62, KC_9, 0, autoshift_dance}; +uint8_t state_63 = IDLE; +uint8_t counter_63 = 0; +const struct Chord chord_63 PROGMEM = {H_TOP0, NUM, &state_63, &counter_63, KC_0, 0, autoshift_dance}; +uint8_t state_64 = IDLE; +const struct Chord chord_64 PROGMEM = {H_TOP1 + H_BOT1, NUM, &state_64, NULL, KC_F1, 0, single_dance}; +uint8_t state_65 = IDLE; +const struct Chord chord_65 PROGMEM = {H_TOP2 + H_BOT2, NUM, &state_65, NULL, KC_F2, 0, single_dance}; +uint8_t state_66 = IDLE; +const struct Chord chord_66 PROGMEM = {H_TOP3 + H_BOT3, NUM, &state_66, NULL, KC_F3, 0, single_dance}; +uint8_t state_67 = IDLE; +const struct Chord chord_67 PROGMEM = {H_TOP4 + H_BOT4, NUM, &state_67, NULL, KC_F4, 0, single_dance}; +uint8_t state_68 = IDLE; +const struct Chord chord_68 PROGMEM = {H_TOP5 + H_BOT5, NUM, &state_68, NULL, KC_F5, 0, single_dance}; +uint8_t state_69 = IDLE; +const struct Chord chord_69 PROGMEM = {H_TOP6 + H_BOT6, NUM, &state_69, NULL, KC_F6, 0, single_dance}; +uint8_t state_70 = IDLE; +const struct Chord chord_70 PROGMEM = {H_TOP7 + H_BOT7, NUM, &state_70, NULL, KC_F7, 0, single_dance}; +uint8_t state_71 = IDLE; +const struct Chord chord_71 PROGMEM = {H_TOP8 + H_BOT8, NUM, &state_71, NULL, KC_F8, 0, single_dance}; +uint8_t state_72 = IDLE; +const struct Chord chord_72 PROGMEM = {H_TOP9 + H_BOT9, NUM, &state_72, NULL, KC_F9, 0, single_dance}; +uint8_t state_73 = IDLE; +const struct Chord chord_73 PROGMEM = {H_TOP0 + H_BOT0, NUM, &state_73, NULL, KC_F10, 0, single_dance}; +uint8_t state_74 = IDLE; +uint8_t counter_74 = 0; +const struct Chord chord_74 PROGMEM = {H_BOT1, NUM, &state_74, &counter_74, KC_GRAVE, 0, autoshift_dance}; +uint8_t state_75 = IDLE; +uint8_t counter_75 = 0; +const struct Chord chord_75 PROGMEM = {H_BOT2, NUM, &state_75, &counter_75, KC_MINUS, 0, autoshift_dance}; +uint8_t state_76 = IDLE; +uint8_t counter_76 = 0; +const struct Chord chord_76 PROGMEM = {H_BOT3, NUM, &state_76, &counter_76, KC_EQUAL, 0, autoshift_dance}; +uint8_t state_77 = IDLE; +uint8_t counter_77 = 0; +const struct Chord chord_77 PROGMEM = {H_BOT4, NUM, &state_77, &counter_77, KC_LBRACKET, 0, autoshift_dance}; +uint8_t state_78 = IDLE; +uint8_t counter_78 = 0; +const struct Chord chord_78 PROGMEM = {H_BOT5, NUM, &state_78, &counter_78, KC_RBRACKET, 0, autoshift_dance}; +uint8_t state_79 = IDLE; +uint8_t counter_79 = 0; +const struct Chord chord_79 PROGMEM = {H_BOT6, NUM, &state_79, &counter_79, KC_BSLASH, 0, autoshift_dance}; +uint8_t state_80 = IDLE; +uint8_t counter_80 = 0; +const struct Chord chord_80 PROGMEM = {H_BOT7, NUM, &state_80, &counter_80, KC_QUOTE, 0, autoshift_dance}; +uint8_t state_81 = IDLE; +const struct Chord chord_81 PROGMEM = {H_BOT9, NUM, &state_81, NULL, KC_F11, 0, single_dance}; +uint8_t state_82 = IDLE; +const struct Chord chord_82 PROGMEM = {H_BOT0, NUM, &state_82, NULL, KC_F12, 0, single_dance}; +uint8_t state_83 = IDLE; +const struct Chord chord_83 PROGMEM = {H_TOP1 + H_TOP2, NUM, &state_83, NULL, KC_ESC, 0, single_dance}; +uint8_t state_84 = IDLE; +const struct Chord chord_84 PROGMEM = {H_TOP3 + H_TOP4, NUM, &state_84, NULL, KC_TAB, 0, single_dance}; +uint8_t state_85 = IDLE; +const struct Chord chord_85 PROGMEM = {H_TOP5 + H_TOP6, NUM, &state_85, NULL, KC_RGUI, 0, one_shot_key}; +uint8_t state_86 = IDLE; +const struct Chord chord_86 PROGMEM = {H_TOP7 + H_TOP8, NUM, &state_86, NULL, KC_INS, 0, single_dance}; +uint8_t state_87 = IDLE; +const struct Chord chord_87 PROGMEM = {H_TOP8 + H_TOP9, NUM, &state_87, NULL, KC_DEL, 0, single_dance}; +uint8_t state_88 = IDLE; +const struct Chord chord_88 PROGMEM = {H_TOP9 + H_TOP0, NUM, &state_88, NULL, KC_BSPC, 0, single_dance}; +uint8_t state_89 = IDLE; +const struct Chord chord_89 PROGMEM = {H_TOP9 + H_TOP0 + H_BOT9 + H_BOT0, NUM, &state_89, NULL, KC_ENTER, 0, single_dance}; +uint8_t state_90 = IDLE; +const struct Chord chord_90 PROGMEM = {H_BOT1 + H_BOT2, NUM, &state_90, NULL, KC_LSFT, 0, one_shot_key}; +uint8_t state_91 = IDLE; +const struct Chord chord_91 PROGMEM = {H_BOT2 + H_BOT3, NUM, &state_91, NULL, KC_LCTL, 0, one_shot_key}; +uint8_t state_92 = IDLE; +const struct Chord chord_92 PROGMEM = {H_BOT3 + H_BOT4, NUM, &state_92, NULL, KC_LALT, 0, one_shot_key}; +uint8_t state_93 = IDLE; +const struct Chord chord_93 PROGMEM = {H_BOT5 + H_BOT6, NUM, &state_93, NULL, KC_LGUI, 0, one_shot_key}; +uint8_t state_94 = IDLE; +const struct Chord chord_94 PROGMEM = {H_BOT7 + H_BOT8, NUM, &state_94, NULL, KC_RALT, 0, one_shot_key}; +uint8_t state_95 = IDLE; +const struct Chord chord_95 PROGMEM = {H_BOT8 + H_BOT9, NUM, &state_95, NULL, KC_RCTL, 0, one_shot_key}; +uint8_t state_96 = IDLE; +const struct Chord chord_96 PROGMEM = {H_BOT9 + H_BOT0, NUM, &state_96, NULL, KC_RSFT, 0, one_shot_key}; +uint8_t state_97 = IDLE; +const struct Chord chord_97 PROGMEM = {H_BOT1 + H_BOT0, NUM, &state_97, NULL, KC_SPACE, 0, single_dance}; +uint8_t state_98 = IDLE; +const struct Chord chord_98 PROGMEM = {H_TOP7, MOV, &state_98, NULL, KC_HOME, 0, single_dance}; +uint8_t state_99 = IDLE; +const struct Chord chord_99 PROGMEM = {H_TOP8, MOV, &state_99, NULL, KC_UP, 0, single_dance}; +uint8_t state_100 = IDLE; +const struct Chord chord_100 PROGMEM = {H_TOP9, MOV, &state_100, NULL, KC_END, 0, single_dance}; +uint8_t state_101 = IDLE; +const struct Chord chord_101 PROGMEM = {H_TOP0, MOV, &state_101, NULL, KC_PGUP, 0, single_dance}; +uint8_t state_102 = IDLE; +const struct Chord chord_102 PROGMEM = {H_BOT3, MOV, &state_102, NULL, KC_LSFT, 0, single_dance}; +uint8_t state_103 = IDLE; +const struct Chord chord_103 PROGMEM = {H_BOT4, MOV, &state_103, NULL, KC_LCTL, 0, single_dance}; +uint8_t state_104 = IDLE; +const struct Chord chord_104 PROGMEM = {H_BOT5, MOV, &state_104, NULL, KC_LALT, 0, single_dance}; +uint8_t state_105 = IDLE; +const struct Chord chord_105 PROGMEM = {H_BOT6, MOV, &state_105, NULL, KC_LGUI, 0, single_dance}; +uint8_t state_106 = IDLE; +const struct Chord chord_106 PROGMEM = {H_BOT7, MOV, &state_106, NULL, KC_LEFT, 0, single_dance}; +uint8_t state_107 = IDLE; +const struct Chord chord_107 PROGMEM = {H_BOT8, MOV, &state_107, NULL, KC_DOWN, 0, single_dance}; +uint8_t state_108 = IDLE; +const struct Chord chord_108 PROGMEM = {H_BOT9, MOV, &state_108, NULL, KC_RIGHT, 0, single_dance}; +uint8_t state_109 = IDLE; +const struct Chord chord_109 PROGMEM = {H_BOT0, MOV, &state_109, NULL, KC_PGDN, 0, single_dance}; +uint8_t state_110 = IDLE; +const struct Chord chord_110 PROGMEM = {H_TOP7, MOUSE, &state_110, NULL, KC_BTN1, 0, single_dance}; +uint8_t state_111 = IDLE; +const struct Chord chord_111 PROGMEM = {H_TOP8, MOUSE, &state_111, NULL, KC_MS_U, 0, single_dance}; +uint8_t state_112 = IDLE; +const struct Chord chord_112 PROGMEM = {H_TOP9, MOUSE, &state_112, NULL, KC_BTN2, 0, single_dance}; +uint8_t state_113 = IDLE; +const struct Chord chord_113 PROGMEM = {H_TOP0, MOUSE, &state_113, NULL, KC_WH_U, 0, single_dance}; +uint8_t state_114 = IDLE; +const struct Chord chord_114 PROGMEM = {H_BOT3, MOUSE, &state_114, NULL, KC_LSFT, 0, single_dance}; +uint8_t state_115 = IDLE; +const struct Chord chord_115 PROGMEM = {H_BOT4, MOUSE, &state_115, NULL, KC_LCTL, 0, single_dance}; +uint8_t state_116 = IDLE; +const struct Chord chord_116 PROGMEM = {H_BOT5, MOUSE, &state_116, NULL, KC_LALT, 0, single_dance}; +uint8_t state_117 = IDLE; +const struct Chord chord_117 PROGMEM = {H_BOT6, MOUSE, &state_117, NULL, KC_LGUI, 0, single_dance}; +uint8_t state_118 = IDLE; +const struct Chord chord_118 PROGMEM = {H_BOT7, MOUSE, &state_118, NULL, KC_MS_L, 0, single_dance}; +uint8_t state_119 = IDLE; +const struct Chord chord_119 PROGMEM = {H_BOT8, MOUSE, &state_119, NULL, KC_MS_D, 0, single_dance}; +uint8_t state_120 = IDLE; +const struct Chord chord_120 PROGMEM = {H_BOT9, MOUSE, &state_120, NULL, KC_MS_R, 0, single_dance}; +uint8_t state_121 = IDLE; +const struct Chord chord_121 PROGMEM = {H_BOT0, MOUSE, &state_121, NULL, KC_WH_D, 0, single_dance}; +uint8_t state_122 = IDLE; +const struct Chord chord_122 PROGMEM = {H_TOP1, ASETNIOP, &state_122, NULL, KC_A, 0, single_dance}; +uint8_t state_123 = IDLE; +const struct Chord chord_123 PROGMEM = {H_TOP2, ASETNIOP, &state_123, NULL, KC_S, 0, single_dance}; +uint8_t state_124 = IDLE; +const struct Chord chord_124 PROGMEM = {H_TOP3, ASETNIOP, &state_124, NULL, KC_E, 0, single_dance}; +uint8_t state_125 = IDLE; +const struct Chord chord_125 PROGMEM = {H_TOP4, ASETNIOP, &state_125, NULL, KC_T, 0, single_dance}; +uint8_t state_126 = IDLE; +const struct Chord chord_126 PROGMEM = {H_TOP7, ASETNIOP, &state_126, NULL, KC_N, 0, single_dance}; +uint8_t state_127 = IDLE; +const struct Chord chord_127 PROGMEM = {H_TOP8, ASETNIOP, &state_127, NULL, KC_I, 0, single_dance}; +uint8_t state_128 = IDLE; +const struct Chord chord_128 PROGMEM = {H_TOP9, ASETNIOP, &state_128, NULL, KC_O, 0, single_dance}; +uint8_t state_129 = IDLE; +const struct Chord chord_129 PROGMEM = {H_TOP0, ASETNIOP, &state_129, NULL, KC_P, 0, single_dance}; +uint8_t state_130 = IDLE; +const struct Chord chord_130 PROGMEM = {H_TOP1 + H_TOP2, ASETNIOP, &state_130, NULL, KC_W, 0, single_dance}; +uint8_t state_131 = IDLE; +const struct Chord chord_131 PROGMEM = {H_TOP2 + H_TOP3, ASETNIOP, &state_131, NULL, KC_D, 0, single_dance}; +uint8_t state_132 = IDLE; +const struct Chord chord_132 PROGMEM = {H_TOP3 + H_TOP4, ASETNIOP, &state_132, NULL, KC_R, 0, single_dance}; +uint8_t state_133 = IDLE; +const struct Chord chord_133 PROGMEM = {H_TOP4 + H_TOP7, ASETNIOP, &state_133, NULL, KC_B, 0, single_dance}; +uint8_t state_134 = IDLE; +const struct Chord chord_134 PROGMEM = {H_TOP7 + H_TOP8, ASETNIOP, &state_134, NULL, KC_H, 0, single_dance}; +uint8_t state_135 = IDLE; +const struct Chord chord_135 PROGMEM = {H_TOP8 + H_TOP9, ASETNIOP, &state_135, NULL, KC_L, 0, single_dance}; +uint8_t state_136 = IDLE; +const struct Chord chord_136 PROGMEM = {H_TOP9 + H_TOP0, ASETNIOP, &state_136, NULL, KC_SCOLON, 0, single_dance}; +uint8_t state_137 = IDLE; +const struct Chord chord_137 PROGMEM = {H_TOP1 + H_TOP3, ASETNIOP, &state_137, NULL, KC_X, 0, single_dance}; +uint8_t state_138 = IDLE; +const struct Chord chord_138 PROGMEM = {H_TOP2 + H_TOP4, ASETNIOP, &state_138, NULL, KC_C, 0, single_dance}; +uint8_t state_139 = IDLE; +const struct Chord chord_139 PROGMEM = {H_TOP3 + H_TOP7, ASETNIOP, &state_139, NULL, KC_Y, 0, single_dance}; +uint8_t state_140 = IDLE; +const struct Chord chord_140 PROGMEM = {H_TOP4 + H_TOP8, ASETNIOP, &state_140, NULL, KC_V, 0, single_dance}; +uint8_t state_141 = IDLE; +const struct Chord chord_141 PROGMEM = {H_TOP7 + H_TOP9, ASETNIOP, &state_141, NULL, KC_U, 0, single_dance}; +uint8_t state_142 = IDLE; +const struct Chord chord_142 PROGMEM = {H_TOP1 + H_TOP4, ASETNIOP, &state_142, NULL, KC_F, 0, single_dance}; +uint8_t state_143 = IDLE; +const struct Chord chord_143 PROGMEM = {H_TOP2 + H_TOP7, ASETNIOP, &state_143, NULL, KC_J, 0, single_dance}; +uint8_t state_144 = IDLE; +const struct Chord chord_144 PROGMEM = {H_TOP3 + H_TOP8, ASETNIOP, &state_144, NULL, KC_COMMA, 0, single_dance}; +uint8_t state_145 = IDLE; +const struct Chord chord_145 PROGMEM = {H_TOP4 + H_TOP9, ASETNIOP, &state_145, NULL, KC_G, 0, single_dance}; +uint8_t state_146 = IDLE; +const struct Chord chord_146 PROGMEM = {H_TOP7 + H_TOP0, ASETNIOP, &state_146, NULL, KC_M, 0, single_dance}; +uint8_t state_147 = IDLE; +const struct Chord chord_147 PROGMEM = {H_TOP1 + H_TOP7, ASETNIOP, &state_147, NULL, KC_Q, 0, single_dance}; +uint8_t state_148 = IDLE; +const struct Chord chord_148 PROGMEM = {H_TOP2 + H_TOP8, ASETNIOP, &state_148, NULL, KC_K, 0, single_dance}; +uint8_t state_149 = IDLE; +const struct Chord chord_149 PROGMEM = {H_TOP3 + H_TOP9, ASETNIOP, &state_149, NULL, KC_MINUS, 0, single_dance}; +uint8_t state_150 = IDLE; +const struct Chord chord_150 PROGMEM = {H_TOP4 + H_TOP0, ASETNIOP, &state_150, NULL, KC_BSPC, 0, single_dance}; +uint8_t state_151 = IDLE; +const struct Chord chord_151 PROGMEM = {H_TOP1 + H_TOP8, ASETNIOP, &state_151, NULL, KC_Z, 0, single_dance}; +uint8_t state_152 = IDLE; +const struct Chord chord_152 PROGMEM = {H_TOP2 + H_TOP9, ASETNIOP, &state_152, NULL, KC_DOT, 0, single_dance}; +uint8_t state_153 = IDLE; +const struct Chord chord_153 PROGMEM = {H_TOP3 + H_TOP0, ASETNIOP, &state_153, NULL, KC_QUOTE, 0, single_dance}; +uint8_t state_154 = IDLE; +const struct Chord chord_154 PROGMEM = {H_TOP1 + H_TOP9, ASETNIOP, &state_154, NULL, KC_LBRACKET, 0, single_dance}; +uint8_t state_155 = IDLE; +const struct Chord chord_155 PROGMEM = {H_TOP2 + H_TOP0, ASETNIOP, &state_155, NULL, KC_RBRACKET, 0, single_dance}; +uint8_t state_156 = IDLE; +const struct Chord chord_156 PROGMEM = {H_TOP1 + H_TOP0, ASETNIOP, &state_156, NULL, KC_SLASH, 0, single_dance}; +uint8_t state_157 = IDLE; +const struct Chord chord_157 PROGMEM = {H_TOP5, ASETNIOP, &state_157, NULL, KC_ESC, 0, single_dance}; +uint8_t state_158 = IDLE; +const struct Chord chord_158 PROGMEM = {H_TOP6, ASETNIOP, &state_158, NULL, KC_DEL, 0, single_dance}; +uint8_t state_159 = IDLE; +const struct Chord chord_159 PROGMEM = {H_BOT4, ASETNIOP, &state_159, NULL, KC_LSFT, 0, single_dance}; +uint8_t state_160 = IDLE; +const struct Chord chord_160 PROGMEM = {H_BOT5, ASETNIOP, &state_160, NULL, KC_LCTL, 0, single_dance}; +uint8_t state_161 = IDLE; +const struct Chord chord_161 PROGMEM = {H_BOT6, ASETNIOP, &state_161, NULL, KC_LALT, 0, single_dance}; +uint8_t state_162 = IDLE; +uint8_t counter_162 = 0; +const struct Chord chord_162 PROGMEM = {H_BOT7, ASETNIOP, &state_162, &counter_162, KC_SPACE, ASETNIOP_123, key_layer_dance}; +uint8_t state_163 = IDLE; +const struct Chord chord_163 PROGMEM = {H_TOP5 + H_TOP6, ASETNIOP, &state_163, NULL, KC_LGUI, 0, single_dance}; +uint8_t state_164 = IDLE; +const struct Chord chord_164 PROGMEM = {H_TOP1 + H_TOP2 + H_TOP3 + H_TOP4, ASETNIOP, &state_164, NULL, QWERTY, 0, perm_pseudolayer}; +uint8_t state_165 = IDLE; +const struct Chord chord_165 PROGMEM = {H_BOT4 + H_BOT7, ASETNIOP, &state_165, NULL, ASETNIOP_FN, 0, temp_pseudolayer}; +uint8_t state_166 = IDLE; +const struct Chord chord_166 PROGMEM = {H_TOP1, ASETNIOP_123, &state_166, NULL, KC_1, 0, single_dance}; +uint8_t state_167 = IDLE; +const struct Chord chord_167 PROGMEM = {H_TOP2, ASETNIOP_123, &state_167, NULL, KC_2, 0, single_dance}; +uint8_t state_168 = IDLE; +const struct Chord chord_168 PROGMEM = {H_TOP3, ASETNIOP_123, &state_168, NULL, KC_3, 0, single_dance}; +uint8_t state_169 = IDLE; +const struct Chord chord_169 PROGMEM = {H_TOP4, ASETNIOP_123, &state_169, NULL, KC_4, 0, single_dance}; +uint8_t state_170 = IDLE; +const struct Chord chord_170 PROGMEM = {H_TOP7, ASETNIOP_123, &state_170, NULL, KC_7, 0, single_dance}; +uint8_t state_171 = IDLE; +const struct Chord chord_171 PROGMEM = {H_TOP8, ASETNIOP_123, &state_171, NULL, KC_8, 0, single_dance}; +uint8_t state_172 = IDLE; +const struct Chord chord_172 PROGMEM = {H_TOP9, ASETNIOP_123, &state_172, NULL, KC_9, 0, single_dance}; +uint8_t state_173 = IDLE; +const struct Chord chord_173 PROGMEM = {H_TOP0, ASETNIOP_123, &state_173, NULL, KC_0, 0, single_dance}; +uint8_t state_174 = IDLE; +const struct Chord chord_174 PROGMEM = {H_TOP3 + H_TOP4, ASETNIOP_123, &state_174, NULL, KC_5, 0, single_dance}; +uint8_t state_175 = IDLE; +const struct Chord chord_175 PROGMEM = {H_TOP4 + H_TOP7, ASETNIOP_123, &state_175, NULL, KC_EQUAL, 0, single_dance}; +uint8_t state_176 = IDLE; +const struct Chord chord_176 PROGMEM = {H_TOP7 + H_TOP8, ASETNIOP_123, &state_176, NULL, KC_6, 0, single_dance}; +uint8_t state_177 = IDLE; +const struct Chord chord_177 PROGMEM = {H_TOP8 + H_TOP9, ASETNIOP_123, &state_177, NULL, KC_BSLASH, 0, single_dance}; +uint8_t state_178 = IDLE; +const struct Chord chord_178 PROGMEM = {H_TOP9 + H_TOP0, ASETNIOP_123, &state_178, NULL, KC_SCOLON, 0, single_dance}; +uint8_t state_179 = IDLE; +const struct Chord chord_179 PROGMEM = {H_TOP4 + H_TOP0, ASETNIOP_123, &state_179, NULL, KC_BSPC, 0, single_dance}; +uint8_t state_180 = IDLE; +const struct Chord chord_180 PROGMEM = {H_TOP5, ASETNIOP_123, &state_180, NULL, KC_ESC, 0, single_dance}; +uint8_t state_181 = IDLE; +const struct Chord chord_181 PROGMEM = {H_TOP6, ASETNIOP_123, &state_181, NULL, KC_DEL, 0, single_dance}; +uint8_t state_182 = IDLE; +const struct Chord chord_182 PROGMEM = {H_BOT4, ASETNIOP_123, &state_182, NULL, KC_LSFT, 0, single_dance}; +uint8_t state_183 = IDLE; +const struct Chord chord_183 PROGMEM = {H_BOT5, ASETNIOP_123, &state_183, NULL, KC_LCTL, 0, single_dance}; +uint8_t state_184 = IDLE; +const struct Chord chord_184 PROGMEM = {H_BOT6, ASETNIOP_123, &state_184, NULL, KC_LALT, 0, single_dance}; +uint8_t state_185 = IDLE; +const struct Chord chord_185 PROGMEM = {H_TOP5 + H_TOP6, ASETNIOP_123, &state_185, NULL, KC_LGUI, 0, single_dance}; +uint8_t state_186 = IDLE; +const struct Chord chord_186 PROGMEM = {H_TOP1, ASETNIOP_FN, &state_186, NULL, KC_HOME, 0, single_dance}; +uint8_t state_187 = IDLE; +const struct Chord chord_187 PROGMEM = {H_TOP2, ASETNIOP_FN, &state_187, NULL, KC_PGDN, 0, single_dance}; +uint8_t state_188 = IDLE; +const struct Chord chord_188 PROGMEM = {H_TOP3, ASETNIOP_FN, &state_188, NULL, KC_PGUP, 0, single_dance}; +uint8_t state_189 = IDLE; +const struct Chord chord_189 PROGMEM = {H_TOP4, ASETNIOP_FN, &state_189, NULL, KC_END, 0, single_dance}; +uint8_t state_190 = IDLE; +const struct Chord chord_190 PROGMEM = {H_TOP7, ASETNIOP_FN, &state_190, NULL, KC_LEFT, 0, single_dance}; +uint8_t state_191 = IDLE; +const struct Chord chord_191 PROGMEM = {H_TOP8, ASETNIOP_FN, &state_191, NULL, KC_DOWN, 0, single_dance}; +uint8_t state_192 = IDLE; +const struct Chord chord_192 PROGMEM = {H_TOP9, ASETNIOP_FN, &state_192, NULL, KC_UP, 0, single_dance}; +uint8_t state_193 = IDLE; +const struct Chord chord_193 PROGMEM = {H_TOP0, ASETNIOP_FN, &state_193, NULL, KC_RIGHT, 0, single_dance}; +uint8_t state_194 = IDLE; +const struct Chord chord_194 PROGMEM = {H_TOP1 + H_TOP2, ASETNIOP_FN, &state_194, NULL, KC_F1, 0, single_dance}; +uint8_t state_195 = IDLE; +const struct Chord chord_195 PROGMEM = {H_TOP2 + H_TOP3, ASETNIOP_FN, &state_195, NULL, KC_F2, 0, single_dance}; +uint8_t state_196 = IDLE; +const struct Chord chord_196 PROGMEM = {H_TOP3 + H_TOP4, ASETNIOP_FN, &state_196, NULL, KC_F3, 0, single_dance}; +uint8_t state_197 = IDLE; +const struct Chord chord_197 PROGMEM = {H_TOP4 + H_TOP7, ASETNIOP_FN, &state_197, NULL, KC_F4, 0, single_dance}; +uint8_t state_198 = IDLE; +const struct Chord chord_198 PROGMEM = {H_TOP7 + H_TOP8, ASETNIOP_FN, &state_198, NULL, KC_F5, 0, single_dance}; +uint8_t state_199 = IDLE; +const struct Chord chord_199 PROGMEM = {H_TOP8 + H_TOP9, ASETNIOP_FN, &state_199, NULL, KC_F6, 0, single_dance}; +uint8_t state_200 = IDLE; +const struct Chord chord_200 PROGMEM = {H_TOP9 + H_TOP0, ASETNIOP_FN, &state_200, NULL, KC_F7, 0, single_dance}; +uint8_t state_201 = IDLE; +const struct Chord chord_201 PROGMEM = {H_TOP1 + H_TOP3, ASETNIOP_FN, &state_201, NULL, KC_F10, 0, single_dance}; +uint8_t state_202 = IDLE; +const struct Chord chord_202 PROGMEM = {H_TOP8 + H_TOP0, ASETNIOP_FN, &state_202, NULL, KC_F8, 0, single_dance}; +uint8_t state_203 = IDLE; +const struct Chord chord_203 PROGMEM = {H_TOP1 + H_TOP4, ASETNIOP_FN, &state_203, NULL, KC_F11, 0, single_dance}; +uint8_t state_204 = IDLE; +const struct Chord chord_204 PROGMEM = {H_TOP7 + H_TOP0, ASETNIOP_FN, &state_204, NULL, KC_F9, 0, single_dance}; +uint8_t state_205 = IDLE; +const struct Chord chord_205 PROGMEM = {H_TOP1 + H_TOP7, ASETNIOP_FN, &state_205, NULL, KC_F12, 0, single_dance}; +uint8_t state_206 = IDLE; +const struct Chord chord_206 PROGMEM = {H_TOP4 + H_TOP0, ASETNIOP_FN, &state_206, NULL, KC_BSPC, 0, single_dance}; +uint8_t state_207 = IDLE; +const struct Chord chord_207 PROGMEM = {H_TOP5, ASETNIOP_FN, &state_207, NULL, KC_ESC, 0, single_dance}; +uint8_t state_208 = IDLE; +const struct Chord chord_208 PROGMEM = {H_TOP6, ASETNIOP_FN, &state_208, NULL, KC_DEL, 0, single_dance}; +uint8_t state_209 = IDLE; +const struct Chord chord_209 PROGMEM = {H_BOT4, ASETNIOP_FN, &state_209, NULL, KC_LSFT, 0, single_dance}; +uint8_t state_210 = IDLE; +const struct Chord chord_210 PROGMEM = {H_BOT5, ASETNIOP_FN, &state_210, NULL, KC_LCTL, 0, single_dance}; +uint8_t state_211 = IDLE; +const struct Chord chord_211 PROGMEM = {H_BOT6, ASETNIOP_FN, &state_211, NULL, KC_LALT, 0, single_dance}; +uint8_t state_212 = IDLE; +const struct Chord chord_212 PROGMEM = {H_TOP5 + H_TOP6, ASETNIOP_FN, &state_212, NULL, KC_LGUI, 0, single_dance}; + +const struct Chord* const list_of_chords[] PROGMEM = { + &chord_0, &chord_1, &chord_2, &chord_3, &chord_4, &chord_5, &chord_6, &chord_7, &chord_8, &chord_9, &chord_10, &chord_11, &chord_12, &chord_13, &chord_14, &chord_15, &chord_16, &chord_17, &chord_18, &chord_19, &chord_20, &chord_21, &chord_22, &chord_23, &chord_24, &chord_25, &chord_26, &chord_27, &chord_28, &chord_29, &chord_30, &chord_31, &chord_32, &chord_33, &chord_34, &chord_35, &chord_36, &chord_37, &chord_38, &chord_39, &chord_40, &chord_41, &chord_42, &chord_43, &chord_44, &chord_45, &chord_46, &chord_47, &chord_48, &chord_49, &chord_50, &chord_51, &chord_52, &chord_53, &chord_54, &chord_55, &chord_56, &chord_57, &chord_58, &chord_59, &chord_60, &chord_61, &chord_62, &chord_63, &chord_64, &chord_65, &chord_66, &chord_67, &chord_68, &chord_69, &chord_70, &chord_71, &chord_72, &chord_73, &chord_74, &chord_75, &chord_76, &chord_77, &chord_78, &chord_79, &chord_80, &chord_81, &chord_82, &chord_83, &chord_84, &chord_85, &chord_86, &chord_87, &chord_88, &chord_89, &chord_90, &chord_91, &chord_92, &chord_93, &chord_94, &chord_95, &chord_96, &chord_97, &chord_98, &chord_99, &chord_100, &chord_101, &chord_102, &chord_103, &chord_104, &chord_105, &chord_106, &chord_107, &chord_108, &chord_109, &chord_110, &chord_111, &chord_112, &chord_113, &chord_114, &chord_115, &chord_116, &chord_117, &chord_118, &chord_119, &chord_120, &chord_121, &chord_122, &chord_123, &chord_124, &chord_125, &chord_126, &chord_127, &chord_128, &chord_129, &chord_130, &chord_131, &chord_132, &chord_133, &chord_134, &chord_135, &chord_136, &chord_137, &chord_138, &chord_139, &chord_140, &chord_141, &chord_142, &chord_143, &chord_144, &chord_145, &chord_146, &chord_147, &chord_148, &chord_149, &chord_150, &chord_151, &chord_152, &chord_153, &chord_154, &chord_155, &chord_156, &chord_157, &chord_158, &chord_159, &chord_160, &chord_161, &chord_162, &chord_163, &chord_164, &chord_165, &chord_166, &chord_167, &chord_168, &chord_169, &chord_170, &chord_171, &chord_172, &chord_173, &chord_174, &chord_175, &chord_176, &chord_177, &chord_178, &chord_179, &chord_180, &chord_181, &chord_182, &chord_183, &chord_184, &chord_185, &chord_186, &chord_187, &chord_188, &chord_189, &chord_190, &chord_191, &chord_192, &chord_193, &chord_194, &chord_195, &chord_196, &chord_197, &chord_198, &chord_199, &chord_200, &chord_201, &chord_202, &chord_203, &chord_204, &chord_205, &chord_206, &chord_207, &chord_208, &chord_209, &chord_210, &chord_211, &chord_212 +}; + +const uint16_t** const leader_triggers PROGMEM = NULL; +void (*leader_functions[]) (void) = {}; + +#define NUMBER_OF_CHORDS 213 +#define NUMBER_OF_LEADER_COMBOS 0 + +bool are_hashed_keycodes_in_sound(HASH_TYPE keycodes_hash, HASH_TYPE sound) { + return (keycodes_hash & sound) == keycodes_hash; +} + +uint8_t keycode_to_index(uint16_t keycode) { + return keycode - FIRST_INTERNAL_KEYCODE; +} + +void sound_keycode_array(uint16_t keycode) { + uint8_t index = keycode_to_index(keycode); + keycode_index++; + keycodes_buffer_array[index] = keycode_index; +} + +void silence_keycode_hash_array(HASH_TYPE keycode_hash) { + for (int i = 0; i < NUMBER_OF_KEYS; i++) { + bool index_in_hash = ((HASH_TYPE) 1 << i) & keycode_hash; + if (index_in_hash) { + uint8_t current_val = keycodes_buffer_array[i]; + keycodes_buffer_array[i] = 0; + for (int j = 0; j < NUMBER_OF_KEYS; j++) { + if (keycodes_buffer_array[j] > current_val) { + keycodes_buffer_array[j]--; + } + } + keycode_index--; + } + } +} + +bool are_hashed_keycodes_in_array(HASH_TYPE keycode_hash) { + for (int i = 0; i < NUMBER_OF_KEYS; i++) { + bool index_in_hash = ((HASH_TYPE) 1 << i) & keycode_hash; + bool index_in_array = (bool) keycodes_buffer_array[i]; + if (index_in_hash && !index_in_array) { + return false; + } + } + return true; +} + +void kill_one_shots(void) { + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + if (*chord->state == IN_ONE_SHOT) { + *chord->state = RESTART; + chord->function(chord); + if (*chord->state == RESTART) { + *chord->state = IDLE; + } + } + } +} + +void process_finished_dances(void) { + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + if (*chord->state == ACTIVATED) { + *chord->state = PRESS_FROM_ACTIVE; + chord->function(chord); + if (a_key_went_through) { + kill_one_shots(); + } + dance_timer = timer_read(); + } else if (*chord->state == IDLE_IN_DANCE) { + *chord->state = FINISHED; + chord->function(chord); + if (*chord->state == FINISHED) { + *chord->state = RESTART; + if (*chord->state == RESTART) { + *chord->state = IDLE; + } + } + } else if (*chord->state == PRESS_FROM_ACTIVE) { + *chord->state = FINISHED_FROM_ACTIVE; + chord->function(chord); + if (a_key_went_through) { + kill_one_shots(); + } + dance_timer = timer_read(); + } + } +} + +uint8_t keycodes_buffer_array_min(uint8_t* first_keycode_index) { + for (int i = 0; i < NUMBER_OF_KEYS; i++) { + if (keycodes_buffer_array[i] == 1) { + if (first_keycode_index != NULL) { + *first_keycode_index = (uint8_t) i; + } + return 1; + } + } + return 0; +} + +void remove_subchords(void) { + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + if (!(*chord->state == READY || *chord->state == READY_IN_DANCE || *chord->state == READY_LOCKED)) { + continue; + } + + struct Chord chord_storage_2; + struct Chord* chord_ptr_2; + struct Chord* chord_2; + for (int j = 0; j < NUMBER_OF_CHORDS; j++) { + if (i == j) {continue;} + + chord_ptr_2 = (struct Chord*) pgm_read_word (&list_of_chords[j]); + memcpy_P(&chord_storage_2, chord_ptr_2, sizeof(struct Chord)); + chord_2 = &chord_storage_2; + + if (are_hashed_keycodes_in_sound(chord_2->keycodes_hash, chord->keycodes_hash)) { + if (*chord_2->state == READY) { + *chord_2->state = IDLE; + } + if (*chord_2->state == READY_IN_DANCE) { + *chord_2->state = IDLE_IN_DANCE; + } + if (*chord_2->state == READY_LOCKED) { + *chord_2->state = LOCKED; + } + } + } + } +} + +void process_ready_chords(void) { + uint8_t first_keycode_index = 0; + while (keycodes_buffer_array_min(&first_keycode_index)) { + // find ready chords + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + // if the chord does not contain the first keycode + bool contains_first_keycode = ((uint32_t) 1 << first_keycode_index) & chord->keycodes_hash; + if (!contains_first_keycode) { + continue; + } + + if (!are_hashed_keycodes_in_array(chord->keycodes_hash)){ + continue; + } + + if (*chord->state == LOCKED) { + *chord->state = READY_LOCKED; + continue; + } + + if (!(chord->pseudolayer == current_pseudolayer || chord->pseudolayer == ALWAYS_ON)) { + continue; + } + + if (*chord->state == IDLE) { + *chord->state = READY; + continue; + } + + if (*chord->state == IDLE_IN_DANCE) { + *chord->state = READY_IN_DANCE; + } + } + + // remove subchords + remove_subchords(); + + // execute logic + // this should be only one chord + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + if (*chord->state == READY_LOCKED) { + *chord->state = RESTART; + chord->function(chord); + if (*chord->state == RESTART) { + *chord->state = IDLE; + } + break; + } + + if (*chord->state == READY || *chord->state == READY_IN_DANCE) { + if (last_chord && last_chord != chord) { + process_finished_dances(); + } + + bool lock_next_prev_state = lock_next; + + *chord->state = ACTIVATED; + chord->function(chord); + dance_timer = timer_read(); + + if (lock_next && lock_next == lock_next_prev_state) { + lock_next = false; + *chord->state = PRESS_FROM_ACTIVE; + chord->function(chord); + if (*chord->state == PRESS_FROM_ACTIVE) { + *chord->state = LOCKED; + } + if (a_key_went_through) { + kill_one_shots(); + } + } + break; + } + } + + // silence notes + silence_keycode_hash_array(chord->keycodes_hash); + } +} + +void deactivate_active_chords(uint16_t keycode) { + HASH_TYPE hash = (HASH_TYPE)1 << (keycode - SAFE_RANGE); + bool broken; + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + broken = are_hashed_keycodes_in_sound(hash, chord->keycodes_hash); + if (!broken) { + continue; + } + + switch (*chord->state) { + case ACTIVATED: + *chord->state = DEACTIVATED; + chord->function(chord); + + if (*chord->state == DEACTIVATED) { + dance_timer = timer_read(); + *chord->state = IDLE_IN_DANCE; + } + if (*chord->state != IN_ONE_SHOT) { + kill_one_shots(); + } + break; + case PRESS_FROM_ACTIVE: + case FINISHED_FROM_ACTIVE: + *chord->state = RESTART; + chord->function(chord); + if (*chord->state == RESTART) { + *chord->state = IDLE; + } + kill_one_shots(); + break; + default: + break; + } + } + +} + +void process_command(void) { + command_mode = 0; + for (int i = 0; i < COMMAND_MAX_LENGTH; i++) { + if (command_buffer[i]) { + register_code(command_buffer[i]); + } + send_keyboard_report(); + } + wait_ms(TAP_TIMEOUT); + for (int i = 0; i < COMMAND_MAX_LENGTH; i++) { + if (command_buffer[i]) { + unregister_code(command_buffer[i]); + } + send_keyboard_report(); + } + for (int i = 0; i < COMMAND_MAX_LENGTH; i++) { + command_buffer[i] = 0; + } + command_ind = 0; +} + +void process_leader(void) { + in_leader_mode = false; + for (int i = 0; i < NUMBER_OF_LEADER_COMBOS; i++) { + uint16_t trigger[LEADER_MAX_LENGTH]; + memcpy_P(trigger, leader_triggers[i], LEADER_MAX_LENGTH * sizeof(uint16_t)); + + if (identical(leader_buffer, trigger)) { + (*leader_functions[i])(); + break; + } + } + for (int i = 0; i < LEADER_MAX_LENGTH; i++) { + leader_buffer[i] = 0; + } +} + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (keycode < FIRST_INTERNAL_KEYCODE || keycode > LAST_INTERNAL_KEYCODE) { + return true; + } + + if (record->event.pressed) { + sound_keycode_array(keycode); + } else { + process_ready_chords(); + deactivate_active_chords(keycode); + } + chord_timer = timer_read(); + leader_timer = timer_read(); + + return false; +} + +void matrix_scan_user(void) { + bool chord_timer_expired = timer_elapsed(chord_timer) > CHORD_TIMEOUT; + if (chord_timer_expired && keycodes_buffer_array_min(NULL)) { + process_ready_chords(); + } + + bool dance_timer_expired = timer_elapsed(dance_timer) > DANCE_TIMEOUT; + if (dance_timer_expired) { // would love to have && in_dance but not sure how + process_finished_dances(); + } + + bool in_command_mode = command_mode == 2; + if (in_command_mode) { + process_command(); + } + + bool leader_timer_expired = timer_elapsed(leader_timer) > LEADER_TIMEOUT; + if (leader_timer_expired && in_leader_mode) { + process_leader(); + } + +} + +void clear(const struct Chord* self) { + if (*self->state == ACTIVATED) { + // kill all chords + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + *chord->state = IDLE; + + if (chord->counter) { + *chord->counter = 0; + } + } + + // clear keyboard + clear_keyboard(); + send_keyboard_report(); + + // switch to default pseudolayer + current_pseudolayer = DEFAULT_PSEUDOLAYER; + + // clear all keyboard states + lock_next = false; + autoshift_mode = true; + command_mode = 0; + in_leader_mode = false; + leader_ind = 0; + dynamic_macro_mode = false; + a_key_went_through = false; + + for (int i = 0; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + dynamic_macro_buffer[i] = 0; + } + } +}
\ No newline at end of file diff --git a/keyboards/butterstick/keymaps/dennytom/keymap_def.json b/keyboards/butterstick/keymaps/dennytom/keymap_def.json new file mode 100644 index 0000000000..16f02ca529 --- /dev/null +++ b/keyboards/butterstick/keymaps/dennytom/keymap_def.json @@ -0,0 +1,309 @@ +{ + "keys": [ + "TOP1", "TOP2", "TOP3", "TOP4", "TOP5", "TOP6", "TOP7", "TOP8", "TOP9", "TOP0", + "BOT1", "BOT2", "BOT3", "BOT4", "BOT5", "BOT6", "BOT7", "BOT8", "BOT9", "BOT0" + ], + "parameters": { + "layout_function_name": "LAYOUT_butter", + "chord_timeout": 100, + "dance_timeout": 200, + "leader_timeout": 750, + "tap_timeout": 50, + "command_max_length": 5, + "leader_max_length": 5, + "dynamic_macro_max_length": 20, + "string_max_length": 16, + "long_press_multiplier": 3, + "default_pseudolayer": "QWERTY" + }, + "layers": [ + { + "type": "auto" + } + ], + "chord_sets": [ + { + "name": "rows", + "chords": [ + ["TOP1"], ["TOP2"], ["TOP3"], ["TOP4"], ["TOP5"], ["TOP6"], ["TOP7"], ["TOP8"], ["TOP9"], ["TOP0"], + ["TOP1", "BOT1"], ["TOP2", "BOT2"], ["TOP3", "BOT3"], ["TOP4", "BOT4"], ["TOP5", "BOT5"], ["TOP6", "BOT6"], ["TOP7", "BOT7"], ["TOP8", "BOT8"], ["TOP9", "BOT9"], ["TOP0", "BOT0"], + ["BOT1"], ["BOT2"], ["BOT3"], ["BOT4"], ["BOT5"], ["BOT6"], ["BOT7"], ["BOT8"], ["BOT9"], ["BOT0"] + ] + }, + { + "name": "cols", + "chords": [ + ["TOP1", "TOP2"], ["TOP2", "TOP3"], ["TOP3", "TOP4"], ["TOP4", "TOP5"], ["TOP5", "TOP6"], ["TOP6", "TOP7"], ["TOP7", "TOP8"], ["TOP8", "TOP9"], ["TOP9", "TOP0"], + ["TOP1", "TOP2", "BOT1", "BOT2"], ["TOP2", "TOP3", "BOT2", "BOT3"], ["TOP3", "TOP4", "BOT3", "BOT4"], ["TOP4", "TOP5", "BOT4", "BOT5"], ["TOP5", "TOP6", "BOT5", "BOT6"], ["TOP6", "TOP7", "BOT6", "BOT7"], ["TOP7", "TOP8", "BOT7", "BOT8"], ["TOP8", "TOP9", "BOT8", "BOT9"], ["TOP9", "TOP0", "BOT9", "BOT0"], + ["BOT1", "BOT2"], ["BOT2", "BOT3"], ["BOT3", "BOT4"], ["BOT4", "BOT5"], ["BOT5", "BOT6"], ["BOT6", "BOT7"], ["BOT7", "BOT8"], ["BOT8", "BOT9"], ["BOT9", "BOT0"] + ] + }, + { + "name": "asetniop", + "chords": [ + ["TOP1"], ["TOP2"], ["TOP3"], ["TOP4"], ["TOP7"], ["TOP8"], ["TOP9"], ["TOP0"], + ["TOP1", "TOP2"], ["TOP2", "TOP3"], ["TOP3", "TOP4"], ["TOP4", "TOP7"], ["TOP7", "TOP8"], ["TOP8", "TOP9"], ["TOP9", "TOP0"], + ["TOP1", "TOP3"], ["TOP2", "TOP4"], ["TOP3", "TOP7"], ["TOP4", "TOP8"], ["TOP7", "TOP9"], ["TOP8", "TOP0"], + ["TOP1", "TOP4"], ["TOP2", "TOP7"], ["TOP3", "TOP8"], ["TOP4", "TOP9"], ["TOP7", "TOP0"], + ["TOP1", "TOP7"], ["TOP2", "TOP8"], ["TOP3", "TOP9"], ["TOP4", "TOP0"], + ["TOP1", "TOP8"], ["TOP2", "TOP9"], ["TOP3", "TOP0"], + ["TOP1", "TOP9"], ["TOP2", "TOP0"], + ["TOP1", "TOP0"] + ] + } + ], + "pseudolayers": [ + { + "name": "ALWAYS_ON", + "chords": [ + { + "type": "chord_set", + "set": "cols", + "keycodes": [ + " ", " ", " ", " ", " ", " ", " ", " ", " ", + "LOCK", " AT", " ", " ", " CMD", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " " + ] + }, + { + "type": "visual", + "chord": [ + "X", "X", " ", " ", " ", " ", " ", " ", "X", "X", + "X", "X", " ", " ", " ", " ", " ", " ", "X", "X" + ], + "keycode": "CLEAR_KB" + } + ] + }, + { + "name": "QWERTY", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + "AS(Q)", "AS(W)", "AS(E)", "AS(R)", "AS(T)", "AS(Y)", "AS(U)", "AS(I)", "AS(O)", "AS(P)", + "AS(A)", "AS(S)", "AS(D)", "AS(F)", "AS(G)", "AS(H)", "AS(J)", "AS(K)", "AS(L)", "AS(;)", + "AS(Z)", "AS(X)", "AS(C)", "AS(V)", "AS(B)", "AS(N)", "AS(M)", "AS(,)", "AS(.)", "AS(/)" + ] + }, + { + "type": "chord_set", + "set": "cols", + "keycodes": [ + " ESC", "MO(MOV)", " TAB", " ", "O(RGUI)", " ", " INS", " DEL", " BSPC", + " ", " ", " ", " ", " ", " ", " ", " ", " ENTER", + "O(LSFT)", "O(LCTL)", "O(LALT)", "O(NUM)", "O(LGUI)", "O(NUM)", "O(RALT)", "O(RCTL)", "O(RSFT)" + ] + }, + { + "type": "simple", + "chord": ["BOT1", "BOT0"], + "keycode": "SPACE" + }, + { + "type": "visual", + "chord": [ + "X", "X", "X", "X", " ", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " ", " " + ], + "keycode": "MO(MOUSE)" + }, + { + "type": "visual", + "chord": [ + "X", "X", "X", "X", " ", " ", "X", "X", "X", "X", + " ", " ", " ", " ", " ", " ", " ", " ", " ", " " + ], + "keycode": "DF(ASETNIOP)" + } + ] + }, + { + "name": "NUM", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + "AS(1)", "AS(2)", "AS(3)", "AS(4)", "AS(5)", "AS(6)", "AS(7)", "AS(8)", "AS(9)", "AS(0)", + " F1", " F2", " F3", " F4", " F5", " F6", " F7", " F8", " F9", " F10", + "AS(`)", "AS(-)", "AS(=)", "AS([)", "AS(])", "AS(\\)", "AS(')", " ", " F11", " F12" + ] + }, + { + "type": "chord_set", + "set": "cols", + "keycodes": [ + " ESC", " ", " TAB", " ", "O(RGUI)", " ", " INS", " DEL", " BSPC", + " ", " ", " ", " ", " ", " ", " ", " ", " ENTER", + "O(LSFT)", "O(LCTL)", "O(LALT)", " ", "O(LGUI)", " ", "O(RALT)", "O(RCTL)", " O(RSFT)" + ] + }, + { + "type": "simple", + "chord": ["BOT1", "BOT0"], + "keycode": "SPACE" + } + ] + }, + { + "name": "MOV", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + " ", " ", " ", " ", " ", " ", " HOME", " UP", " END", " PGUP", + " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", + " ", " ", " LSFT", " LCTL", " LALT", " LGUI", " LEFT", " DOWN", "RIGHT", " PGDN" + ] + } + ] + }, + { + "name": "MOUSE", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + " ", " ", " ", " ", " ", " ", " BTN1", " MS_U", " BTN2", " WH_U", + " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", + " ", " ", " LSFT", " LCTL", " LALT", " LGUI", " MS_L", " MS_D", " MS_R", " WH_D" + ] + } + ] + }, + { + "name": "ASETNIOP", + "chords": [ + { + "type": "chord_set", + "set": "asetniop", + "keycodes": [ + "A", "S", "E", "T", "N", "I", "O", "P", + "W", "D", "R", "B", "H", "L", ";", + "X", "C", "Y", "V", "U", "", + "F", "J", ",", "G", "M", + "Q", "K", "-", "BSPC", + "Z", ".", "'", + "[", "]", + "/" + ] + }, + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + " ", " ", " ", " ", " ESC", " DEL", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", + " ", " ", " ", "LSFT", "LCTL", "LALT", "KL(SPACE, ASETNIOP_123)", "", "", "" + ] + }, + { + "type": "chord_set", + "set": "cols", + "keycodes": [ + " ", " ", " ", " ", "LGUI", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " " + ] + }, + { + "type": "visual", + "chord": [ + "X", "X", "X", "X", " ", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " ", " " + ], + "keycode": "DF(QWERTY)" + }, + { + "type": "visual", + "chord": [ + " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", + " ", " ", " ", "X", " ", " ", "X", " ", " ", " " + ], + "keycode": "MO(ASETNIOP_FN)" + } + ] + }, + { + "name": "ASETNIOP_123", + "chords": [ + { + "type": "chord_set", + "set": "asetniop", + "keycodes": [ + "1", "2", "3", "4", "7", "8", "9", "0", + " ", " ", "5", "=", "6", "\\", ";", + " ", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", + " ", " ", " ", "BSPC", + " ", " ", " ", + " ", " ", + " " + ] + }, + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + " ", " ", " ", " ", " ESC", " DEL", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", + " ", " ", " ", "LSFT", "LCTL", "LALT", " ", " ", " ", " " + ] + }, + { + "type": "chord_set", + "set": "cols", + "keycodes": [ + " ", " ", " ", " ", "LGUI", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " " + ] + } + ] + }, + { + "name": "ASETNIOP_FN", + "chords": [ + { + "type": "chord_set", + "set": "asetniop", + "keycodes": [ + "HOME", "PGDN", "PGUP", " END", "LEFT", "DOWN", " UP", "RIGHT", + " F1", " F2", " F3", " F4", " F5", " F6", " F7", + " F10", " ", " ", " ", " ", " F8", + " F11", " ", " ", " ", " F9", + " F12", " ", " ", "BSPC", + " ", " ", " ", + " ", " ", + " " + ] + }, + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + " ", " ", " ", " ", " ESC", " DEL", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", + " ", " ", " ", "LSFT", "LCTL", "LALT", " ", " ", " ", " " + ] + }, + { + "type": "chord_set", + "set": "cols", + "keycodes": [ + " ", " ", " ", " ", "LGUI", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " " + ] + } + ] + } + ], + "leader_sequences": [], + "extra_code": "", + "extra_dependencies": [] +}
\ No newline at end of file diff --git a/keyboards/butterstick/keymaps/dennytom/rules.mk b/keyboards/butterstick/keymaps/dennytom/rules.mk new file mode 100644 index 0000000000..1155f72c04 --- /dev/null +++ b/keyboards/butterstick/keymaps/dennytom/rules.mk @@ -0,0 +1,8 @@ +MOUSEKEY_ENABLE = yes +EXTRAKEY_ENABLE = yes +CONSOLE_ENABLE = no +# COMMAND_ENABLE = no +NKRO_ENABLE = yes + +TMPVAR := $(SRC) +SRC = $(filter-out sten.c, $(TMPVAR))
\ No newline at end of file diff --git a/keyboards/georgi/keymaps/dennytom/README.md b/keyboards/georgi/keymaps/dennytom/README.md new file mode 100644 index 0000000000..14bc1d2045 --- /dev/null +++ b/keyboards/georgi/keymaps/dennytom/README.md @@ -0,0 +1,11 @@ +# # Dennytom's Georgi Layout + +This keymap is using a custom chording engine. Head out to my (DennyTom) user space to find the source files and details. + +To make a real keymap from the JSON file, run + +```sh +python3 parser.py keymap_def.json keymap.c +``` + +Likely will change with use. I enjoy the modifiers on the "home row".
\ No newline at end of file diff --git a/keyboards/georgi/keymaps/dennytom/keymap.c b/keyboards/georgi/keymaps/dennytom/keymap.c new file mode 100644 index 0000000000..2e01917745 --- /dev/null +++ b/keyboards/georgi/keymaps/dennytom/keymap.c @@ -0,0 +1,1208 @@ +#include QMK_KEYBOARD_H + +#define H_TOP1 ((HASH_TYPE) 1 << 0) +#define H_TOP2 ((HASH_TYPE) 1 << 1) +#define H_TOP3 ((HASH_TYPE) 1 << 2) +#define H_TOP4 ((HASH_TYPE) 1 << 3) +#define H_TOP5 ((HASH_TYPE) 1 << 4) +#define H_TOP6 ((HASH_TYPE) 1 << 5) +#define H_TOP7 ((HASH_TYPE) 1 << 6) +#define H_TOP8 ((HASH_TYPE) 1 << 7) +#define H_TOP9 ((HASH_TYPE) 1 << 8) +#define H_TOP10 ((HASH_TYPE) 1 << 9) +#define H_TOP11 ((HASH_TYPE) 1 << 10) +#define H_TOP12 ((HASH_TYPE) 1 << 11) +#define H_BOT1 ((HASH_TYPE) 1 << 12) +#define H_BOT2 ((HASH_TYPE) 1 << 13) +#define H_BOT3 ((HASH_TYPE) 1 << 14) +#define H_BOT4 ((HASH_TYPE) 1 << 15) +#define H_BOT5 ((HASH_TYPE) 1 << 16) +#define H_BOT6 ((HASH_TYPE) 1 << 17) +#define H_BOT7 ((HASH_TYPE) 1 << 18) +#define H_BOT8 ((HASH_TYPE) 1 << 19) +#define H_BOT9 ((HASH_TYPE) 1 << 20) +#define H_BOT10 ((HASH_TYPE) 1 << 21) +#define H_BOT11 ((HASH_TYPE) 1 << 22) +#define H_BOT12 ((HASH_TYPE) 1 << 23) +#define H_THU1 ((HASH_TYPE) 1 << 24) +#define H_THU2 ((HASH_TYPE) 1 << 25) +#define H_THU3 ((HASH_TYPE) 1 << 26) +#define H_THU4 ((HASH_TYPE) 1 << 27) +#define H_THU5 ((HASH_TYPE) 1 << 28) +#define H_THU6 ((HASH_TYPE) 1 << 29) + +enum internal_keycodes { + TOP1 = SAFE_RANGE, + TOP2, TOP3, TOP4, TOP5, TOP6, TOP7, TOP8, TOP9, TOP10, TOP11, TOP12, BOT1, BOT2, BOT3, BOT4, BOT5, BOT6, BOT7, BOT8, BOT9, BOT10, BOT11, BOT12, THU1, THU2, THU3, THU4, THU5, THU6, + FIRST_INTERNAL_KEYCODE = TOP1, + LAST_INTERNAL_KEYCODE = THU6 +}; + +enum pseudolayers { + ALWAYS_ON, QWERTY, NUM, FNC, NAV, MOUSE +}; + +#define CHORD_TIMEOUT 100 +#define DANCE_TIMEOUT 200 +#define LEADER_TIMEOUT 750 +#define TAP_TIMEOUT 50 +#define LONG_PRESS_MULTIPLIER 3 +#define DYNAMIC_MACRO_MAX_LENGTH 20 +#define COMMAND_MAX_LENGTH 5 +#define STRING_MAX_LENGTH 16 +#define LEADER_MAX_LENGTH 5 +#define HASH_TYPE uint32_t +#define NUMBER_OF_KEYS 30 +#define DEFAULT_PSEUDOLAYER QWERTY + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT_georgi(TOP1, TOP2, TOP3, TOP4, TOP5, TOP6, TOP7, TOP8, TOP9, TOP10, TOP11, TOP12, BOT1, BOT2, BOT3, BOT4, BOT5, BOT6, BOT7, BOT8, BOT9, BOT10, BOT11, BOT12, THU1, THU2, THU3, THU4, THU5, THU6), +}; +size_t keymapsCount = 1; + +uint8_t keycodes_buffer_array[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +uint8_t command_buffer[] = { + 0, 0, 0, 0, 0 +}; + +uint16_t leader_buffer[] = { + 0, 0, 0, 0, 0 +}; + +uint8_t dynamic_macro_buffer[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +enum chord_states { + IDLE, + READY, + ACTIVATED, + DEACTIVATED, + PRESS_FROM_ACTIVE, + FINISHED_FROM_ACTIVE, + IDLE_IN_DANCE, + READY_IN_DANCE, + FINISHED, + LOCKED, + READY_LOCKED, + RESTART, + IN_ONE_SHOT +}; + +struct Chord { + uint32_t keycodes_hash; + uint8_t pseudolayer; + uint8_t* state; + uint8_t* counter; + uint16_t value1; + uint8_t value2; + void (*function) (const struct Chord*); +}; + +uint8_t current_pseudolayer = DEFAULT_PSEUDOLAYER; +bool lock_next = false; +uint16_t chord_timer = 0; +uint16_t dance_timer = 0; +bool autoshift_mode = true; +uint8_t keycode_index = 0; +uint8_t command_mode = 0; +uint8_t command_ind = 0; +bool in_leader_mode = false; +uint8_t leader_ind = 0; +uint16_t leader_timer = 0; +uint8_t dynamic_macro_mode = false; +uint8_t dynamic_macro_ind = 0; +bool a_key_went_through = false; +struct Chord* last_chord = NULL; + +bool handle_US_ANSI_shifted_keys(int16_t keycode, bool in) { + bool is_US_ANSI_shifted = true; + + int16_t regular_keycode = KC_NO; + switch (keycode) { + case KC_TILDE: + regular_keycode = KC_GRAVE; + break; + case KC_EXCLAIM: + regular_keycode = KC_1; + break; + case KC_AT: + regular_keycode = KC_2; + break; + case KC_HASH: + regular_keycode = KC_3; + break; + case KC_DOLLAR: + regular_keycode = KC_4; + break; + case KC_PERCENT: + regular_keycode = KC_5; + break; + case KC_CIRCUMFLEX: + regular_keycode = KC_6; + break; + case KC_AMPERSAND: + regular_keycode = KC_7; + break; + case KC_ASTERISK: + regular_keycode = KC_8; + break; + case KC_LEFT_PAREN: + regular_keycode = KC_9; + break; + case KC_RIGHT_PAREN: + regular_keycode = KC_0; + break; + case KC_UNDERSCORE: + regular_keycode = KC_MINUS; + break; + case KC_PLUS: + regular_keycode = KC_EQUAL; + break; + case KC_LEFT_CURLY_BRACE: + regular_keycode = KC_LBRACKET; + break; + case KC_RIGHT_CURLY_BRACE: + regular_keycode = KC_RBRACKET; + break; + case KC_PIPE: + regular_keycode = KC_BSLASH; + break; + case KC_COLON: + regular_keycode = KC_SCOLON; + break; + case KC_DOUBLE_QUOTE: + regular_keycode = KC_QUOTE; + break; + case KC_LEFT_ANGLE_BRACKET: + regular_keycode = KC_COMMA; + break; + case KC_RIGHT_ANGLE_BRACKET: + regular_keycode = KC_DOT; + break; + case KC_QUESTION: + regular_keycode = KC_SLASH; + break; + default: + is_US_ANSI_shifted = false; + } + if (is_US_ANSI_shifted) { + if (in) { + register_code(KC_LSFT); + register_code(regular_keycode); + } else { + unregister_code(regular_keycode); + unregister_code(KC_LSFT); + } + } + return is_US_ANSI_shifted; +} + +void key_in(int16_t keycode) { + if (command_mode == 1 && command_ind < COMMAND_MAX_LENGTH) { + command_buffer[command_ind] = keycode; + command_ind++; + a_key_went_through = true; + } else if (in_leader_mode && leader_ind < LEADER_MAX_LENGTH) { + leader_buffer[leader_ind] = keycode; + leader_ind++; + a_key_went_through = true; + } else if (dynamic_macro_mode && dynamic_macro_ind < DYNAMIC_MACRO_MAX_LENGTH) { + dynamic_macro_buffer[dynamic_macro_ind] = keycode; + dynamic_macro_ind++; + a_key_went_through = true; + } else { + if (!handle_US_ANSI_shifted_keys(keycode, true)) { + register_code(keycode); + } + send_keyboard_report(); + a_key_went_through = true; + } +} + +void key_out(int16_t keycode) { + if (command_mode == 0) { + if (!handle_US_ANSI_shifted_keys(keycode, false)) { + if (command_mode == 0 && in_leader_mode == false && dynamic_macro_mode == false) { + unregister_code(keycode); + } + } + send_keyboard_report(); + } +} + +void tap_key(int16_t keycode) { + key_in(keycode); + wait_ms(TAP_TIMEOUT); + key_out(keycode); +} +const char * const strings[] PROGMEM = { + +}; +void single_dance(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + key_in(self->value1); + break; + case DEACTIVATED: + key_out(self->value1); + *self->state = IDLE; + break; + case RESTART: + key_out(self->value1); + break; + default: + break; + } +} + +void key_layer_dance(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + current_pseudolayer = self->value2; + a_key_went_through = false; + break; + case DEACTIVATED: + case RESTART: + if (!a_key_went_through) { + tap_key(self->value1); + } + current_pseudolayer = self->pseudolayer; + *self->state = IDLE; // does not have effect if the state was RESTART + break; + default: + break; + } +} + +void key_mod_dance(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + key_in(self->value2); + a_key_went_through = false; + break; + case DEACTIVATED: + case RESTART: + key_out(self->value2); + if (!a_key_went_through) { + tap_key(self->value1); + } + *self->state = IDLE; // does not have effect if the state was RESTART + break; + default: + break; + } +} + +void key_key_dance(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + break; + case DEACTIVATED: + tap_key(self->value1); + *self->state = IDLE; + break; + case FINISHED: + case PRESS_FROM_ACTIVE: + key_in(self->value2); + break; + case RESTART: + key_out(self->value2); + break; + default: + break; + } +} + +void autoshift_dance_impl(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + *self->counter = 0; + break; + case DEACTIVATED: + case RESTART: + tap_key(self->value1); + *self->state = IDLE; + break; + case FINISHED_FROM_ACTIVE: + if (*self->counter == (LONG_PRESS_MULTIPLIER - 2)) { + key_in(KC_LSFT); + tap_key(self->value1); + key_out(KC_LSFT); + *self->state = IDLE; + // the skip to IDLE is usually just a lag optimization, + // in this case it has a logic function, on a short + // press (still longer than a tap) the key does not get shifted + } else { + *self->counter += 1; + *self->state = PRESS_FROM_ACTIVE; + dance_timer = timer_read(); + } + break; + default: + break; + } +} + +void autoshift_dance(const struct Chord* self) { + if (autoshift_mode) { + autoshift_dance_impl(self); + } else { + single_dance(self); + } +} + +void autoshift_toggle(const struct Chord* self){ + if (*self->state == ACTIVATED) { + autoshift_mode = !autoshift_mode; + *self->state = IDLE; + } +} + +void temp_pseudolayer(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + current_pseudolayer = self->value1; + break; + case DEACTIVATED: + current_pseudolayer = self->pseudolayer; + *self->state = IDLE; + break; + case RESTART: + current_pseudolayer = self->pseudolayer; + break; + default: + break; + } +} + +void temp_pseudolayer_alt(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + current_pseudolayer = self->value1; + break; + case DEACTIVATED: + current_pseudolayer = self->value2; + *self->state = IDLE; + break; + case RESTART: + current_pseudolayer = self->value2; + break; + default: + break; + } +} + +void perm_pseudolayer(const struct Chord* self) { + if (*self->state == ACTIVATED) { + current_pseudolayer = self->value1; + *self->state = IDLE; + } +} + +void switch_layer(const struct Chord* self) { + if (*self->state == ACTIVATED) { + layer_move(self->value1); + *self->state = IDLE; + } +} + +void lock(const struct Chord* self) { + if (*self->state == ACTIVATED) { + lock_next = true; + *self->state = IDLE; + } +} + +void one_shot_key(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + break; + case DEACTIVATED: + key_in(self->value1); + *self->state = IN_ONE_SHOT; + break; + case FINISHED: + case PRESS_FROM_ACTIVE: + key_in(self->value1); + a_key_went_through = false; + break; + case RESTART: + if (a_key_went_through) { + key_out(self->value1); + } else { + *self->state = IN_ONE_SHOT; + } + default: + break; + } +} + +void one_shot_layer(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + break; + case DEACTIVATED: + current_pseudolayer = self->value1; + *self->state = IN_ONE_SHOT; + break; + case FINISHED: + case PRESS_FROM_ACTIVE: + current_pseudolayer = self->value1; + a_key_went_through = false; + break; + case RESTART: + if (a_key_went_through) { + current_pseudolayer = self->pseudolayer; + } else { + *self->state = IN_ONE_SHOT; + } + default: + break; + } +} + +void command(const struct Chord* self) { + if (*self->state == ACTIVATED) { + command_mode++; + *self->state = IDLE; + } +} + +bool identical(uint16_t* buffer1, uint16_t* buffer2) { + bool same = true; + for (int i = 0; i < LEADER_MAX_LENGTH; i++) { + same = same && (buffer1[i] == buffer2[i]); + } + return same; +} + +void leader(const struct Chord* self) { + if (*self->state == ACTIVATED) { + in_leader_mode = true; + *self->state = IDLE; + } +} + +void dynamic_macro_record(const struct Chord* self) { + if (*self->state == ACTIVATED) { + for (int i = 0; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + dynamic_macro_buffer[i] = 0; + } + dynamic_macro_mode = true; + *self->state = IDLE; + } +} + +void dynamic_macro_next(const struct Chord* self) { + if (*self->state == ACTIVATED) { + if (dynamic_macro_mode && dynamic_macro_ind < DYNAMIC_MACRO_MAX_LENGTH) { + dynamic_macro_buffer[dynamic_macro_ind] = 0; + dynamic_macro_ind++; + } + *self->state = IDLE; + } +} + +void dynamic_macro_end(const struct Chord* self) { + if (*self->state == ACTIVATED) { + if (dynamic_macro_mode) { + dynamic_macro_mode = false; + } + *self->state = IDLE; + } +} + +void dynamic_macro_play(const struct Chord* self) { + if (*self->state == ACTIVATED) { + int ind_start = 0; + while (ind_start < DYNAMIC_MACRO_MAX_LENGTH) { + for (int i = ind_start; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + if (dynamic_macro_buffer[i] == 0) { + break; + } + register_code(dynamic_macro_buffer[i]); + } + send_keyboard_report(); + wait_ms(TAP_TIMEOUT); + for (int i = ind_start; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + if (dynamic_macro_buffer[i] == 0) { + ind_start = i + 1; + break; + } + unregister_code(dynamic_macro_buffer[i]); + } + send_keyboard_report(); + } + *self->state = IDLE; + } +} + +void string_in(const struct Chord* self) { + if (*self->state == ACTIVATED) { + char buffer[STRING_MAX_LENGTH]; + strcpy_P(buffer, (char*)pgm_read_word(&(strings[self->value1]))); + send_string(buffer); + } +} + +void clear(const struct Chord* self); + +void reset_keyboard_kb(void){ +#ifdef WATCHDOG_ENABLE + MCUSR = 0; + wdt_disable(); + wdt_reset(); +#endif + reset_keyboard(); +} + +void reset(const struct Chord* self) { + if (*self->state == ACTIVATED) { + reset_keyboard_kb(); + } +} + +uint8_t state_0 = IDLE; +const struct Chord chord_0 PROGMEM = {H_TOP1 + H_TOP12 + H_BOT1 + H_BOT12, ALWAYS_ON, &state_0, NULL, 0, 0, clear}; +uint8_t state_1 = IDLE; +const struct Chord chord_1 PROGMEM = {H_TOP6 + H_TOP7 + H_BOT6 + H_BOT7, ALWAYS_ON, &state_1, NULL, 0, 0, command}; +uint8_t state_2 = IDLE; +const struct Chord chord_2 PROGMEM = {H_TOP1, QWERTY, &state_2, NULL, KC_ESC, 0, single_dance}; +uint8_t state_3 = IDLE; +const struct Chord chord_3 PROGMEM = {H_TOP2, QWERTY, &state_3, NULL, KC_Q, 0, single_dance}; +uint8_t state_4 = IDLE; +const struct Chord chord_4 PROGMEM = {H_TOP3, QWERTY, &state_4, NULL, KC_W, 0, single_dance}; +uint8_t state_5 = IDLE; +const struct Chord chord_5 PROGMEM = {H_TOP4, QWERTY, &state_5, NULL, KC_E, 0, single_dance}; +uint8_t state_6 = IDLE; +const struct Chord chord_6 PROGMEM = {H_TOP5, QWERTY, &state_6, NULL, KC_R, 0, single_dance}; +uint8_t state_7 = IDLE; +const struct Chord chord_7 PROGMEM = {H_TOP6, QWERTY, &state_7, NULL, KC_T, 0, single_dance}; +uint8_t state_8 = IDLE; +const struct Chord chord_8 PROGMEM = {H_TOP7, QWERTY, &state_8, NULL, KC_Y, 0, single_dance}; +uint8_t state_9 = IDLE; +const struct Chord chord_9 PROGMEM = {H_TOP8, QWERTY, &state_9, NULL, KC_U, 0, single_dance}; +uint8_t state_10 = IDLE; +const struct Chord chord_10 PROGMEM = {H_TOP9, QWERTY, &state_10, NULL, KC_I, 0, single_dance}; +uint8_t state_11 = IDLE; +const struct Chord chord_11 PROGMEM = {H_TOP10, QWERTY, &state_11, NULL, KC_O, 0, single_dance}; +uint8_t state_12 = IDLE; +const struct Chord chord_12 PROGMEM = {H_TOP11, QWERTY, &state_12, NULL, KC_P, 0, single_dance}; +uint8_t state_13 = IDLE; +const struct Chord chord_13 PROGMEM = {H_TOP12, QWERTY, &state_13, NULL, KC_BSLASH, 0, single_dance}; +uint8_t state_14 = IDLE; +const struct Chord chord_14 PROGMEM = {H_TOP1 + H_BOT1, QWERTY, &state_14, NULL, KC_INS, 0, single_dance}; +uint8_t state_15 = IDLE; +const struct Chord chord_15 PROGMEM = {H_TOP2 + H_BOT2, QWERTY, &state_15, NULL, KC_A, 0, single_dance}; +uint8_t state_16 = IDLE; +uint8_t counter_16 = 0; +const struct Chord chord_16 PROGMEM = {H_TOP3 + H_BOT3, QWERTY, &state_16, &counter_16, KC_S, KC_LALT, key_key_dance}; +uint8_t state_17 = IDLE; +const struct Chord chord_17 PROGMEM = {H_TOP4 + H_BOT4, QWERTY, &state_17, NULL, KC_D, KC_LCTL, key_mod_dance}; +uint8_t state_18 = IDLE; +const struct Chord chord_18 PROGMEM = {H_TOP5 + H_BOT5, QWERTY, &state_18, NULL, KC_F, KC_LSFT, key_mod_dance}; +uint8_t state_19 = IDLE; +uint8_t counter_19 = 0; +const struct Chord chord_19 PROGMEM = {H_TOP6 + H_BOT6, QWERTY, &state_19, &counter_19, KC_G, KC_LGUI, key_key_dance}; +uint8_t state_20 = IDLE; +uint8_t counter_20 = 0; +const struct Chord chord_20 PROGMEM = {H_TOP7 + H_BOT7, QWERTY, &state_20, &counter_20, KC_H, KC_RGUI, key_key_dance}; +uint8_t state_21 = IDLE; +const struct Chord chord_21 PROGMEM = {H_TOP8 + H_BOT8, QWERTY, &state_21, NULL, KC_J, KC_RSFT, key_mod_dance}; +uint8_t state_22 = IDLE; +const struct Chord chord_22 PROGMEM = {H_TOP9 + H_BOT9, QWERTY, &state_22, NULL, KC_K, KC_RCTL, key_mod_dance}; +uint8_t state_23 = IDLE; +uint8_t counter_23 = 0; +const struct Chord chord_23 PROGMEM = {H_TOP10 + H_BOT10, QWERTY, &state_23, &counter_23, KC_L, KC_RALT, key_key_dance}; +uint8_t state_24 = IDLE; +const struct Chord chord_24 PROGMEM = {H_TOP11 + H_BOT11, QWERTY, &state_24, NULL, KC_SCOLON, 0, single_dance}; +uint8_t state_25 = IDLE; +const struct Chord chord_25 PROGMEM = {H_BOT1, QWERTY, &state_25, NULL, KC_TAB, 0, single_dance}; +uint8_t state_26 = IDLE; +const struct Chord chord_26 PROGMEM = {H_BOT2, QWERTY, &state_26, NULL, KC_Z, 0, single_dance}; +uint8_t state_27 = IDLE; +const struct Chord chord_27 PROGMEM = {H_BOT3, QWERTY, &state_27, NULL, KC_X, 0, single_dance}; +uint8_t state_28 = IDLE; +const struct Chord chord_28 PROGMEM = {H_BOT4, QWERTY, &state_28, NULL, KC_C, 0, single_dance}; +uint8_t state_29 = IDLE; +const struct Chord chord_29 PROGMEM = {H_BOT5, QWERTY, &state_29, NULL, KC_V, 0, single_dance}; +uint8_t state_30 = IDLE; +const struct Chord chord_30 PROGMEM = {H_BOT6, QWERTY, &state_30, NULL, KC_B, 0, single_dance}; +uint8_t state_31 = IDLE; +const struct Chord chord_31 PROGMEM = {H_BOT7, QWERTY, &state_31, NULL, KC_N, 0, single_dance}; +uint8_t state_32 = IDLE; +const struct Chord chord_32 PROGMEM = {H_BOT8, QWERTY, &state_32, NULL, KC_M, 0, single_dance}; +uint8_t state_33 = IDLE; +const struct Chord chord_33 PROGMEM = {H_BOT9, QWERTY, &state_33, NULL, KC_COMMA, 0, single_dance}; +uint8_t state_34 = IDLE; +const struct Chord chord_34 PROGMEM = {H_BOT10, QWERTY, &state_34, NULL, KC_DOT, 0, single_dance}; +uint8_t state_35 = IDLE; +const struct Chord chord_35 PROGMEM = {H_BOT11, QWERTY, &state_35, NULL, KC_SLASH, 0, single_dance}; +uint8_t state_36 = IDLE; +const struct Chord chord_36 PROGMEM = {H_BOT12, QWERTY, &state_36, NULL, KC_QUOTE, 0, single_dance}; +uint8_t state_37 = IDLE; +const struct Chord chord_37 PROGMEM = {H_THU1, QWERTY, &state_37, NULL, KC_ENTER, 0, single_dance}; +uint8_t state_38 = IDLE; +uint8_t counter_38 = 0; +const struct Chord chord_38 PROGMEM = {H_THU2, QWERTY, &state_38, &counter_38, KC_SPC, NUM, key_layer_dance}; +uint8_t state_39 = IDLE; +uint8_t counter_39 = 0; +const struct Chord chord_39 PROGMEM = {H_THU3, QWERTY, &state_39, &counter_39, KC_BSPC, NAV, key_layer_dance}; +uint8_t state_40 = IDLE; +const struct Chord chord_40 PROGMEM = {H_THU4, QWERTY, &state_40, NULL, KC_DEL, 0, single_dance}; +uint8_t state_41 = IDLE; +uint8_t counter_41 = 0; +const struct Chord chord_41 PROGMEM = {H_THU5, QWERTY, &state_41, &counter_41, KC_SPC, FNC, key_layer_dance}; +uint8_t state_42 = IDLE; +const struct Chord chord_42 PROGMEM = {H_THU6, QWERTY, &state_42, NULL, KC_ENTER, 0, single_dance}; +uint8_t state_43 = IDLE; +const struct Chord chord_43 PROGMEM = {H_THU2 + H_THU3, QWERTY, &state_43, NULL, MOUSE, 0, temp_pseudolayer}; +uint8_t state_44 = IDLE; +const struct Chord chord_44 PROGMEM = {H_TOP1, NUM, &state_44, NULL, KC_GRAVE, 0, single_dance}; +uint8_t state_45 = IDLE; +const struct Chord chord_45 PROGMEM = {H_TOP2, NUM, &state_45, NULL, KC_1, 0, single_dance}; +uint8_t state_46 = IDLE; +const struct Chord chord_46 PROGMEM = {H_TOP3, NUM, &state_46, NULL, KC_2, 0, single_dance}; +uint8_t state_47 = IDLE; +const struct Chord chord_47 PROGMEM = {H_TOP4, NUM, &state_47, NULL, KC_3, 0, single_dance}; +uint8_t state_48 = IDLE; +const struct Chord chord_48 PROGMEM = {H_TOP5, NUM, &state_48, NULL, KC_4, 0, single_dance}; +uint8_t state_49 = IDLE; +const struct Chord chord_49 PROGMEM = {H_TOP6, NUM, &state_49, NULL, KC_5, 0, single_dance}; +uint8_t state_50 = IDLE; +const struct Chord chord_50 PROGMEM = {H_TOP7, NUM, &state_50, NULL, KC_6, 0, single_dance}; +uint8_t state_51 = IDLE; +const struct Chord chord_51 PROGMEM = {H_TOP8, NUM, &state_51, NULL, KC_7, 0, single_dance}; +uint8_t state_52 = IDLE; +const struct Chord chord_52 PROGMEM = {H_TOP9, NUM, &state_52, NULL, KC_8, 0, single_dance}; +uint8_t state_53 = IDLE; +const struct Chord chord_53 PROGMEM = {H_TOP10, NUM, &state_53, NULL, KC_9, 0, single_dance}; +uint8_t state_54 = IDLE; +const struct Chord chord_54 PROGMEM = {H_TOP11, NUM, &state_54, NULL, KC_0, 0, single_dance}; +uint8_t state_55 = IDLE; +const struct Chord chord_55 PROGMEM = {H_TOP12, NUM, &state_55, NULL, KC_MINUS, 0, single_dance}; +uint8_t state_56 = IDLE; +const struct Chord chord_56 PROGMEM = {H_TOP3 + H_BOT3, NUM, &state_56, NULL, KC_LALT, 0, single_dance}; +uint8_t state_57 = IDLE; +const struct Chord chord_57 PROGMEM = {H_TOP4 + H_BOT4, NUM, &state_57, NULL, KC_LCTL, 0, single_dance}; +uint8_t state_58 = IDLE; +const struct Chord chord_58 PROGMEM = {H_TOP5 + H_BOT5, NUM, &state_58, NULL, KC_LSFT, 0, single_dance}; +uint8_t state_59 = IDLE; +const struct Chord chord_59 PROGMEM = {H_TOP6 + H_BOT6, NUM, &state_59, NULL, KC_LGUI, 0, single_dance}; +uint8_t state_60 = IDLE; +const struct Chord chord_60 PROGMEM = {H_TOP7 + H_BOT7, NUM, &state_60, NULL, KC_RGUI, 0, single_dance}; +uint8_t state_61 = IDLE; +const struct Chord chord_61 PROGMEM = {H_TOP8 + H_BOT8, NUM, &state_61, NULL, KC_RSFT, 0, single_dance}; +uint8_t state_62 = IDLE; +const struct Chord chord_62 PROGMEM = {H_TOP9 + H_BOT9, NUM, &state_62, NULL, KC_RCTL, 0, single_dance}; +uint8_t state_63 = IDLE; +const struct Chord chord_63 PROGMEM = {H_TOP10 + H_BOT10, NUM, &state_63, NULL, KC_RALT, 0, single_dance}; +uint8_t state_64 = IDLE; +const struct Chord chord_64 PROGMEM = {H_BOT12, NUM, &state_64, NULL, KC_EQUAL, 0, single_dance}; +uint8_t state_65 = IDLE; +const struct Chord chord_65 PROGMEM = {H_TOP2, FNC, &state_65, NULL, KC_F1, 0, single_dance}; +uint8_t state_66 = IDLE; +const struct Chord chord_66 PROGMEM = {H_TOP3, FNC, &state_66, NULL, KC_F2, 0, single_dance}; +uint8_t state_67 = IDLE; +const struct Chord chord_67 PROGMEM = {H_TOP4, FNC, &state_67, NULL, KC_F3, 0, single_dance}; +uint8_t state_68 = IDLE; +const struct Chord chord_68 PROGMEM = {H_TOP5, FNC, &state_68, NULL, KC_F4, 0, single_dance}; +uint8_t state_69 = IDLE; +const struct Chord chord_69 PROGMEM = {H_TOP6, FNC, &state_69, NULL, KC_F5, 0, single_dance}; +uint8_t state_70 = IDLE; +const struct Chord chord_70 PROGMEM = {H_TOP7, FNC, &state_70, NULL, KC_F6, 0, single_dance}; +uint8_t state_71 = IDLE; +const struct Chord chord_71 PROGMEM = {H_TOP8, FNC, &state_71, NULL, KC_F7, 0, single_dance}; +uint8_t state_72 = IDLE; +const struct Chord chord_72 PROGMEM = {H_TOP9, FNC, &state_72, NULL, KC_F8, 0, single_dance}; +uint8_t state_73 = IDLE; +const struct Chord chord_73 PROGMEM = {H_TOP10, FNC, &state_73, NULL, KC_F9, 0, single_dance}; +uint8_t state_74 = IDLE; +const struct Chord chord_74 PROGMEM = {H_TOP11, FNC, &state_74, NULL, KC_F10, 0, single_dance}; +uint8_t state_75 = IDLE; +const struct Chord chord_75 PROGMEM = {H_TOP12, FNC, &state_75, NULL, KC_F11, 0, single_dance}; +uint8_t state_76 = IDLE; +const struct Chord chord_76 PROGMEM = {H_TOP3 + H_BOT3, FNC, &state_76, NULL, KC_LALT, 0, single_dance}; +uint8_t state_77 = IDLE; +const struct Chord chord_77 PROGMEM = {H_TOP4 + H_BOT4, FNC, &state_77, NULL, KC_LCTL, 0, single_dance}; +uint8_t state_78 = IDLE; +const struct Chord chord_78 PROGMEM = {H_TOP5 + H_BOT5, FNC, &state_78, NULL, KC_LSFT, 0, single_dance}; +uint8_t state_79 = IDLE; +const struct Chord chord_79 PROGMEM = {H_TOP6 + H_BOT6, FNC, &state_79, NULL, KC_LGUI, 0, single_dance}; +uint8_t state_80 = IDLE; +const struct Chord chord_80 PROGMEM = {H_TOP7 + H_BOT7, FNC, &state_80, NULL, KC_RGUI, 0, single_dance}; +uint8_t state_81 = IDLE; +const struct Chord chord_81 PROGMEM = {H_TOP8 + H_BOT8, FNC, &state_81, NULL, KC_RSFT, 0, single_dance}; +uint8_t state_82 = IDLE; +const struct Chord chord_82 PROGMEM = {H_TOP9 + H_BOT9, FNC, &state_82, NULL, KC_RCTL, 0, single_dance}; +uint8_t state_83 = IDLE; +const struct Chord chord_83 PROGMEM = {H_TOP10 + H_BOT10, FNC, &state_83, NULL, KC_RALT, 0, single_dance}; +uint8_t state_84 = IDLE; +const struct Chord chord_84 PROGMEM = {H_BOT12, FNC, &state_84, NULL, KC_F12, 0, single_dance}; +uint8_t state_85 = IDLE; +const struct Chord chord_85 PROGMEM = {H_TOP8, NAV, &state_85, NULL, KC_HOME, 0, single_dance}; +uint8_t state_86 = IDLE; +const struct Chord chord_86 PROGMEM = {H_TOP9, NAV, &state_86, NULL, KC_UP, 0, single_dance}; +uint8_t state_87 = IDLE; +const struct Chord chord_87 PROGMEM = {H_TOP10, NAV, &state_87, NULL, KC_END, 0, single_dance}; +uint8_t state_88 = IDLE; +const struct Chord chord_88 PROGMEM = {H_TOP11, NAV, &state_88, NULL, KC_PGUP, 0, single_dance}; +uint8_t state_89 = IDLE; +const struct Chord chord_89 PROGMEM = {H_TOP3 + H_BOT3, NAV, &state_89, NULL, KC_LALT, 0, single_dance}; +uint8_t state_90 = IDLE; +const struct Chord chord_90 PROGMEM = {H_TOP4 + H_BOT4, NAV, &state_90, NULL, KC_LCTL, 0, single_dance}; +uint8_t state_91 = IDLE; +const struct Chord chord_91 PROGMEM = {H_TOP5 + H_BOT5, NAV, &state_91, NULL, KC_LSFT, 0, single_dance}; +uint8_t state_92 = IDLE; +const struct Chord chord_92 PROGMEM = {H_TOP6 + H_BOT6, NAV, &state_92, NULL, KC_LGUI, 0, single_dance}; +uint8_t state_93 = IDLE; +const struct Chord chord_93 PROGMEM = {H_BOT8, NAV, &state_93, NULL, KC_LEFT, 0, single_dance}; +uint8_t state_94 = IDLE; +const struct Chord chord_94 PROGMEM = {H_BOT9, NAV, &state_94, NULL, KC_DOWN, 0, single_dance}; +uint8_t state_95 = IDLE; +const struct Chord chord_95 PROGMEM = {H_BOT10, NAV, &state_95, NULL, KC_RIGHT, 0, single_dance}; +uint8_t state_96 = IDLE; +const struct Chord chord_96 PROGMEM = {H_BOT11, NAV, &state_96, NULL, KC_PGDN, 0, single_dance}; +uint8_t state_97 = IDLE; +const struct Chord chord_97 PROGMEM = {H_TOP8, MOUSE, &state_97, NULL, KC_BTN1, 0, single_dance}; +uint8_t state_98 = IDLE; +const struct Chord chord_98 PROGMEM = {H_TOP9, MOUSE, &state_98, NULL, KC_MS_U, 0, single_dance}; +uint8_t state_99 = IDLE; +const struct Chord chord_99 PROGMEM = {H_TOP10, MOUSE, &state_99, NULL, KC_BTN2, 0, single_dance}; +uint8_t state_100 = IDLE; +const struct Chord chord_100 PROGMEM = {H_TOP11, MOUSE, &state_100, NULL, KC_WH_U, 0, single_dance}; +uint8_t state_101 = IDLE; +const struct Chord chord_101 PROGMEM = {H_TOP3 + H_BOT3, MOUSE, &state_101, NULL, KC_LALT, 0, single_dance}; +uint8_t state_102 = IDLE; +const struct Chord chord_102 PROGMEM = {H_TOP4 + H_BOT4, MOUSE, &state_102, NULL, KC_LCTL, 0, single_dance}; +uint8_t state_103 = IDLE; +const struct Chord chord_103 PROGMEM = {H_TOP5 + H_BOT5, MOUSE, &state_103, NULL, KC_LSFT, 0, single_dance}; +uint8_t state_104 = IDLE; +const struct Chord chord_104 PROGMEM = {H_TOP6 + H_BOT6, MOUSE, &state_104, NULL, KC_LGUI, 0, single_dance}; +uint8_t state_105 = IDLE; +const struct Chord chord_105 PROGMEM = {H_BOT8, MOUSE, &state_105, NULL, KC_MS_L, 0, single_dance}; +uint8_t state_106 = IDLE; +const struct Chord chord_106 PROGMEM = {H_BOT9, MOUSE, &state_106, NULL, KC_MS_D, 0, single_dance}; +uint8_t state_107 = IDLE; +const struct Chord chord_107 PROGMEM = {H_BOT10, MOUSE, &state_107, NULL, KC_MS_R, 0, single_dance}; +uint8_t state_108 = IDLE; +const struct Chord chord_108 PROGMEM = {H_BOT11, MOUSE, &state_108, NULL, KC_WH_D, 0, single_dance}; + +const struct Chord* const list_of_chords[] PROGMEM = { + &chord_0, &chord_1, &chord_2, &chord_3, &chord_4, &chord_5, &chord_6, &chord_7, &chord_8, &chord_9, &chord_10, &chord_11, &chord_12, &chord_13, &chord_14, &chord_15, &chord_16, &chord_17, &chord_18, &chord_19, &chord_20, &chord_21, &chord_22, &chord_23, &chord_24, &chord_25, &chord_26, &chord_27, &chord_28, &chord_29, &chord_30, &chord_31, &chord_32, &chord_33, &chord_34, &chord_35, &chord_36, &chord_37, &chord_38, &chord_39, &chord_40, &chord_41, &chord_42, &chord_43, &chord_44, &chord_45, &chord_46, &chord_47, &chord_48, &chord_49, &chord_50, &chord_51, &chord_52, &chord_53, &chord_54, &chord_55, &chord_56, &chord_57, &chord_58, &chord_59, &chord_60, &chord_61, &chord_62, &chord_63, &chord_64, &chord_65, &chord_66, &chord_67, &chord_68, &chord_69, &chord_70, &chord_71, &chord_72, &chord_73, &chord_74, &chord_75, &chord_76, &chord_77, &chord_78, &chord_79, &chord_80, &chord_81, &chord_82, &chord_83, &chord_84, &chord_85, &chord_86, &chord_87, &chord_88, &chord_89, &chord_90, &chord_91, &chord_92, &chord_93, &chord_94, &chord_95, &chord_96, &chord_97, &chord_98, &chord_99, &chord_100, &chord_101, &chord_102, &chord_103, &chord_104, &chord_105, &chord_106, &chord_107, &chord_108 +}; + +const uint16_t** const leader_triggers PROGMEM = NULL; +void (*leader_functions[]) (void) = {}; + +#define NUMBER_OF_CHORDS 109 +#define NUMBER_OF_LEADER_COMBOS 0 + +bool are_hashed_keycodes_in_sound(HASH_TYPE keycodes_hash, HASH_TYPE sound) { + return (keycodes_hash & sound) == keycodes_hash; +} + +uint8_t keycode_to_index(uint16_t keycode) { + return keycode - FIRST_INTERNAL_KEYCODE; +} + +void sound_keycode_array(uint16_t keycode) { + uint8_t index = keycode_to_index(keycode); + keycode_index++; + keycodes_buffer_array[index] = keycode_index; +} + +void silence_keycode_hash_array(HASH_TYPE keycode_hash) { + for (int i = 0; i < NUMBER_OF_KEYS; i++) { + bool index_in_hash = ((HASH_TYPE) 1 << i) & keycode_hash; + if (index_in_hash) { + uint8_t current_val = keycodes_buffer_array[i]; + keycodes_buffer_array[i] = 0; + for (int j = 0; j < NUMBER_OF_KEYS; j++) { + if (keycodes_buffer_array[j] > current_val) { + keycodes_buffer_array[j]--; + } + } + keycode_index--; + } + } +} + +bool are_hashed_keycodes_in_array(HASH_TYPE keycode_hash) { + for (int i = 0; i < NUMBER_OF_KEYS; i++) { + bool index_in_hash = ((HASH_TYPE) 1 << i) & keycode_hash; + bool index_in_array = (bool) keycodes_buffer_array[i]; + if (index_in_hash && !index_in_array) { + return false; + } + } + return true; +} + +void kill_one_shots(void) { + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + if (*chord->state == IN_ONE_SHOT) { + *chord->state = RESTART; + chord->function(chord); + if (*chord->state == RESTART) { + *chord->state = IDLE; + } + } + } +} + +void process_finished_dances(void) { + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + if (*chord->state == ACTIVATED) { + *chord->state = PRESS_FROM_ACTIVE; + chord->function(chord); + if (a_key_went_through) { + kill_one_shots(); + } + dance_timer = timer_read(); + } else if (*chord->state == IDLE_IN_DANCE) { + *chord->state = FINISHED; + chord->function(chord); + if (*chord->state == FINISHED) { + *chord->state = RESTART; + if (*chord->state == RESTART) { + *chord->state = IDLE; + } + } + } else if (*chord->state == PRESS_FROM_ACTIVE) { + *chord->state = FINISHED_FROM_ACTIVE; + chord->function(chord); + if (a_key_went_through) { + kill_one_shots(); + } + dance_timer = timer_read(); + } + } +} + +uint8_t keycodes_buffer_array_min(uint8_t* first_keycode_index) { + for (int i = 0; i < NUMBER_OF_KEYS; i++) { + if (keycodes_buffer_array[i] == 1) { + if (first_keycode_index != NULL) { + *first_keycode_index = (uint8_t) i; + } + return 1; + } + } + return 0; +} + +void remove_subchords(void) { + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + if (!(*chord->state == READY || *chord->state == READY_IN_DANCE || *chord->state == READY_LOCKED)) { + continue; + } + + struct Chord chord_storage_2; + struct Chord* chord_ptr_2; + struct Chord* chord_2; + for (int j = 0; j < NUMBER_OF_CHORDS; j++) { + if (i == j) {continue;} + + chord_ptr_2 = (struct Chord*) pgm_read_word (&list_of_chords[j]); + memcpy_P(&chord_storage_2, chord_ptr_2, sizeof(struct Chord)); + chord_2 = &chord_storage_2; + + if (are_hashed_keycodes_in_sound(chord_2->keycodes_hash, chord->keycodes_hash)) { + if (*chord_2->state == READY) { + *chord_2->state = IDLE; + } + if (*chord_2->state == READY_IN_DANCE) { + *chord_2->state = IDLE_IN_DANCE; + } + if (*chord_2->state == READY_LOCKED) { + *chord_2->state = LOCKED; + } + } + } + } +} + +void process_ready_chords(void) { + uint8_t first_keycode_index = 0; + while (keycodes_buffer_array_min(&first_keycode_index)) { + // find ready chords + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + // if the chord does not contain the first keycode + bool contains_first_keycode = ((uint32_t) 1 << first_keycode_index) & chord->keycodes_hash; + if (!contains_first_keycode) { + continue; + } + + if (!are_hashed_keycodes_in_array(chord->keycodes_hash)){ + continue; + } + + if (*chord->state == LOCKED) { + *chord->state = READY_LOCKED; + continue; + } + + if (!(chord->pseudolayer == current_pseudolayer || chord->pseudolayer == ALWAYS_ON)) { + continue; + } + + if (*chord->state == IDLE) { + *chord->state = READY; + continue; + } + + if (*chord->state == IDLE_IN_DANCE) { + *chord->state = READY_IN_DANCE; + } + } + + // remove subchords + remove_subchords(); + + // execute logic + // this should be only one chord + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + if (*chord->state == READY_LOCKED) { + *chord->state = RESTART; + chord->function(chord); + if (*chord->state == RESTART) { + *chord->state = IDLE; + } + break; + } + + if (*chord->state == READY || *chord->state == READY_IN_DANCE) { + if (last_chord && last_chord != chord) { + process_finished_dances(); + } + + bool lock_next_prev_state = lock_next; + + *chord->state = ACTIVATED; + chord->function(chord); + dance_timer = timer_read(); + + if (lock_next && lock_next == lock_next_prev_state) { + lock_next = false; + *chord->state = PRESS_FROM_ACTIVE; + chord->function(chord); + if (*chord->state == PRESS_FROM_ACTIVE) { + *chord->state = LOCKED; + } + if (a_key_went_through) { + kill_one_shots(); + } + } + break; + } + } + + // silence notes + silence_keycode_hash_array(chord->keycodes_hash); + } +} + +void deactivate_active_chords(uint16_t keycode) { + HASH_TYPE hash = (HASH_TYPE)1 << (keycode - SAFE_RANGE); + bool broken; + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + broken = are_hashed_keycodes_in_sound(hash, chord->keycodes_hash); + if (!broken) { + continue; + } + + switch (*chord->state) { + case ACTIVATED: + *chord->state = DEACTIVATED; + chord->function(chord); + + if (*chord->state == DEACTIVATED) { + dance_timer = timer_read(); + *chord->state = IDLE_IN_DANCE; + } + if (*chord->state != IN_ONE_SHOT) { + kill_one_shots(); + } + break; + case PRESS_FROM_ACTIVE: + case FINISHED_FROM_ACTIVE: + *chord->state = RESTART; + chord->function(chord); + if (*chord->state == RESTART) { + *chord->state = IDLE; + } + kill_one_shots(); + break; + default: + break; + } + } + +} + +void process_command(void) { + command_mode = 0; + for (int i = 0; i < COMMAND_MAX_LENGTH; i++) { + if (command_buffer[i]) { + register_code(command_buffer[i]); + } + send_keyboard_report(); + } + wait_ms(TAP_TIMEOUT); + for (int i = 0; i < COMMAND_MAX_LENGTH; i++) { + if (command_buffer[i]) { + unregister_code(command_buffer[i]); + } + send_keyboard_report(); + } + for (int i = 0; i < COMMAND_MAX_LENGTH; i++) { + command_buffer[i] = 0; + } + command_ind = 0; +} + +void process_leader(void) { + in_leader_mode = false; + for (int i = 0; i < NUMBER_OF_LEADER_COMBOS; i++) { + uint16_t trigger[LEADER_MAX_LENGTH]; + memcpy_P(trigger, leader_triggers[i], LEADER_MAX_LENGTH * sizeof(uint16_t)); + + if (identical(leader_buffer, trigger)) { + (*leader_functions[i])(); + break; + } + } + for (int i = 0; i < LEADER_MAX_LENGTH; i++) { + leader_buffer[i] = 0; + } +} + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (keycode < FIRST_INTERNAL_KEYCODE || keycode > LAST_INTERNAL_KEYCODE) { + return true; + } + + if (record->event.pressed) { + sound_keycode_array(keycode); + } else { + process_ready_chords(); + deactivate_active_chords(keycode); + } + chord_timer = timer_read(); + leader_timer = timer_read(); + + return false; +} + +void matrix_scan_user(void) { + bool chord_timer_expired = timer_elapsed(chord_timer) > CHORD_TIMEOUT; + if (chord_timer_expired && keycodes_buffer_array_min(NULL)) { + process_ready_chords(); + } + + bool dance_timer_expired = timer_elapsed(dance_timer) > DANCE_TIMEOUT; + if (dance_timer_expired) { // would love to have && in_dance but not sure how + process_finished_dances(); + } + + bool in_command_mode = command_mode == 2; + if (in_command_mode) { + process_command(); + } + + bool leader_timer_expired = timer_elapsed(leader_timer) > LEADER_TIMEOUT; + if (leader_timer_expired && in_leader_mode) { + process_leader(); + } + +} + +void clear(const struct Chord* self) { + if (*self->state == ACTIVATED) { + // kill all chords + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + *chord->state = IDLE; + + if (chord->counter) { + *chord->counter = 0; + } + } + + // clear keyboard + clear_keyboard(); + send_keyboard_report(); + + // switch to default pseudolayer + current_pseudolayer = DEFAULT_PSEUDOLAYER; + + // clear all keyboard states + lock_next = false; + autoshift_mode = true; + command_mode = 0; + in_leader_mode = false; + leader_ind = 0; + dynamic_macro_mode = false; + a_key_went_through = false; + + for (int i = 0; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + dynamic_macro_buffer[i] = 0; + } + } +}
\ No newline at end of file diff --git a/keyboards/georgi/keymaps/dennytom/keymap_def.json b/keyboards/georgi/keymaps/dennytom/keymap_def.json new file mode 100644 index 0000000000..232ccafadf --- /dev/null +++ b/keyboards/georgi/keymaps/dennytom/keymap_def.json @@ -0,0 +1,153 @@ +{ + "keys": [ + "TOP1", "TOP2", "TOP3", "TOP4", "TOP5", "TOP6", "TOP7", "TOP8", "TOP9", "TOP10", "TOP11", "TOP12", + "BOT1", "BOT2", "BOT3", "BOT4", "BOT5", "BOT6", "BOT7", "BOT8", "BOT9", "BOT10", "BOT11", "BOT12", + "THU1", "THU2", "THU3", "THU4", "THU5", "THU6" + ], + "parameters": { + "layout_function_name": "LAYOUT_georgi", + "chord_timeout": 100, + "dance_timeout": 200, + "leader_timeout": 750, + "tap_timeout": 50, + "command_max_length": 5, + "leader_max_length": 5, + "dynamic_macro_max_length": 20, + "string_max_length": 16, + "long_press_multiplier": 3, + "default_pseudolayer": "QWERTY" + }, + "layers": [ + { + "type": "auto" + } + ], + "chord_sets": [ + { + "name": "rows", + "chords": + [ + ["TOP1"], ["TOP2"], ["TOP3"], ["TOP4"], ["TOP5"], ["TOP6"], ["TOP7"], ["TOP8"], ["TOP9"], ["TOP10"], ["TOP11"], ["TOP12"], + ["TOP1", "BOT1"], ["TOP2", "BOT2"], ["TOP3", "BOT3"], ["TOP4", "BOT4"], ["TOP5", "BOT5"], ["TOP6", "BOT6"], ["TOP7", "BOT7"], ["TOP8", "BOT8"], ["TOP9", "BOT9"], ["TOP10", "BOT10"], ["TOP11", "BOT11"], ["TOP12", "BOT12"], + ["BOT1"], ["BOT2"], ["BOT3"], ["BOT4"], ["BOT5"], ["BOT6"], ["BOT7"], ["BOT8"], ["BOT9"], ["BOT10"], ["BOT11"], ["BOT12"], + ["THU1"], ["THU2"], ["THU3"], ["THU4"], ["THU5"], ["THU6"] + ] + } + ], + "pseudolayers": [ + { + "name": "ALWAYS_ON", + "chords": [ + { + "type": "visual", + "chord": [ + "X", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "X", + "X", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "X", + " ", " ", " ", " ", " ", " " + ], + "keycode": "CLEAR_KB" + }, + { + "type": "visual", + "chord": [ + " ", " ", " ", " ", " ", "X", "X", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", "X", "X", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " " + ], + "keycode": "CMD" + } + ] + }, + { + "name": "QWERTY", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + "ESC", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "\\", + "INS", "A", "KK(S, LALT)", "KM(D, LCTL)", "KM(F, LSFT)", "KK(G, LGUI)", "KK(H, RGUI)", "KM(J, RSFT)", "KM(K, RCTL)", "KK(L, RALT)", ";", " ", + "TAB", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", "'", + "","","","","","" + ] + }, + { + "type": "visual_array", + "keys": ["THU1", "THU2", "THU3", "THU4", "THU5", "THU6"], + "dictionary": [ + ["X", " ", " ", " ", " ", " ", "ENTER"], + [" ", "X", " ", " ", " ", " ", "KL(SPC, NUM)"], + [" ", " ", "X", " ", " ", " ", "KL(BSPC, NAV)"], + [" ", " ", " ", "X", " ", " ", "DEL"], + [" ", " ", " ", " ", "X", " ", "KL(SPC, FNC)"], + [" ", " ", " ", " ", " ", "X", "ENTER"], + [" ", "X", "X", " ", " ", " ", "MO(MOUSE)"] + ] + } + ] + }, + { + "name": "NUM", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + "`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", + " ", " ", "LALT", "LCTL", "LSFT", "LGUI", "RGUI", "RSFT", "RCTL", "RALT", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " ", "[", "]", "=", + " ", " ", " ", " ", " ", " " + ] + } + ] + }, + { + "name": "FNC", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + " ", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", + " ", " ", "LALT", "LCTL", "LSFT", "LGUI", "RGUI", "RSFT", "RCTL", "RALT", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "F12", + " ", " ", " ", " ", " ", " " + ] + } + ] + }, + { + "name": "NAV", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + " ", " ", " ", " ", " ", " ", " ", "HOME", "UP", "END", "PGUP", " ", + " ", " ", "LALT", "LCTL", "LSFT", "LGUI", " ", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", "LEFT", "DOWN", "RIGHT", "PGDN", " ", + " ", " ", " ", " ", " ", " " + ] + } + ] + }, + { + "name": "MOUSE", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + " ", " ", " ", " ", " ", " ", " ", "BTN1", "MS_U", "BTN2", "WH_U", " ", + " ", " ", "LALT", "LCTL", "LSFT", "LGUI", " ", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", "MS_L", "MS_D", "MS_R", "WH_D", " ", + " ", " ", " ", " ", " ", " " + ] + } + ] + } + ], + "leader_sequences": [], + "extra_code": "", + "extra_dependencies": [] +}
\ No newline at end of file diff --git a/keyboards/georgi/keymaps/dennytom/rules.mk b/keyboards/georgi/keymaps/dennytom/rules.mk new file mode 100644 index 0000000000..1155f72c04 --- /dev/null +++ b/keyboards/georgi/keymaps/dennytom/rules.mk @@ -0,0 +1,8 @@ +MOUSEKEY_ENABLE = yes +EXTRAKEY_ENABLE = yes +CONSOLE_ENABLE = no +# COMMAND_ENABLE = no +NKRO_ENABLE = yes + +TMPVAR := $(SRC) +SRC = $(filter-out sten.c, $(TMPVAR))
\ No newline at end of file diff --git a/users/dennytom/chording_engine/README.md b/users/dennytom/chording_engine/README.md new file mode 100644 index 0000000000..3610b190bf --- /dev/null +++ b/users/dennytom/chording_engine/README.md @@ -0,0 +1,376 @@ +# README + +## About + +This is a custom combo engine. I call it chording engine mostly to differentiate it from QMK's combos. It is useful even if you are not using chording as a main input method to replace combos. + +Why does this exist? Typing on tiny keyboards can be challenging and you will end up relying on dances and / or combos. Pure QMK combos can be insufficient as they do not really support overlapping combos. For example, if you define 3 combos `(KC_Q, KC_W)`, `(KC_Z, KC_X)` and `(KC_Q, KC_W, KC_Z, KC_X)` and press Q, W, Z and X at the same time, all three combos will activate. Steno engines (and g Board Industries' custom steno inspired engine) solve this, however, they don't allow for comfortable typing in the traditional way. The steno chord activates only when *all* keys are lifted and makes it difficult to implement some advanced features. This engine treats each chord independently to allow for more comfortable typing experience. + +## TOC + +- [README](#readme) + - [About](#about) + - [TOC](#toc) + - [Start here](#start-here) + - [Steps](#steps) + - [Features](#features) + - [Chords](#chords) + - [Tap-Dance](#tap-dance) + - [Pseudolayers](#pseudolayers) + - [Control chords](#control-chords) + - [Settings up JSON definition](#settings-up-json-definition) + - [Keyboard and engine parameters](#keyboard-and-engine-parameters) + - [Pseudolayers](#pseudolayers-1) + - [Supported keycodes](#supported-keycodes) + - [Leader Key](#leader-key) + - [Extra code](#extra-code) + - [Further details](#further-details) + - [Implementation](#implementation) + - [Internal keycodes](#internal-keycodes) + - [Chords](#chords-1) + - [Caveats](#caveats) + +## Start here + +This engine therefore uses python parser that translates a JSON definition of keyboard specific information and keymap definition and produces `keymap.c`. Every function on this keymap is a chord (combo). The resulting keymap file is long and I do not encourage you to edit it. All you should have to edit is the JSON file. To produce the keymap file, run + +```sh +./parser.py keymap_def.json keymap.c +``` + +To prepare the keymap JSON definition, you can use on of my keymaps as a starting point. I have on for butterstick and for georgi. There is also a JSON schema that has some examples and sane defaults. All details are explained in the next section. The parser tries to validate some of the things that the JSON schema can not. Finally there is a JSON in the tests folder that has at least one example of every feature. + +Watch out, you can not name your JSON file `keymap.json` if you place in the keymap folder. QMK creates `keymap.json` as a part of compilation process and if you already have one, it gets confused. + +## Steps + +When setting up a new keyboard, follow the steps: + +1. Make a new directory for your keymap as QMK's documentation describes. +2. Write your JSON. Name it anything but `keymap.json`. +3. Depending on the keyboard / keymap, create `rules.mk` (follow QMK's documentation and note that if the keyboard's `rules.mk` include custom source files, this is the place you can remove them). +4. Use my python parser to generate the `keymap.c`. Run it from the `/users/dennytom/chording_engine` directory as it is using relative paths to some extra files. +5. Follow QMK's documentation to compile and flash your firmware. + +## Features + +### Chords + +Once again, *everything* on this keymap is a chord. Even sending `KC_Q` is done by pressing a single key chord. Chord gets activated after all it's keys get pressed. Only the longest chord gets activated. The order of the pressed keys *does not matter*, only the fact they have been pressed within the same time frame. An active chord gets deactivated if *any* of it's keys gets depressed. To activate the same single chord again, *all* it's keys have to be depressed and pressed again. With a few exceptions chords are independent of each other. No matter if some chords are currently active and some not, others can be activated or deactivated without affecting each other's state. *If you press keys to belonging to multiple different, non-overlapping chords, all get activated in the order they are defined in the keymap.* + +### Tap-Dance + +To make it even stranger, all chords are technically tap-dance chords. They are relatively simple state machines that execute a specific function every time they change state. For simplicity and optimization purposes, there are a few prewritten functions that implement common features like "send a single key" or "lock". Any number of chords can be "in dance" at any given moment without affecting each other's state. Custom dances can be easily added. Check out the `state_machine.png` to see all the states any chord can be in. + +### Pseudolayers + +Only one QMK layer is used. Following the butterstick's default keymap's example, the chording engine is using pseudolayers. The main difference to QMK's layers is that only one pseudolayer can be active at each time (meaning you can not use `KC_TRANS`, I actually don't know what will happen if you do). Chords can be activated only if they are on the currently active pseudolayer. Chords that are currently active do not get deactivated if the pseudolayer changes and will deactivate if any of their keys gets depressed even no matter the current pseudolayer. Locked chords (see below) and chords on the `ALWAYS_ON` pseudolayer can be activated anytime. + +### Control chords + +The engine implements a number of ways of changing how chords behave: + +* **Lock**: Similarly to QMK's lock, the next chord activated after the Lock chord will not deactivate on release of any of its keys, it will deactivate when all its keys get pressed again. Any number of chords can be locked at the same time. To make sure a locked chord can be unlocked, it can activate no matter the current pseudolayer. A chord can be locked mid dance. +* **One shots**: Chords that send keycodes and chords that turn on pseudolayers can be one shots. If tapped, they will lock (stay active) until the next keycode gets sent, *not necessarily when the next chord gets activated*. If held, they will deactivate on release *even if no keycode got sent*. +* **Tap-Hold**: Also called key-layer dance and key-key dance. Either sends a defined keycode on tap and temporarily switches pseudolayer on hold *or* sends two different keycodes on tap and hold. +* **Command mode**: After getting activated for the first time, the keyboard switches to command mode. All *keycodes* that would get registered get buffered instead. After activating the Command mode chord for the second time, all buffered keycodes get released at the same time allowing for key combination that would be hard or impossible to press. The Command mode only affects keycodes. It is therefore possible to change pseudolayers or activate / deactivate other chords while in Command mode. While multiple Command mode chords can be defined, they would not be independent. The keyboard either is or is not in command mode and there is only one buffer. +* **Leader key**: Just like pure QMK's Leader key, this allows you to add functions that get executed if the Leader key and a specific sequence of keycodes gets registered in a predefined order in a short timeframe. For example `:wq` can send `Ctrl+S` and `Ctrl+W` in a quick succession. While multiple Leader keys can be defined, they all would access the same list of sequences. +* **Dynamic macro**: A sequence of keycodes can be recorded and stored in the RAM of the keyboard and replayed. + +## Settings up JSON definition + +The JSON definition has 3 main sections. The elements `keys`, `parameters` and `layers` teach the engine about the details of your keyboard and set its parameters. The elements `pseudolayers`, `leader_sequences` and `chord_sets` define your keymap. Finally, the elements `extra_code` and `extra_dependencies` allow you to include more code to extend the capabilities of the engine. + +### Keyboard and engine parameters + +I do not have experience with stenography, so the the steno keycodes are hard for me to remember. That is why the keymap is using new keycodes TOP1, TOP2, ... . + +```c + "keys": ["TOP1", "TOP2", "TOP3", ...] +``` + +You can name these however you like as long as they do not crash with QMK's keycodes. + +*The chording engine in it's current implementation can handle up to 64 keys. If you need to support more, contact me (email or u/DennyTom at Reddit).* + +All timings, maximum lengths for macros, command mode and leader function are defined in `keyboard_parameters` field. Almost all should be pretty self-explanatory. + +My keyboards are small, so I only use the engine, but you might want to use layers that combine chord-able keys and traditional QMK keys or layers with advanced keycodes, for example for stenography. The array `layers` defines all the parser needs to know: + +```json +"layers": [ + { + "type": "auto" + }, + { + "type": "manual", + "keycodes": ["KC_1", "KC_2", "KC_3", "KC_4", "KC_5", "KC_6", "KC_7", "KC_8", "KC_9", "KC_0", + "KC_Q", "KC_W", "KC_E", "KC_R", "KC_T", "KC_Y", "KC_U", "KC_I", "KC_O", "KC_P" + ] + }, + { + "type": "manual", + "keycodes": ["KC_1", "KC_2", "KC_3", "KC_4", "KC_5", "KC_6", "KC_7", "KC_8", "KC_9", "KC_0", + "BOT1", "BOT2", "BOT3", "BOT4", "BOT5", "BOT6", "BOT7", "BOT8", "BOT9", "BOT0"] + } + ] +``` + +This example defines 3 layers, one that is automatically populated with chording engine's internal keycodes, second that is populated with QMK's keycodes and third that uses both internal and QMK's keycodes. The layers do not have names, you have to access them with `TO(1)` and `TO(0)`. + +Some keyboards mangle the order of keycodes when registering them in the layers. For that fill up the `layout_function_name` with the name of function / macro. If your keyboard does not do it, leave that string empty. + +### Pseudolayers + +Array `pseudolayers` defines the keymap per pseudolayer. Each field has to contain the name for the layer and the list of chords. + +```JSON +"pseudolayers": [ + { + "name": "QWERTY", + "chords": [ + { + "type": "simple", + "keycode": "SPACE", + "chord": ["BOT1", "BOT0"] + }, + { + "type": "visual", + "keycode": "CLEAR_KB", + "chord": [ + "X", "", "", "", "", "", "", "", "", "X", + "X", "", "", "", "", "", "", "", "", "X", + ] + }, + { + "type": "visual_array", + "keys": ["TOP1", "TOP2", "TOP3"], + "dictionary": [ + ["X", "X", " ", "ESC"], + [" ", "X", "X", "TAB"], + ["X", "X", "X", "ENTER"] + ] + }, + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", + "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", + "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/" + ] + } + ] + } +] +``` + +The array `chord` defines chords. You can either use simple chord and list all the keys that have to pressed at the same time, or use the visual chord and place `"X"` over keys that will be part of the chord. You can also use `visual_array` to define a number of chords in a visual way on a subset of keys defined in the `keys` array. Finally, you can use `chord_set` to define a number of chords following a pattern that was set in the `chord_sets` array in the root object like this: + +```json +"chord_sets": [ + { + "name": "rows", + "chords": [ + ["TOP1"], ["TOP2"], ["TOP3"], ["TOP4"], ["TOP5"], ["TOP6"], ["TOP7"], ["TOP8"], ["TOP9"], ["TOP0"] + ["TOP1", "BOT1"], ["TOP2", "BOT2"], ["TOP3", "BOT3"], ["TOP4", "BOT4"], ["TOP5", "BOT5"], ["TOP6", "BOT6"], ["TOP7", "BOT7"], ["TOP8", "BOT8"], ["TOP9", "BOT9"], ["TOP0", "BOT0"], + ["BOT1"], ["BOT2"], ["BOT3"], ["BOT4"], ["BOT5"], ["BOT6"], ["BOT7"], ["BOT8"], ["BOT9"], ["BOT0"] + ] + }, + { + "name": "cols", + "chords": [ + ["TOP1", "TOP2"], ["TOP2", "TOP3"], ["TOP3", "TOP4"], ["TOP4", "TOP5"], ["TOP5", "TOP6"], ["TOP6", "TOP7"], ["TOP7", "TOP8"], ["TOP8", "TOP9"], ["TOP9", "TOP0"], + ["TOP1", "TOP2", "BOT1", "BOT2"], ["TOP2", "TOP3", "BOT2", "BOT3"], ["TOP3", "TOP4", "BOT3", "BOT4"], ["TOP4", "TOP5", "BOT4", "BOT5"], ["TOP5", "TOP6", "BOT5", "BOT6"], ["TOP6", "TOP7", "BOT6", "BOT7"], ["TOP7", "TOP8", "BOT7", "BOT8"], ["TOP8", "TOP9", "BOT8", "BOT9"], ["TOP9", "TOP0", "BOT9", "BOT0"], + ["BOT1", "BOT2"], ["BOT2", "BOT3"], ["BOT3", "BOT4"], ["BOT4", "BOT5"], ["BOT5", "BOT6"], ["BOT6", "BOT7"], ["BOT7", "BOT8"], ["BOT8", "BOT9"], ["BOT9", "BOT00"], + ] + } +] +``` + + + +You might notice that the code tries to do a few clever things when parsing keycodes: + +* If the keycode would be just a character basic keycode, it tries to allow the use of shortcuts. `Q` will get replaced with `KC_Q`, `,` becomes `KC_COMMA`. This *should* work for all KC_ keycodes unless I missed some. +* `MO()` and `DF()` macros work the same way for pseudolayers as they would for layers in pure QMK. +* `O()` is a shortcut for `OSK()` or `OSL()`. +* `STR('...')` sends a string. Careful with quoting. +* Special chords like Command mode have their own codes like `CMD`. +* The empty strings get ignored. + +### Supported keycodes + +* **`X`** or **`KC_X`**: Send code `KC_X` just like a normal keyboard. + +* **`STR("X")`**: Send string "x" on each activation of the chord. Once again, watch out for quoting and escaping characters. If you want special characters (especially quotes) in your string, look up Python reference for string literals and experiment. Also, because of how the string gets parsed, it is not possible to use `(` in the string. + +* **`MO(X)`**: Temporary switch to pseudolayer `X`. Because only one pseudolayer can be active at any moment, this works by switching back to the pseudolayer the chord lives on on deactivation. If you chain `MO()`s on multiple pseudolayers and deactivate them in a random order, you might end up stranded on a pseudolayer. I recommend adding `CLEAR` somewhere on `ALWAYS_ON` pseudolayer just in case. + +* **`MO(X,Y)`**: Temporary switch to pseudolayer `Y`. Switches to pseudolayer `X` on deactivation. Especially useful when you want to put the `MO()` chord on `ALWAYS_ON`. + +* **`DF(X)`**: Permanent switch to pseudolayer `X`. + +* **`TO(X)`**: Switches the QMK layer to `X`. + +* **`O(X)`**: One-shot key `X` (if `X` starts with `"KC_"`) or one-shot layer `X` (otherwise) . Both have retro tapping enabled. + +* **Tap-holds** + + * **`KK(X, Y)`**: Pulses code `X` on tap and code `Y` on hold. + * **`KL(X, Y)`**: Pulses code `X` on tap and switches to pseudolayer `Y` on hold. If during the hold no key gets registered, the code `X` will get sent instead (similar to QMK's retro tapping). + * **`KM(X, Y)`**: Same as `KK()` but meant for modifiers on hold. Instead of a timer to figure out tap-hold, uses retro tapping like behavior just like `KL()`. This has issues with GUI and ALT as they often have a meaning. + * The chording engine determines if you are holding a chord based on a *global* timer. If you start holding a tap-hold chord and very quickly start tapping other chords, the hold might not activate until a short moment *after the last* chord when the timer expires. If you are running into this, adjust timeouts or wait a brief moment after pressing the chord to make sure it switches into the hold state before pressing other chords. + +* **Autoshift** + + * **`AS(X)`**: Pulses code `X` on tap and Pulses left shift + `X` on hold. + * **`AT`** : Toggles autoshift for all autoshift chords. If off, all `AS` chords act like `KC` chords. + +* **`LOCK`**: The lock key. Since tap-dances of chords are independent, it is possible to lock a chord *anywhere in it's dance if you time it right!*. If that happens, use the `CLEAR` chord or restart your keeb. + +* **`CMD`**: The command mode. The number of keycodes that can be buffered is defined in in `command_max_length`. + +* **`LEAD`**: The leader key. The maximum length of the sequences needs to be defined in `keyboard_params`. You can use `leader_sequences` array to add sequences: + + ```json + "leader_sequences": [ + { + "name": "fn_L1", + "function": "void fn_L1(void) { SEND(KC_LCTL); SEND(KC_LALT); SEND(KC_DEL); }", + "sequence": ["KC_Q", "KC_Z"] + } + ] + ``` + + When the engine notices the sequence, it will call the function defined in the field `name`. You can either define it in the `function` field, in the field `extra_code` or in an external file that you then have to insert manually or using the `extra_dependencies` array. The parser copy-pastes the contents `extra_code` of all files specified in the `extra_dependencies` array in the `keymap.c`. + +* **`M(X, VALUE1, VALUE2)`**: A custom macro. Adds a chord that will use function `X` and with `chord.value1 = VALUE1; chord.value2 = VALUE2;`. The function `X` can be arbitrary C function, go crazy. Just like with the leader sequences, you have to insert the code into the generated `keymap.c` manually or through `extra_code` or `extra_dependencies`. The following example defines a macro that acts exactly like `KC_MEH` (the chording engine *should* support `KC_MEH`, this is just an example): + + ```c + void fn_M1(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + key_in(KC_LCTL); + key_in(KC_LSFT); + key_in(KC_LALT); + break; + case DEACTIVATED: + key_out(KC_LCTL); + key_out(KC_LSFT); + key_out(KC_LALT); + break; + case FINISHED: + case FINISHED_FROM_ACTIVE: + break; + case RESTART: + key_out(KC_LCTL); + key_out(KC_LSFT); + key_out(KC_LALT); + break; + default: + break; + } + } + ``` + + Since this feels like it would be the most common way to use this feature, I wrote a macro for this: + +* **`MK(X1, X2, ...)`**: Acts like `KC()` except it registers / unregisters all `X1`, `X2`, ... codes at the same time. + +* **`D(X1, X2, ...)`**: A basic keycode dance. If tapped (or held), registers `X1`. If tapped and then tapped again (or held), registers `X2`, ... It *cannot* be combined with tap-hold, however holding will result in repeat. You can put in as many basic keycodes as you want, but the macro will break if you go beyond 256. It will try to expand shortened keycodes. Advanced keycodes are not supported. + +* **`DM_RECORD`, `DM_NEXT`, `DM_END`, `DM_PLAY`**: Start recording a dynamic macro. Once you start recording, basic keycodes will get stored. When replaying the macro, all keys you press before `DM_NEXT` or `DM_END` will get pressed at the same time. For example the sequence `DM_RECORD`, `KC_CTRL`, `KC_A`, `DM_NEXT`, `KC_BSPC`, `DM_END` will record a macro that when played will execute the sequence Ctrl+a, Backspace. `dynamic_macro_max_length` defines the maximum length of the macro to be recorded. You can increase it for the price of RAM. The example above requires 4 units of length to be saved (Ctrl, A, next, Backspace). + +* **`CLEAR_KB`**: clears keyboard, sets all chords to the default state and switches the pseudolayer to the default one. Basically the emergency stop button. + +* **`RESET`**: Go to the DFU flashing mode. + +**Caveat** of the current implementation is that the tap-hold, `MK` and `D` keycodes can not accept any of the keycodes that have some sort a function like dynamic macro specific chords, `CLEAR_KB`, `RESET`, `LOCK`, `AT`, ... + +### Leader Key + +The sequences are not defined by the *keys* you press but by the *keycodes* that get intercepted. The length of the sequence must be equal or shorter than the maximum (defined in `keyboard.inc`). Currently, the timeout for the leader sequence refreshes after each key pressed. If the sequence is not in the database, nothing will happen. + +### Extra code + +Extra C code needed to define custom chords can be added by quoting in in the `extra_code` element or by saving it in another header file and including it using the `extra_dependencies` element: + +```json +{ + "extra_code": "void double_dance(const struct Chord* self) { ... }\n", + "extra_dependencies": ["my_header.h"] +} +``` + + + +## Further details + +### Implementation + +The source files are split into several files. `engine.part.1`, `engine.part.2` and `engine.part.3` contain C code that defines the Chord structure, implementations for all provided functions and the engine itself. `parser.py` generates keyboard and keymap dependent code. The file `chord.py` contains most of the logic required to properly translate chords from the JSON to the C code. I rarely write in python, if you have improvements, let me know, *please*. + +### Internal keycodes + +When `process_record_user()` gets one of the internal keycodes, it returns `true`, completely bypassing keyboard's and QMK's `process_record` functions. *All other* keycodes get passed down to QMK's standard processing. + +### Chords + +Each chord is defined by a constant structure, a function and two non-constant `int` variables keeping the track of the chord's state: + +```c +struct Chord { + uint32_t keycodes_hash; + uint8_t pseudolayer; + uint8_t* state; + uint8_t* counter; + uint16_t value1; + uint8_t value2; + void (*function) (const struct Chord*); +}; + +uint8_t state_0 = IDLE; +uint8_t counter_0 = 0; +void function_0(struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + register_code(self->value1); + break; + case DEACTIVATED: + unregister_code(self->value1); + break; + case FINISHED: + case PRESS_FROM_ACTIVE: + break; + case RESTART: + unregister_code(self->value1); + break; + default: + break; + } +} +const struct Chord chord_0 PROGMEM = {H_TOP1, QWERTY, &state_0, &counter_0, KC_Q, 0, function_0}; +``` + +All chords have to be added to `list_of_chord` array that gets regularly scanned and processed. The function doesn't actually activate on all state changes, there are a few more like `IDLE` (nothing is currently happening to the chord) or `IN_ONE_SHOT` (the chord is one shot and is currently locked). Those are all necessary for internal use only. The ones you have to worry about are + +* `ACTIVATED`: Analogous to a key being pressed (this includes repeated presses for tap-dance) +* `DEACTIVATED`: Analogous to a key being depressed (also can be repeated) +* `FINISHED`: Happens if the chord got deactivated and then the dance timer expired. +* `PRESS_FROM_ACTIVE`: Happens if the chord was active when the dance timer expired. Meaning you at least once activated the chord and then kept holding it down. Useful to recognize taps and holds. +* `FINISHED_FROM_ACTIVE`: Happens *after* `PRESS_FROM_HOLD` if the chord is still active when the dance timer expires for the second time. Can be combined with the `counter` to recognize even longer presses. Useful if you want to recognize long presses, for example for autoshift functionality. In `keyboard.inc` you can set `LONG_PRESS_MULTIPLIER` to set how many times does dance timer have to expire for the autoshift to trigger. +* `RESTART`: The dance is done. Happens immediately after `FINISHED` or on chord deactivation from `FINISHED_FROM_ACTIVE`. Anything you have to do to get the chord into `IDLE` mode happens here. + +The chords change states based on external and internal events. Anytime a chord's function is activated, it may change it's own state. Also, on certain events, the chording engine will trigger the functions of all chords in a specific state and *if the chords' state hasn't changed* it will then change it appropriately. The default behavior when a chord changes state is described by the following diagram: + +![state machine diagram](state_machine.png) +The colors differentiate in which function the change happens, see `state_machine.dot` for a bit more detail. Black arrows happen in more than one function. Arrows without a label happen immediately. + +You can see that the diagram is not exhaustive. For example nothing leads into `IN_ONE_SHOT`. That is because the chord's function can change the chord's state. This is useful for some advanced chords that break the default behavir (one-shots) and for optimization (chords that just send `KC_X` do not need to ever go into dance). + +## Caveats + +Each chord stores as much as possible in `PROGMEM` and unless it needs it, doesn't allocate `counter`. However it still has to store it's `state` and sometimes the `counter` in RAM. If you keep adding more chords, at one point you will run out. If your firmware fits in the memory and your keyboard crashes, try optimizing your RAM usage. + +Also, the code is not perfect. I keep testing it, but can not guarantee that it is stable. Some functions take (very short but still) time and if you happen to create keypress event when the keyboard can not see it, a chord can get stuck in a funny state. That is especially fun if the pseudolayer changes and you can not immediately press it again. Just restart the keyboard or push the key a few times. diff --git a/users/dennytom/chording_engine/chord.py b/users/dennytom/chording_engine/chord.py new file mode 100644 index 0000000000..707f36b82a --- /dev/null +++ b/users/dennytom/chording_engine/chord.py @@ -0,0 +1,466 @@ +from functools import reduce +import re + +strings = [] +number_of_strings = -1 + +def top_level_split(s): + """ + Split `s` by top-level commas only. Commas within parentheses are ignored. + """ + + # Parse the string tracking whether the current character is within + # parentheses. + balance = 0 + parts = [] + part = "" + + for i in range(len(s)): + c = s[i] + part += c + if c == '(': + balance += 1 + elif c == ')': + balance -= 1 + elif c == ',' and balance == 0 and not s[i+1] == ',': + part = part[:-1].strip() + parts.append(part) + part = "" + + # Capture last part + if len(part): + parts.append(part.strip()) + + return parts + +def new_chord(on_pseudolayer, keycodes_hash, has_counter, value1, value2, function, output_buffer, index): + counter_link = "NULL" + output_buffer += "uint8_t state_" + str(index) + " = IDLE;\n" + if has_counter: + output_buffer += "uint8_t counter_" + str(index) + " = 0;\n" + counter_link = "&counter_" + str(index) + output_buffer += "const struct Chord chord_" + str(index) + " PROGMEM = {" + keycodes_hash + ", " + on_pseudolayer + ", &state_" + str(index) + ", " + counter_link + ", " + str(value1) + ", " + str(value2) + ", " + function + "};\n" + index += 1 + return [output_buffer, index] + +def KC(on_pseudolayer, keycodes_hash, keycode, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, keycode, 0, "single_dance", output_buffer, index) + +def AS(on_pseudolayer, keycodes_hash, keycode, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, True, keycode, 0, "autoshift_dance", output_buffer, index) + +def AT(on_pseudolayer, keycodes_hash, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "autoshift_toggle", output_buffer, index) + +def KL(on_pseudolayer, keycodes_hash, keycode, to_pseudolayer, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, True, keycode, to_pseudolayer, "key_layer_dance", output_buffer, index) + +def KK(on_pseudolayer, keycodes_hash, keycode1, keycode2, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, True, keycode1, keycode2, "key_key_dance", output_buffer, index) + +def KM(on_pseudolayer, keycodes_hash, keycode, to_pseudolayer, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, keycode, to_pseudolayer, "key_mod_dance", output_buffer, index) + +def MO(on_pseudolayer, keycodes_hash, to_pseudolayer, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, to_pseudolayer, 0, "temp_pseudolayer", output_buffer, index) + +def MO_alt(on_pseudolayer, keycodes_hash, from_pseudolayer, to_pseudolayer, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, to_pseudolayer, from_pseudolayer, "temp_pseudolayer_alt", output_buffer, index) + +def LOCK(on_pseudolayer, keycodes_hash, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "lock", output_buffer, index) + +def DF(on_pseudolayer, keycodes_hash, to_pseudolayer, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, to_pseudolayer, 0, "perm_pseudolayer", output_buffer, index) + +def TO(on_pseudolayer, keycodes_hash, to_pseudolayer, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, to_pseudolayer, 0, "switch_layer", output_buffer, index) + +def OSK(on_pseudolayer, keycodes_hash, keycode, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, keycode, 0, "one_shot_key", output_buffer, index) + +def OSL(on_pseudolayer, keycodes_hash, to_pseudolayer, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, to_pseudolayer, 0, "one_shot_layer", output_buffer, index) + +def CMD(on_pseudolayer, keycodes_hash, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "command", output_buffer, index) + +def DM_RECORD(on_pseudolayer, keycodes_hash, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "dynamic_macro_record", output_buffer, index) + +def DM_NEXT(on_pseudolayer, keycodes_hash, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "dynamic_macro_next", output_buffer, index) + +def DM_END(on_pseudolayer, keycodes_hash, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "dynamic_macro_end", output_buffer, index) + +def DM_PLAY(on_pseudolayer, keycodes_hash, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "dynamic_macro_play", output_buffer, index) + +def LEAD(on_pseudolayer, keycodes_hash, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "leader", output_buffer, index) + +def CLEAR(on_pseudolayer, keycodes_hash, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "clear", output_buffer, index) + +def RESET(on_pseudolayer, keycodes_hash, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "reset", output_buffer, index) + +def STR(on_pseudolayer, keycodes_hash, string_input, output_buffer, index, number_of_strings, strings): + [a, b] = new_chord(on_pseudolayer, keycodes_hash, False, number_of_strings, 0, "string_in", output_buffer, index) + return [a, b, number_of_strings + 1, strings + [string_input]] + +def M(on_pseudolayer, keycodes_hash, value1, value2, fnc, output_buffer, index): + return new_chord(on_pseudolayer, keycodes_hash, True, value1, value2, fnc, output_buffer, index) + +def expand_keycode_fnc(DEFINITION): + if DEFINITION == "`": + DEFINITION = "GRAVE" + elif DEFINITION == "-": + DEFINITION = "MINUS" + elif DEFINITION == "=": + DEFINITION = "EQUAL" + elif DEFINITION == "[": + DEFINITION = "LBRACKET" + elif DEFINITION == "]": + DEFINITION = "RBRACKET" + elif DEFINITION == "\\": + DEFINITION = "BSLASH" + elif DEFINITION == ";": + DEFINITION = "SCOLON" + elif DEFINITION == "'": + DEFINITION = "QUOTE" + elif DEFINITION == ",": + DEFINITION = "COMMA" + elif DEFINITION == ".": + DEFINITION = "DOT" + elif DEFINITION == "/": + DEFINITION = "SLASH" + elif DEFINITION == "~": + DEFINITION = "TILDE" + elif DEFINITION == "*": + DEFINITION = "ASTERISK" + elif DEFINITION == "+": + DEFINITION = "PLUS" + elif DEFINITION == "(": + DEFINITION = "LEFT_PAREN" + elif DEFINITION == ")": + DEFINITION = "RIGHT_PAREN" + elif DEFINITION == "<": + DEFINITION = "LEFT_ANGLE_BRACKET" + elif DEFINITION == ">": + DEFINITION = "RIGHT_ANGLE_BRACKET" + elif DEFINITION == "{": + DEFINITION = "LEFT_CURLY_BRACE" + elif DEFINITION == "}": + DEFINITION = "RIGHT_CURLY_BRACE" + elif DEFINITION == "?": + DEFINITION = "QUESTION" + elif DEFINITION == "~": + DEFINITION = "TILDE" + elif DEFINITION == ":": + DEFINITION = "COLON" + elif DEFINITION == "_": + DEFINITION = "UNDERSCORE" + elif DEFINITION == '"': + DEFINITION = "DOUBLE_QUOTE" + elif DEFINITION == "@": + DEFINITION = "AT" + elif DEFINITION == "#": + DEFINITION = "HASH" + elif DEFINITION == "$": + DEFINITION = "DOLLAR" + elif DEFINITION == "!": + DEFINITION = "EXCLAIM" + elif DEFINITION == "%": + DEFINITION = "PERCENT" + elif DEFINITION == "^": + DEFINITION = "CIRCUMFLEX" + elif DEFINITION == "&": + DEFINITION = "AMPERSAND" + elif DEFINITION == "|": + DEFINITION = "PIPE" + + if DEFINITION in [ + "A", "a", "B", "b", "C", "c", "D", "d", "E", "e", + "F", "f", "G", "g", "H", "h", "I", "i", "J", "j", + "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", + "P", "p", "Q", "q", "R", "r", "S", "s", "T", "t", + "U", "u", "V", "v", "W", "w", "X", "x", "Y", "y", + "Z", "z", "1", "2", "3", "4", "5", "6", "7", "8", + "9", "0", "F1", "F2", "F3", "F4", "F5", "F6", "F7", + "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", + "F16", "F17", "F18", "F19", "F20", "F21", "F22", + "F23", "F24", "ENTER", "ENT", "ESCAPE", "ESC", + "BSPACE", "BSPC", "TAB", "SPACE", "SPC", "NONUS_HASH", + "NUHS", "NONUS_BSLASH", "NUBS", "COMMA", "COMM", + "DOT", "SLASH", "SLSH", "TILDE", "TILD", "EXCLAIM", + "EXLM", "AT", "HASH", "DOLLAR", "DLR", "PERCENT", + "PERC", "CIRCUMFLEX", "CIRC", "AMPERSAND", "AMPR", + "ASTERISK", "ASTR", "LEFT_PAREN", "LPRN", "RIGHT_PAREN", + "RPRN", "UNDERSCORE", "UNDS", "PLUS", "LEFT_CURLY_BRACE", + "LCBR", "RIGHT_CURLY_BRACE", "RCBR", "PIPE", "COLON", + "COLN", "DOUBLE_QUOTE", "DQUO", "DQT", + "LEFT_ANGLE_BRACKET", "LABK", "LT", "RIGHT_ANGLE_BRACKET", + "RABK", "GT", "QUESTION", "QUES", "SCOLON", "SCLN", + "QUOTE", "QUOT", "LBRACKET", "LBRC", "RBRACKET", "RBRC", + "BSLASH", "BSLS", "MINUS", "MINS", "EQUAL", "EQL", + "GRAVE", "GRV", "ZKHK", "CAPSLOCK", "CLCK", "CAPS", + "SCROLLOCK", "SLCK", "BRMD", "NUMLOCK", "NLCK", + "LOCKING_CAPS", "LCAP", "LOCKING_NUM", "LNUM", + "LOCKING_SCROLL", "LSCR", "LCTRL", "LCTL", "LSHIFT", + "LSFT", "LALT", "LGUI", "LCMD", "LWIN", "RCTRL", + "RCTL", "RSHIFT", "RSFT", "RALT", "RGUI", "RCMD", + "RWIN", "INT1", "RO", "INT2", "KANA", "INT3", "JYEN", + "INT4", "HENK", "INT5", "MHEN", "INT6", "INT7", + "INT8", "INT9", "LANG1", "HAEN", "LANG2", "HANJ", + "LANG3", "LANG4", "LANG5", "LANG6", "LANG7", "LANG8", + "LANG9", "PSCREEN", "PSCR", "PAUSE", "PAUS", "BRK", + "BRMU", "INSERT", "INS", "HOME", "PGUP", "DELETE", + "DEL", "END", "PGDOWN", "PGDN", "RIGHT", "RGHT", + "LEFT", "DOWN", "UP", "APPLICATION", "APP", "POWER", + "EXECUTE", "EXEC", "HELP", "MENU", "SELECT", "SLCT", + "STOP", "AGAIN", "AGIN", "UNDO", "CUT", "COPY", + "PASTE", "PSTE", "FIND", "MUTE", "VOLUP", "VOLDOWN", + "ALT_ERASE", "ERAS", "SYSREQ", "CANCEL", "CLEAR", + "CLR", "PRIOR", "RETURN", "SEPARATOR", "OUT", "OPER", + "CLEAR_AGAIN", "CRSEL", "EXSEL", "SYSTEM_POWER", + "PWR", "SYSTEM_SLEEP", "SLEP", "SYSTEM_WAKE", "WAKE", + "AUDIO_MUTE", "MUTE", "AUDIO_VOL_UP", "VOLU", + "AUDIO_VOL_DOWN", "VOLD", "MEDIA_NEXT_TRACK", "MNXT", + "MEDIA_PREV_TRACK", "MPRV", "CPRV", "MEDIA_STOP", "MSTP", + "MEDIA_PLAY_PAUSE", "MPLY", "MEDIA_SELECT", "MSEL", + "MEDIA_EJECT", "EJCT", "MAIL", "CALCULATOR", "CALC", + "MY_COMPUTER", "MYCM", "WWW_SEARCH", "WSCH", "WWW_HOME", + "WHOM", "WWW_BACK", "WBAK", "WWW_FORWARD", "WFWD", + "WWW_STOP", "WSTP", "WWW_REFRESH", "WREF", + "WWW_FAVORITES", "WFAV", "MEDIA_FAST_FORWARD", "MFFD", + "MEDIA_REWIND", "MRWD", "BRIGHTNESS_UP", "BRIU", + "BRIGHTNESS_DOWN", "BRID", "KP_SLASH", "PSLS", + "KP_ASTERISK", "PAST", "KP_MINUS", "PMNS", "KP_PLUS", + "PPLS", "KP_ENTER", "PENT", "KP_1", "P1", "KP_2", "P2", + "KP_3", "P3", "KP_4", "P4", "KP_5", "P5", "KP_6", "P6", + "KP_7", "P7", "KP_8", "P8", "KP_9", "P9", "KP_0", "P0", + "KP_DOT", "PDOT", "KP_EQUAL", "PEQL", "KP_COMMA", "PCMM", + "MS_BTN1", "BTN1", "MS_BTN2", "BTN2", "MS_BTN3", "BTN3", + "MS_BTN4", "BTN4", "MS_BTN5", "BTN5", "MS_BTN6", "BTN6", + "MS_LEFT", "MS_L", "MS_DOWN", "MS_D", "MS_UP", "MS_U", + "MS_RIGHT", "MS_R", "MS_WH_UP", "WH_U", "MS_WH_DOWN", + "WH_D", "MS_WH_LEFT", "MS_WH_L", "MS_WH_RIGHT", "MS_WH_R", + "KC_MS_ACCEL0", "ACL0", "KC_MS_ACCEL1", "ACL1", + "KC_MS_ACCEL2", "ACL2" + ]: + return "KC_" + DEFINITION + else: + return DEFINITION + +def MK(on_pseudolayer, keycodes_hash, definition, output_buffer, index): + l = len(definition.split(', ')) + output_buffer += "void function_" + str(index) + "(const struct Chord* self) {\n" + output_buffer += " switch (*self->state) {\n" + output_buffer += " case ACTIVATED:\n" + for i in range(0, l): + val = definition.split(',')[i].strip() + code = expand_keycode_fnc(val) + output_buffer += " key_in(" + code + ");\n" + output_buffer += " break;\n" + output_buffer += " case DEACTIVATED:\n" + for i in range(0, l): + val = definition.split(',')[i].strip() + code = expand_keycode_fnc(val) + output_buffer += " key_out(" + code + ");\n" + output_buffer += " *self->state = IDLE;\n" + output_buffer += " break;\n" + output_buffer += " case RESTART:\n" + for i in range(0, l): + val = definition.split(',')[i].strip() + code = expand_keycode_fnc(val) + output_buffer += " key_out(" + code + ");\n" + output_buffer += " break;\n" + output_buffer += " default:\n" + output_buffer += " break;\n" + output_buffer += " };\n" + output_buffer += "}\n" + return new_chord(on_pseudolayer, keycodes_hash, True, 0, 0, "function_" + str(index), output_buffer, index) + +def D(on_pseudolayer, keycodes_hash, DEFINITION, output_buffer, index): + l = len(DEFINITION.split(',')) + output_buffer += "void function_" + str(index) + "(const struct Chord* self) {\n" + output_buffer += " switch (*self->state) {\n" + output_buffer += " case ACTIVATED:\n" + output_buffer += " *self->counter = *self->counter + 1;\n" + output_buffer += " break;\n" + output_buffer += " case PRESS_FROM_ACTIVE:\n" + output_buffer += " switch (*self->counter) {\n" + for i in range(0, l): + val = DEFINITION.split(',')[i].strip() + code = expand_keycode_fnc(val) + output_buffer += " case " + str(i + 1) + ":\n" + output_buffer += " key_in( " + code + ");\n" + output_buffer += " break;\n" + output_buffer += " default:\n" + output_buffer += " break;\n" + output_buffer += " }\n" + output_buffer += " *self->state = FINISHED_FROM_ACTIVE;\n" + output_buffer += " break;\n" + output_buffer += " case FINISHED:\n" + output_buffer += " switch (*self->counter) {\n" + for i in range(0, l): + val = DEFINITION.split(',')[i].strip() + code = expand_keycode_fnc(val) + output_buffer += " case " + str(i + 1) + ":\n" + output_buffer += " tap_key( " + code + ");\n" + output_buffer += " break;\n" + output_buffer += " default:\n" + output_buffer += " break;\n" + output_buffer += " }\n" + output_buffer += " *self->counter = 0;\n" + output_buffer += " *self->state = IDLE;\n" + output_buffer += " break;\n" + output_buffer += " case RESTART:\n" + output_buffer += " switch (*self->counter) {\n" + for i in range(0, l): + val = DEFINITION.split(',')[i].strip() + code = expand_keycode_fnc(val) + output_buffer += " case " + str(i + 1) + ":\n" + output_buffer += " key_out( " + code + ");\n" + output_buffer += " break;\n" + output_buffer += " default:\n" + output_buffer += " break;\n" + output_buffer += " }\n" + output_buffer += " *self->counter = 0;\n" + output_buffer += " break;\n" + output_buffer += " default:\n" + output_buffer += " break;\n" + output_buffer += " }\n" + output_buffer += "}\n" + return new_chord(on_pseudolayer, keycodes_hash, True, 0, 0, "function_" + str(index), output_buffer, index) + +def O(on_pseudolayer, keycodes_hash, DEFINITION, output_buffer, index): + if DEFINITION[0:3] == "KC_": + return OSK(on_pseudolayer, keycodes_hash, DEFINITION, output_buffer, index) + else: + return OSL(on_pseudolayer, keycodes_hash, DEFINITION, output_buffer, index) + +def add_key(PSEUDOLAYER, KEYCODES_HASH, DEFINITION, output_buffer, index, number_of_strings, strings): + # if "= {" + KEYCODES_HASH + ", " + PSEUDOLAYER in output_buffer: + # KEYCODES_HASH = re.sub('H_', '', KEYCODES_HASH) + # raise Exception("You are trying to register a chord that you already registered (" + KEYCODES_HASH + ", " + PSEUDOLAYER + ")") + + if DEFINITION == "": + return [output_buffer, index, number_of_strings, strings] + else: + split = DEFINITION.split("(") + type = split[0].strip() + if len(split) == 1: + if type == "LOCK": + [output_buffer, index] = LOCK(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index) + elif type == "AT": + [output_buffer, index] = AT(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index) + elif type == "CMD": + [output_buffer, index] = CMD(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index) + elif type == "LEAD": + [output_buffer, index] = LEAD(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index) + elif type == "DM_RECORD": + [output_buffer, index] = DM_RECORD(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index) + elif type == "DM_NEXT": + [output_buffer, index] = DM_NEXT(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index) + elif type == "DM_END": + [output_buffer, index] = DM_END(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index) + elif type == "DM_PLAY": + [output_buffer, index] = DM_PLAY(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index) + elif type == "CLEAR_KB": + [output_buffer, index] = CLEAR(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index) + elif type == "RESET": + [output_buffer, index] = RESET(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index) + else: + code = expand_keycode_fnc(type) + [output_buffer, index] = KC(PSEUDOLAYER, KEYCODES_HASH, code, output_buffer, index) + else: + val = split[1][:-1].strip() + if type == "O": + code = expand_keycode_fnc(val) + [output_buffer, index] = O(PSEUDOLAYER, KEYCODES_HASH, code, output_buffer, index) + elif type == "D": + [output_buffer, index] = D(PSEUDOLAYER, KEYCODES_HASH, val, output_buffer, index) + elif type == "MK": + [output_buffer, index] = MK(PSEUDOLAYER, KEYCODES_HASH, val, output_buffer, index) + elif type == "M": + fnc = val.split(',')[0].strip() + val1 = val.split(',')[1].strip() + val2 = val.split(',')[2].strip() + [output_buffer, index] = M(PSEUDOLAYER, KEYCODES_HASH, val1, val2, fnc, output_buffer, index) + elif type == "KK": + val1 = val.split(',')[0].strip() + code1 = expand_keycode_fnc(val1) + val2 = val.split(',')[1].strip() + code2 = expand_keycode_fnc(val2) + [output_buffer, index] = KK(PSEUDOLAYER, KEYCODES_HASH, code1, code2, output_buffer, index) + elif type == "KL": + val1 = val.split(',')[0].strip() + code1 = expand_keycode_fnc(val1) + val2 = val.split(',')[1].strip() + [output_buffer, index] = KL(PSEUDOLAYER, KEYCODES_HASH, code1, val2, output_buffer, index) + elif type == "KM": + val1 = val.split(',')[0].strip() + code1 = expand_keycode_fnc(val1) + val2 = val.split(',')[1].strip() + code2 = expand_keycode_fnc(val2) + [output_buffer, index] = KM(PSEUDOLAYER, KEYCODES_HASH, code1, code2, output_buffer, index) + elif type == "AS": + code = expand_keycode_fnc(val) + [output_buffer, index] = AS(PSEUDOLAYER, KEYCODES_HASH, code, output_buffer, index) + elif type == "MO": + if not ',' in val: + [output_buffer, index] = MO(PSEUDOLAYER, KEYCODES_HASH, val, output_buffer, index) + else: + val1 = val.split(',')[0].strip() + val2 = val.split(',')[1].strip() + [output_buffer, index] = MO_alt(PSEUDOLAYER, KEYCODES_HASH, val1, val2, output_buffer, index) + elif type == "DF": + [output_buffer, index] = DF(PSEUDOLAYER, KEYCODES_HASH, val, output_buffer, index) + elif type == "TO": + [output_buffer, index] = TO(PSEUDOLAYER, KEYCODES_HASH, val, output_buffer, index) + elif type == "STR": + [output_buffer, index, number_of_strings, strings] = STR(PSEUDOLAYER, KEYCODES_HASH, val, output_buffer, index, number_of_strings, strings) + return [output_buffer, index, number_of_strings, strings] + +def add_leader_combo(DEFINITION, FUNCTION): + return list_of_leader_combos.append([DEFINITION, FUNCTION]) + +def add_chord_set(PSEUDOLAYER, INPUT_STRING, TYPE, data, output_buffer, index, number_of_strings, strings): + chord_set = {} + for set in data["chord_sets"]: + if set["name"] == TYPE: + chord_set = set["chords"] + break + + separated_string = top_level_split(INPUT_STRING) + for word, chord in zip(separated_string, chord_set): + chord_hash = reduce((lambda x, y: str(x) + " + " + str(y)), ["H_" + key for key in chord]) + [output_buffer, index, number_of_strings, strings] = add_key(PSEUDOLAYER, chord_hash, word, output_buffer, index, number_of_strings, strings) + + return [output_buffer, index, number_of_strings, strings] + +def add_dictionary(PSEUDOLAYER, keycodes, array, output_buffer, index, number_of_strings, strings): + for chord in array: + hash = "" + for word, key in zip(chord[:-1], keycodes): + if word == "X": + hash = hash + " + H_" + key + hash = hash[3:] + if hash != "": + [output_buffer, index, number_of_strings, strings] = add_key(PSEUDOLAYER, hash, chord[-1], output_buffer, index, number_of_strings, strings) + + return [output_buffer, index, number_of_strings, strings] + +def secret_chord(PSEUDOLAYER, ACTION, INPUT_STRING, data, output_buffer, index, number_of_strings, strings): + separated_string = top_level_split(INPUT_STRING) + hash = "" + for word, key in zip(separated_string, data["keys"]): + if word == "X": + hash = hash + " + H_" + key + + hash = hash[3:] + if hash != "": + return add_key(PSEUDOLAYER, hash, ACTION, output_buffer, index, number_of_strings, strings)
\ No newline at end of file diff --git a/users/dennytom/chording_engine/engine.part.1 b/users/dennytom/chording_engine/engine.part.1 new file mode 100644 index 0000000000..73df4cdeaa --- /dev/null +++ b/users/dennytom/chording_engine/engine.part.1 @@ -0,0 +1,163 @@ +enum chord_states { + IDLE, + READY, + ACTIVATED, + DEACTIVATED, + PRESS_FROM_ACTIVE, + FINISHED_FROM_ACTIVE, + IDLE_IN_DANCE, + READY_IN_DANCE, + FINISHED, + LOCKED, + READY_LOCKED, + RESTART, + IN_ONE_SHOT +}; + +struct Chord { + uint32_t keycodes_hash; + uint8_t pseudolayer; + uint8_t* state; + uint8_t* counter; + uint16_t value1; + uint8_t value2; + void (*function) (const struct Chord*); +}; + +uint8_t current_pseudolayer = DEFAULT_PSEUDOLAYER; +bool lock_next = false; +uint16_t chord_timer = 0; +uint16_t dance_timer = 0; +bool autoshift_mode = true; +uint8_t keycode_index = 0; +uint8_t command_mode = 0; +uint8_t command_ind = 0; +bool in_leader_mode = false; +uint8_t leader_ind = 0; +uint16_t leader_timer = 0; +uint8_t dynamic_macro_mode = false; +uint8_t dynamic_macro_ind = 0; +bool a_key_went_through = false; +struct Chord* last_chord = NULL; + +bool handle_US_ANSI_shifted_keys(int16_t keycode, bool in) { + bool is_US_ANSI_shifted = true; + + int16_t regular_keycode = KC_NO; + switch (keycode) { + case KC_TILDE: + regular_keycode = KC_GRAVE; + break; + case KC_EXCLAIM: + regular_keycode = KC_1; + break; + case KC_AT: + regular_keycode = KC_2; + break; + case KC_HASH: + regular_keycode = KC_3; + break; + case KC_DOLLAR: + regular_keycode = KC_4; + break; + case KC_PERCENT: + regular_keycode = KC_5; + break; + case KC_CIRCUMFLEX: + regular_keycode = KC_6; + break; + case KC_AMPERSAND: + regular_keycode = KC_7; + break; + case KC_ASTERISK: + regular_keycode = KC_8; + break; + case KC_LEFT_PAREN: + regular_keycode = KC_9; + break; + case KC_RIGHT_PAREN: + regular_keycode = KC_0; + break; + case KC_UNDERSCORE: + regular_keycode = KC_MINUS; + break; + case KC_PLUS: + regular_keycode = KC_EQUAL; + break; + case KC_LEFT_CURLY_BRACE: + regular_keycode = KC_LBRACKET; + break; + case KC_RIGHT_CURLY_BRACE: + regular_keycode = KC_RBRACKET; + break; + case KC_PIPE: + regular_keycode = KC_BSLASH; + break; + case KC_COLON: + regular_keycode = KC_SCOLON; + break; + case KC_DOUBLE_QUOTE: + regular_keycode = KC_QUOTE; + break; + case KC_LEFT_ANGLE_BRACKET: + regular_keycode = KC_COMMA; + break; + case KC_RIGHT_ANGLE_BRACKET: + regular_keycode = KC_DOT; + break; + case KC_QUESTION: + regular_keycode = KC_SLASH; + break; + default: + is_US_ANSI_shifted = false; + } + if (is_US_ANSI_shifted) { + if (in) { + register_code(KC_LSFT); + register_code(regular_keycode); + } else { + unregister_code(regular_keycode); + unregister_code(KC_LSFT); + } + } + return is_US_ANSI_shifted; +} + +void key_in(int16_t keycode) { + if (command_mode == 1 && command_ind < COMMAND_MAX_LENGTH) { + command_buffer[command_ind] = keycode; + command_ind++; + a_key_went_through = true; + } else if (in_leader_mode && leader_ind < LEADER_MAX_LENGTH) { + leader_buffer[leader_ind] = keycode; + leader_ind++; + a_key_went_through = true; + } else if (dynamic_macro_mode && dynamic_macro_ind < DYNAMIC_MACRO_MAX_LENGTH) { + dynamic_macro_buffer[dynamic_macro_ind] = keycode; + dynamic_macro_ind++; + a_key_went_through = true; + } else { + if (!handle_US_ANSI_shifted_keys(keycode, true)) { + register_code(keycode); + } + send_keyboard_report(); + a_key_went_through = true; + } +} + +void key_out(int16_t keycode) { + if (command_mode == 0) { + if (!handle_US_ANSI_shifted_keys(keycode, false)) { + if (command_mode == 0 && in_leader_mode == false && dynamic_macro_mode == false) { + unregister_code(keycode); + } + } + send_keyboard_report(); + } +} + +void tap_key(int16_t keycode) { + key_in(keycode); + wait_ms(TAP_TIMEOUT); + key_out(keycode); +}
\ No newline at end of file diff --git a/users/dennytom/chording_engine/engine.part.2 b/users/dennytom/chording_engine/engine.part.2 new file mode 100644 index 0000000000..91dcbb7503 --- /dev/null +++ b/users/dennytom/chording_engine/engine.part.2 @@ -0,0 +1,323 @@ +void single_dance(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + key_in(self->value1); + break; + case DEACTIVATED: + key_out(self->value1); + *self->state = IDLE; + break; + case RESTART: + key_out(self->value1); + break; + default: + break; + } +} + +void key_layer_dance(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + current_pseudolayer = self->value2; + a_key_went_through = false; + break; + case DEACTIVATED: + case RESTART: + if (!a_key_went_through) { + tap_key(self->value1); + } + current_pseudolayer = self->pseudolayer; + *self->state = IDLE; // does not have effect if the state was RESTART + break; + default: + break; + } +} + +void key_mod_dance(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + key_in(self->value2); + a_key_went_through = false; + break; + case DEACTIVATED: + case RESTART: + key_out(self->value2); + if (!a_key_went_through) { + tap_key(self->value1); + } + *self->state = IDLE; // does not have effect if the state was RESTART + break; + default: + break; + } +} + +void key_key_dance(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + break; + case DEACTIVATED: + tap_key(self->value1); + *self->state = IDLE; + break; + case FINISHED: + case PRESS_FROM_ACTIVE: + key_in(self->value2); + break; + case RESTART: + key_out(self->value2); + break; + default: + break; + } +} + +void autoshift_dance_impl(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + *self->counter = 0; + break; + case DEACTIVATED: + case RESTART: + tap_key(self->value1); + *self->state = IDLE; + break; + case FINISHED_FROM_ACTIVE: + if (*self->counter == (LONG_PRESS_MULTIPLIER - 2)) { + key_in(KC_LSFT); + tap_key(self->value1); + key_out(KC_LSFT); + *self->state = IDLE; + // the skip to IDLE is usually just a lag optimization, + // in this case it has a logic function, on a short + // press (still longer than a tap) the key does not get shifted + } else { + *self->counter += 1; + *self->state = PRESS_FROM_ACTIVE; + dance_timer = timer_read(); + } + break; + default: + break; + } +} + +void autoshift_dance(const struct Chord* self) { + if (autoshift_mode) { + autoshift_dance_impl(self); + } else { + single_dance(self); + } +} + +void autoshift_toggle(const struct Chord* self){ + if (*self->state == ACTIVATED) { + autoshift_mode = !autoshift_mode; + *self->state = IDLE; + } +} + +void temp_pseudolayer(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + current_pseudolayer = self->value1; + break; + case DEACTIVATED: + current_pseudolayer = self->pseudolayer; + *self->state = IDLE; + break; + case RESTART: + current_pseudolayer = self->pseudolayer; + break; + default: + break; + } +} + +void temp_pseudolayer_alt(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + current_pseudolayer = self->value1; + break; + case DEACTIVATED: + current_pseudolayer = self->value2; + *self->state = IDLE; + break; + case RESTART: + current_pseudolayer = self->value2; + break; + default: + break; + } +} + +void perm_pseudolayer(const struct Chord* self) { + if (*self->state == ACTIVATED) { + current_pseudolayer = self->value1; + *self->state = IDLE; + } +} + +void switch_layer(const struct Chord* self) { + if (*self->state == ACTIVATED) { + layer_move(self->value1); + *self->state = IDLE; + } +} + +void lock(const struct Chord* self) { + if (*self->state == ACTIVATED) { + lock_next = true; + *self->state = IDLE; + } +} + +void one_shot_key(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + break; + case DEACTIVATED: + key_in(self->value1); + *self->state = IN_ONE_SHOT; + break; + case FINISHED: + case PRESS_FROM_ACTIVE: + key_in(self->value1); + a_key_went_through = false; + break; + case RESTART: + if (a_key_went_through) { + key_out(self->value1); + } else { + *self->state = IN_ONE_SHOT; + } + default: + break; + } +} + +void one_shot_layer(const struct Chord* self) { + switch (*self->state) { + case ACTIVATED: + break; + case DEACTIVATED: + current_pseudolayer = self->value1; + *self->state = IN_ONE_SHOT; + break; + case FINISHED: + case PRESS_FROM_ACTIVE: + current_pseudolayer = self->value1; + a_key_went_through = false; + break; + case RESTART: + if (a_key_went_through) { + current_pseudolayer = self->pseudolayer; + } else { + *self->state = IN_ONE_SHOT; + } + default: + break; + } +} + +void command(const struct Chord* self) { + if (*self->state == ACTIVATED) { + command_mode++; + *self->state = IDLE; + } +} + +bool identical(uint16_t* buffer1, uint16_t* buffer2) { + bool same = true; + for (int i = 0; i < LEADER_MAX_LENGTH; i++) { + same = same && (buffer1[i] == buffer2[i]); + } + return same; +} + +void leader(const struct Chord* self) { + if (*self->state == ACTIVATED) { + in_leader_mode = true; + *self->state = IDLE; + } +} + +void dynamic_macro_record(const struct Chord* self) { + if (*self->state == ACTIVATED) { + for (int i = 0; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + dynamic_macro_buffer[i] = 0; + } + dynamic_macro_mode = true; + *self->state = IDLE; + } +} + +void dynamic_macro_next(const struct Chord* self) { + if (*self->state == ACTIVATED) { + if (dynamic_macro_mode && dynamic_macro_ind < DYNAMIC_MACRO_MAX_LENGTH) { + dynamic_macro_buffer[dynamic_macro_ind] = 0; + dynamic_macro_ind++; + } + *self->state = IDLE; + } +} + +void dynamic_macro_end(const struct Chord* self) { + if (*self->state == ACTIVATED) { + if (dynamic_macro_mode) { + dynamic_macro_mode = false; + } + *self->state = IDLE; + } +} + +void dynamic_macro_play(const struct Chord* self) { + if (*self->state == ACTIVATED) { + int ind_start = 0; + while (ind_start < DYNAMIC_MACRO_MAX_LENGTH) { + for (int i = ind_start; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + if (dynamic_macro_buffer[i] == 0) { + break; + } + register_code(dynamic_macro_buffer[i]); + } + send_keyboard_report(); + wait_ms(TAP_TIMEOUT); + for (int i = ind_start; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + if (dynamic_macro_buffer[i] == 0) { + ind_start = i + 1; + break; + } + unregister_code(dynamic_macro_buffer[i]); + } + send_keyboard_report(); + } + *self->state = IDLE; + } +} + +void string_in(const struct Chord* self) { + if (*self->state == ACTIVATED) { + char buffer[STRING_MAX_LENGTH]; + strcpy_P(buffer, (char*)pgm_read_word(&(strings[self->value1]))); + send_string(buffer); + } +} + +void clear(const struct Chord* self); + +void reset_keyboard_kb(void){ +#ifdef WATCHDOG_ENABLE + MCUSR = 0; + wdt_disable(); + wdt_reset(); +#endif + reset_keyboard(); +} + +void reset(const struct Chord* self) { + if (*self->state == ACTIVATED) { + reset_keyboard_kb(); + } +} diff --git a/users/dennytom/chording_engine/engine.part.3 b/users/dennytom/chording_engine/engine.part.3 new file mode 100644 index 0000000000..cf19008abc --- /dev/null +++ b/users/dennytom/chording_engine/engine.part.3 @@ -0,0 +1,404 @@ +bool are_hashed_keycodes_in_sound(HASH_TYPE keycodes_hash, HASH_TYPE sound) { + return (keycodes_hash & sound) == keycodes_hash; +} + +uint8_t keycode_to_index(uint16_t keycode) { + return keycode - FIRST_INTERNAL_KEYCODE; +} + +void sound_keycode_array(uint16_t keycode) { + uint8_t index = keycode_to_index(keycode); + keycode_index++; + keycodes_buffer_array[index] = keycode_index; +} + +void silence_keycode_hash_array(HASH_TYPE keycode_hash) { + for (int i = 0; i < NUMBER_OF_KEYS; i++) { + bool index_in_hash = ((HASH_TYPE) 1 << i) & keycode_hash; + if (index_in_hash) { + uint8_t current_val = keycodes_buffer_array[i]; + keycodes_buffer_array[i] = 0; + for (int j = 0; j < NUMBER_OF_KEYS; j++) { + if (keycodes_buffer_array[j] > current_val) { + keycodes_buffer_array[j]--; + } + } + keycode_index--; + } + } +} + +bool are_hashed_keycodes_in_array(HASH_TYPE keycode_hash) { + for (int i = 0; i < NUMBER_OF_KEYS; i++) { + bool index_in_hash = ((HASH_TYPE) 1 << i) & keycode_hash; + bool index_in_array = (bool) keycodes_buffer_array[i]; + if (index_in_hash && !index_in_array) { + return false; + } + } + return true; +} + +void kill_one_shots(void) { + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + if (*chord->state == IN_ONE_SHOT) { + *chord->state = RESTART; + chord->function(chord); + if (*chord->state == RESTART) { + *chord->state = IDLE; + } + } + } +} + +void process_finished_dances(void) { + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + if (*chord->state == ACTIVATED) { + *chord->state = PRESS_FROM_ACTIVE; + chord->function(chord); + if (a_key_went_through) { + kill_one_shots(); + } + dance_timer = timer_read(); + } else if (*chord->state == IDLE_IN_DANCE) { + *chord->state = FINISHED; + chord->function(chord); + if (*chord->state == FINISHED) { + *chord->state = RESTART; + if (*chord->state == RESTART) { + *chord->state = IDLE; + } + } + } else if (*chord->state == PRESS_FROM_ACTIVE) { + *chord->state = FINISHED_FROM_ACTIVE; + chord->function(chord); + if (a_key_went_through) { + kill_one_shots(); + } + dance_timer = timer_read(); + } + } +} + +uint8_t keycodes_buffer_array_min(uint8_t* first_keycode_index) { + for (int i = 0; i < NUMBER_OF_KEYS; i++) { + if (keycodes_buffer_array[i] == 1) { + if (first_keycode_index != NULL) { + *first_keycode_index = (uint8_t) i; + } + return 1; + } + } + return 0; +} + +void remove_subchords(void) { + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + if (!(*chord->state == READY || *chord->state == READY_IN_DANCE || *chord->state == READY_LOCKED)) { + continue; + } + + struct Chord chord_storage_2; + struct Chord* chord_ptr_2; + struct Chord* chord_2; + for (int j = 0; j < NUMBER_OF_CHORDS; j++) { + if (i == j) {continue;} + + chord_ptr_2 = (struct Chord*) pgm_read_word (&list_of_chords[j]); + memcpy_P(&chord_storage_2, chord_ptr_2, sizeof(struct Chord)); + chord_2 = &chord_storage_2; + + if (are_hashed_keycodes_in_sound(chord_2->keycodes_hash, chord->keycodes_hash)) { + if (*chord_2->state == READY) { + *chord_2->state = IDLE; + } + if (*chord_2->state == READY_IN_DANCE) { + *chord_2->state = IDLE_IN_DANCE; + } + if (*chord_2->state == READY_LOCKED) { + *chord_2->state = LOCKED; + } + } + } + } +} + +void process_ready_chords(void) { + uint8_t first_keycode_index = 0; + while (keycodes_buffer_array_min(&first_keycode_index)) { + // find ready chords + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + // if the chord does not contain the first keycode + bool contains_first_keycode = ((uint32_t) 1 << first_keycode_index) & chord->keycodes_hash; + if (!contains_first_keycode) { + continue; + } + + if (!are_hashed_keycodes_in_array(chord->keycodes_hash)){ + continue; + } + + if (*chord->state == LOCKED) { + *chord->state = READY_LOCKED; + continue; + } + + if (!(chord->pseudolayer == current_pseudolayer || chord->pseudolayer == ALWAYS_ON)) { + continue; + } + + if (*chord->state == IDLE) { + *chord->state = READY; + continue; + } + + if (*chord->state == IDLE_IN_DANCE) { + *chord->state = READY_IN_DANCE; + } + } + + // remove subchords + remove_subchords(); + + // execute logic + // this should be only one chord + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + if (*chord->state == READY_LOCKED) { + *chord->state = RESTART; + chord->function(chord); + if (*chord->state == RESTART) { + *chord->state = IDLE; + } + break; + } + + if (*chord->state == READY || *chord->state == READY_IN_DANCE) { + if (last_chord && last_chord != chord) { + process_finished_dances(); + } + + bool lock_next_prev_state = lock_next; + + *chord->state = ACTIVATED; + chord->function(chord); + dance_timer = timer_read(); + + if (lock_next && lock_next == lock_next_prev_state) { + lock_next = false; + *chord->state = PRESS_FROM_ACTIVE; + chord->function(chord); + if (*chord->state == PRESS_FROM_ACTIVE) { + *chord->state = LOCKED; + } + if (a_key_went_through) { + kill_one_shots(); + } + } + break; + } + } + + // silence notes + silence_keycode_hash_array(chord->keycodes_hash); + } +} + +void deactivate_active_chords(uint16_t keycode) { + HASH_TYPE hash = (HASH_TYPE)1 << (keycode - SAFE_RANGE); + bool broken; + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + broken = are_hashed_keycodes_in_sound(hash, chord->keycodes_hash); + if (!broken) { + continue; + } + + switch (*chord->state) { + case ACTIVATED: + *chord->state = DEACTIVATED; + chord->function(chord); + + if (*chord->state == DEACTIVATED) { + dance_timer = timer_read(); + *chord->state = IDLE_IN_DANCE; + } + if (*chord->state != IN_ONE_SHOT) { + kill_one_shots(); + } + break; + case PRESS_FROM_ACTIVE: + case FINISHED_FROM_ACTIVE: + *chord->state = RESTART; + chord->function(chord); + if (*chord->state == RESTART) { + *chord->state = IDLE; + } + kill_one_shots(); + break; + default: + break; + } + } + +} + +void process_command(void) { + command_mode = 0; + for (int i = 0; i < COMMAND_MAX_LENGTH; i++) { + if (command_buffer[i]) { + register_code(command_buffer[i]); + } + send_keyboard_report(); + } + wait_ms(TAP_TIMEOUT); + for (int i = 0; i < COMMAND_MAX_LENGTH; i++) { + if (command_buffer[i]) { + unregister_code(command_buffer[i]); + } + send_keyboard_report(); + } + for (int i = 0; i < COMMAND_MAX_LENGTH; i++) { + command_buffer[i] = 0; + } + command_ind = 0; +} + +void process_leader(void) { + in_leader_mode = false; + for (int i = 0; i < NUMBER_OF_LEADER_COMBOS; i++) { + uint16_t trigger[LEADER_MAX_LENGTH]; + memcpy_P(trigger, leader_triggers[i], LEADER_MAX_LENGTH * sizeof(uint16_t)); + + if (identical(leader_buffer, trigger)) { + (*leader_functions[i])(); + break; + } + } + for (int i = 0; i < LEADER_MAX_LENGTH; i++) { + leader_buffer[i] = 0; + } +} + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (keycode < FIRST_INTERNAL_KEYCODE || keycode > LAST_INTERNAL_KEYCODE) { + return true; + } + + if (record->event.pressed) { + sound_keycode_array(keycode); + } else { + process_ready_chords(); + deactivate_active_chords(keycode); + } + chord_timer = timer_read(); + leader_timer = timer_read(); + + return false; +} + +void matrix_scan_user(void) { + bool chord_timer_expired = timer_elapsed(chord_timer) > CHORD_TIMEOUT; + if (chord_timer_expired && keycodes_buffer_array_min(NULL)) { + process_ready_chords(); + } + + bool dance_timer_expired = timer_elapsed(dance_timer) > DANCE_TIMEOUT; + if (dance_timer_expired) { // would love to have && in_dance but not sure how + process_finished_dances(); + } + + bool in_command_mode = command_mode == 2; + if (in_command_mode) { + process_command(); + } + + bool leader_timer_expired = timer_elapsed(leader_timer) > LEADER_TIMEOUT; + if (leader_timer_expired && in_leader_mode) { + process_leader(); + } + +} + +void clear(const struct Chord* self) { + if (*self->state == ACTIVATED) { + // kill all chords + struct Chord chord_storage; + struct Chord* chord_ptr; + struct Chord* chord; + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + chord = &chord_storage; + + *chord->state = IDLE; + + if (chord->counter) { + *chord->counter = 0; + } + } + + // clear keyboard + clear_keyboard(); + send_keyboard_report(); + + // switch to default pseudolayer + current_pseudolayer = DEFAULT_PSEUDOLAYER; + + // clear all keyboard states + lock_next = false; + autoshift_mode = true; + command_mode = 0; + in_leader_mode = false; + leader_ind = 0; + dynamic_macro_mode = false; + a_key_went_through = false; + + for (int i = 0; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + dynamic_macro_buffer[i] = 0; + } + } +}
\ No newline at end of file diff --git a/users/dennytom/chording_engine/keymap_def.schema.json b/users/dennytom/chording_engine/keymap_def.schema.json new file mode 100644 index 0000000000..9f9a8c5cbc --- /dev/null +++ b/users/dennytom/chording_engine/keymap_def.schema.json @@ -0,0 +1,337 @@ +{ + "definitions": {}, + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "title": "The Keymap definition", + "required": [ + "keys", + "parameters", + "layers", + "chord_sets", + "pseudolayers", + "leader_sequences", + "extra_code", + "extra_dependencies" + ], + "properties": { + "keys": { + "type": "array", + "title": "The Internal Keycodes", + "description": "Name Keycodes for the Chording Engine. These can be any string except already valid QMK keycodes.", + "items": { + "type": "string", + "title": "Individual Keycode", + "examples": [ + "L1", + "R1", + "TOP1", + "THUMB_3", + "Bottom_6" + ] + } + }, + "parameters": { + "type": "object", + "title": "Keyboard Parameters", + "description": "Keyboard, user and layout specific parameters like timers, max length for buffers and default pseudolayer.", + "required": [ + "layout_function_name", + "chord_timeout", + "dance_timeout", + "leader_timeout", + "tap_timeout", + "command_max_length", + "leader_max_length", + "dynamic_macro_max_length", + "string_max_length", + "long_press_multiplier", + "default_pseudolayer" + ], + "properties": { + "layout_function_name": { + "type": "string", + "examples": [ + "LAYOUT_ginny", + "" + ] + }, + "chord_timeout": { + "type": "integer", + "title": "The Chord Timeout", + "description": "The time in ms you have to press additional keys before the engine assumes you finished pressing keys that are part of a chord.", + "default": 100 + }, + "dance_timeout": { + "type": "integer", + "title": "The Dance Timeout", + "description": "The time in ms you have to repeatedly activate a chord before the engine assumes you finished a dance.", + "default": 200 + }, + "leader_timeout": { + "type": "integer", + "title": "The Leader Timeout", + "description": "The time in ms you have to activate additional chords before the engine assumes you finished adding chords to a leader sequence.", + "default": 750 + }, + "tap_timeout": { + "type": "integer", + "title": "The Tap Timeout", + "description": "The time in ms you have to finish pressing a chord before the engine assumes that you didn't just tap it but are holding it down.", + "default": 50 + }, + "command_max_length": { + "type": "integer", + "title": "Command Max Length", + "description": "The maximum length for chords buffered in command mode.", + "default": 5 + }, + "leader_max_length": { + "type": "integer", + "title": "Leader Max Length", + "description": "The maximum length of leader sequences you can define in your keymap", + "default": 5 + }, + "dynamic_macro_max_length": { + "type": "integer", + "title": "Dynamic Macro Max Length", + "description": "The maximum number of chords (including Dynamic Macro Next) you can record to a Dynamic Macro", + "default": 20 + }, + "string_max_length": { + "type": "integer", + "title": "String Max Length", + "description": "The maximum length of a string that the STR() chord can accept.", + "default": 16 + }, + "long_press_multiplier": { + "type": "integer", + "title": "Long Press Multiplier", + "description": "How many times does the chord timer have expire before a chord is registered as not only held but in a long press (for example for Autoshift). Has to be integer.", + "default": 3 + }, + "default_pseudolayer": { + "type": "string", + "title": "Default Pseudolayer", + "description": "Which pseudolayer should be active when the keyboard starts / restarts.", + "examples": [ + "BASE", + "QWERTY" + ] + } + } + }, + "layers": { + "type": "array", + "title": "QMK Layers", + "description": "The layers QMK needs to know about. Can contain chording engine's internal keycodes or QMK's keycodes. Do not define chords here, those belong in pseudolayers.", + "minItems": 1, + "uniqueItems": false, + "items": { + "type": "object", + "title": "Individual Layers", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "title": "Type of Individual Layers", + "description": "Auto layer fills all keycodes to be chording engine's internal keycodes, manual let's you place internal and QMK's keycodes however you wish.", + "examples": [ + "auto", + "manual" + ] + }, + "keycodes": { + "type": "array", + "title": "Individual Chord", + "description": "A list of of keys that need to be pressed to activate this chord", + "items": { + "type": "string", + "title": "Individual Keycodes", + "description": "A keycode that is a part of the individual chord. Has to be an internal keycode." + } + } + } + } + }, + "chord_sets": { + "type": "array", + "title": "Chord Sets Definitions", + "description": "Describes predefined sets of chords to ease defining a number of chords in a pseudolayer.", + "items": { + "type": "object", + "required": [ + "name", + "chords" + ], + "properties": { + "name": { + "type": "string", + "title": "Name of the Set", + "examples": [ + "rows", + "asetniop" + ] + }, + "chords": { + "type": "array", + "title": "Chords", + "description": "List of all chords in this set", + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "array", + "title": "Individual Chord", + "description": "A list of of keys that need to be pressed to activate this chord", + "items": { + "type": "string", + "title": "Individual Keycodes", + "description": "A keycode that is a part of the individual chord. Has to be an internal keycode." + } + } + } + } + } + }, + "pseudolayers": { + "type": "array", + "title": "Pseudolayers", + "description": "The pseudolayers holding the chords to be processed by the chording engine.", + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "title": "Name of the Pseudolayer", + "default": null, + "examples": [ + "ALWAYS_ON", + "QWERTY" + ] + }, + "chords": { + "type": "array", + "title": "Chords", + "description": "List of chords belonging on the pseudolayer.", + "items": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "title": "Type of the chord array", + "description": "Defines how this objects describes one or more chords.", + "examples": [ + "visual_array", + "visual", + "simple", + "chord_set" + ] + }, + "keys": { + "type": "array", + "title": "Subset of keys", + "description": "Subset of internal keycodes that will be used when defining the chords. For visual_array type only.", + "examples": [ + "[\"L1\", \"L2\", \"L3\", \"L4\", \"R1\", \"R2\", \"R3\", \"R4\"]" + ], + "items": { + "type": "string" + } + }, + "dictionary": { + "type": "array", + "title": "Dictionary", + "description": "A table. Each row defines in a visual way which keys have to be pressed and what is the desired outcome. For visual_array type only.", + "items": { + "type": "array", + "items": { + "type": "string", + "examples": [ + "[\"X"\, \" "\, \" "\, \"X"\, \"X"\, \" "\, \" "\, \"X"\, \"MO(BASE, NUM)\"] + ] + } + } + }, + "keycode": { + "type": "string", + "title": "Keycode", + "description": "A keycode to be assigned to the chord when it is registered. For simple and visual types only." + }, + "set": { + "type": "string", + "title": "Chord set", + "description": "Name of the chord set to be used. Has to be one already defined in the chord_sets array. For chord_set type only." + }, + "keycodes": { + "type": "array", + "title": "Keycodes", + "description": "List of keycodes to be assigned to each chord when it is registered. For set type only.", + "items": { + "type": "string" + } + }, + "chord": { + "type": "array", + "title": "Chord", + "description": "Array of \"X\"'s and \" \"'s that shows which keys have to be pressed to activate the chord. For visual type only ", + "items": { + "type": "string" + } + } + } + } + } + } + } + }, + "leader_sequences": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "examples": ["fn_L1"] + }, + "function": { + "type": "string", + "description": "C code the sequence should run. Instead of here, can be defined in extra_dependencies or extra_code", + "examples": ["void fn_L1(void) { SEND(KC_LCTL); SEND(KC_LALT); SEND(KC_DEL); }"] + }, + "sequence": { + "type": "array", + "items": { + "type": "string" + }, + "examples": [["KC_Q", "KC_Z"]] + } + } + } + }, + "extra_code": { + "type": "string", + "label": "Extra Code", + "description": "C code to be inserted into the generated keymap", + "examples": ["void fn_L1(void) {\n SEND(KC_LCTL);\n SEND(KC_LALT);\n SEND(KC_DEL);\n}\n"], + "default": "" + }, + "extra_dependencies": { + "type": "array", + "label": "Extra Dependencies", + "description": "List of files to be #include'd in the generated keymap", + "examples": [ + "[\"user_functions.c\"]" + ], + "default": "" + } + } +}
\ No newline at end of file diff --git a/users/dennytom/chording_engine/parser.py b/users/dennytom/chording_engine/parser.py new file mode 100644 index 0000000000..b62cf007e6 --- /dev/null +++ b/users/dennytom/chording_engine/parser.py @@ -0,0 +1,231 @@ +#!/usr/bin/env python3 + +import json +from functools import reduce +from chord import * +import sys + +comma_separator = (lambda x, y: str(x) + ", " + str(y)) +string_sum = (lambda x, y: str(x) + " + " + str(y)) +newline_separator = (lambda x, y: str(x) + "\n" + str(y)) + +def add_includes(data): + output_buffer = "" + if not ("do_not_include_QMK" in data["parameters"] and data["parameters"]["do_not_include_QMK"] == True): + output_buffer += "#include QMK_KEYBOARD_H\n" + if len(data["extra_dependencies"]) > 0: + for dependecy in data["extra_dependencies"]: + output_buffer += '#include "' + dependecy + '"\n' + + return output_buffer + "\n" + +def add_parameters(data): + output_buffer = "" + + number_of_keys = len(data["keys"]) + if number_of_keys <= 8: + hash_type = "uint8_t" + elif number_of_keys <= 16: + hash_type = "uint16_t" + elif number_of_keys <= 32: + hash_type = "uint32_t" + elif number_of_keys <= 64: + hash_type = "uint64_t" + else: + raise Exception("The engine currently supports only up to 64 keys.") + + output_buffer += "#define CHORD_TIMEOUT " + str(data["parameters"]["chord_timeout"]) + "\n" + output_buffer += "#define DANCE_TIMEOUT " + str(data["parameters"]["dance_timeout"]) + "\n" + output_buffer += "#define LEADER_TIMEOUT " + str(data["parameters"]["leader_timeout"]) + "\n" + output_buffer += "#define TAP_TIMEOUT " + str(data["parameters"]["tap_timeout"]) + "\n" + output_buffer += "#define LONG_PRESS_MULTIPLIER " + str(data["parameters"]["long_press_multiplier"]) + "\n" + output_buffer += "#define DYNAMIC_MACRO_MAX_LENGTH " + str(data["parameters"]["dynamic_macro_max_length"]) + "\n" + output_buffer += "#define COMMAND_MAX_LENGTH " + str(data["parameters"]["command_max_length"]) + "\n" + output_buffer += "#define STRING_MAX_LENGTH " + str(data["parameters"]["string_max_length"]) + "\n" + output_buffer += "#define LEADER_MAX_LENGTH " + str(data["parameters"]["leader_max_length"]) + "\n" + output_buffer += "#define HASH_TYPE " + hash_type + "\n" + output_buffer += "#define NUMBER_OF_KEYS " + str(len(data["keys"])) + "\n" + output_buffer += "#define DEFAULT_PSEUDOLAYER " + data["parameters"]["default_pseudolayer"] + "\n" + + return output_buffer + "\n" + +def add_keycodes(data): + output_buffer = "" + + if not len(data["keys"]) == len(set(data["keys"])): + raise Exception("The keys must have unique names") + + for key, counter in zip(data["keys"], range(0, len(data["keys"]))): + output_buffer += "#define H_" + key + " ((HASH_TYPE) 1 << " + str(counter) + ")\n" + output_buffer += "\n" + + output_buffer += "enum internal_keycodes {\n" + output_buffer += " " + data["keys"][0] + " = SAFE_RANGE,\n" + output_buffer += " " + reduce(comma_separator, [key for key in data["keys"][1:]]) + ",\n" + output_buffer += " FIRST_INTERNAL_KEYCODE = " + data["keys"][0] + ",\n" + output_buffer += " LAST_INTERNAL_KEYCODE = " + data["keys"][-1] + "\n" + output_buffer += "};\n" + + return output_buffer + "\n" + +def add_pseudolayers(data): + output_buffer = "" + + if len(data["pseudolayers"]) == 0: + raise Exception("You didn't define any pseudolayers") + + if not len([pseudolayer["name"] for pseudolayer in data["pseudolayers"]]) == len(set([pseudolayer["name"] for pseudolayer in data["pseudolayers"]])): + raise Exception("The pseudolayers must have unique names") + + pseudolayers = data["pseudolayers"] + if not "ALWAYS_ON" in [layer["name"] for layer in pseudolayers]: + pseudolayers += [{"name": "ALWAYS_ON", "chords": []}] # the engine expects ALWAYS_ON to exist + + output_buffer += "enum pseudolayers {\n" + output_buffer += " " + reduce(comma_separator, [layer["name"] for layer in pseudolayers]) + "\n" + output_buffer += "};\n" + + return output_buffer + "\n" + +def add_layers(data): + output_buffer = "" + + output_buffer += "const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {\n" + for layer, counter in zip(data["layers"], range(0,len(data["layers"]))): + if layer["type"] == "auto": + output_buffer += " [" + str(counter) + "] = " + data["parameters"]["layout_function_name"] + "(" + reduce(comma_separator, [key for key in data["keys"]]) + "),\n" + else: + output_buffer += " [" + str(counter) + "] = " + data["parameters"]["layout_function_name"] + "(" + reduce(comma_separator, [key for key in layer["keycodes"]]) + "),\n" + output_buffer += "};\n" + output_buffer += "size_t keymapsCount = " + str(len(data["layers"])) + ";\n" + + return output_buffer + "\n" + +def prep_buffers(data): + output_buffer = "" + + output_buffer += "uint8_t keycodes_buffer_array[] = {\n" + output_buffer += " " + reduce(comma_separator, ["0"] * len(data["keys"])) + "\n" + output_buffer += "};\n" + output_buffer += "\n" + + output_buffer += "uint8_t command_buffer[] = {\n" + output_buffer += " " + reduce(comma_separator, ["0"] * data["parameters"]["command_max_length"]) + "\n" + output_buffer += "};\n" + output_buffer += "\n" + + output_buffer += "uint16_t leader_buffer[] = {\n" + output_buffer += " " + reduce(comma_separator, ["0"] * data["parameters"]["leader_max_length"]) + "\n" + output_buffer += "};\n" + output_buffer += "\n" + + output_buffer += "uint8_t dynamic_macro_buffer[] = {\n" + output_buffer += " " + reduce(comma_separator, ["0"] * data["parameters"]["dynamic_macro_max_length"]) + "\n" + output_buffer += "};" + + return output_buffer + "\n" + +def parse_keyboard_specifics(data): + keyboard_part_0 = add_includes(data) + keyboard_part_0 += add_keycodes(data) + keyboard_part_0 += add_pseudolayers(data) + keyboard_part_0 += add_parameters(data) + keyboard_part_0 += add_layers(data) + keyboard_part_0 += prep_buffers(data) + + return keyboard_part_0 + '\n' + +def parse_chords(data): + keyboard_part_2 = "" + strings = [] + number_of_strings = 0 + number_of_chords = 0 + + for pseudolayer in data["pseudolayers"]: + name = pseudolayer["name"] + for chord in pseudolayer["chords"]: + if chord["type"] == "chord_set": + keycodes = reduce(comma_separator, [word for word in chord["keycodes"]]) + [keyboard_part_2, number_of_chords, number_of_strings, strings] = add_chord_set(name, keycodes, chord["set"], data, keyboard_part_2, number_of_chords, number_of_strings, strings) + if chord["type"] == "visual_array": + [keyboard_part_2, number_of_chords, number_of_strings, strings] = add_dictionary(name, chord["keys"], chord["dictionary"], keyboard_part_2, number_of_chords, number_of_strings, strings) + if chord["type"] == "visual": + keycodes = reduce(comma_separator, [word for word in chord["chord"]]) + [keyboard_part_2, number_of_chords, number_of_strings, strings] = secret_chord(name, chord["keycode"], keycodes, data, keyboard_part_2, number_of_chords, number_of_strings, strings) + elif chord["type"] == "simple": + keycodes = reduce(string_sum, ["H_" + word for word in chord["chord"]]) + [keyboard_part_2, number_of_chords, number_of_strings, strings] = add_key(name, keycodes, chord["keycode"], keyboard_part_2, number_of_chords, number_of_strings, strings) + keyboard_part_2 += "\n" + + keyboard_part_2 += "const struct Chord* const list_of_chords[] PROGMEM = {\n" + keyboard_part_2 += " " + reduce(comma_separator, ["&chord_" + str(i) for i in range(0, number_of_chords)]) + "\n" + keyboard_part_2 += "};\n" + keyboard_part_2 += "\n" + + if len(data["leader_sequences"]) > 0: + keyboard_part_2 += reduce(newline_separator, [sequence["function"] for sequence in data["leader_sequences"]]) + "\n\n" + keyboard_part_2 += "const uint16_t leader_triggers[][LEADER_MAX_LENGTH] PROGMEM = {\n" + for sequence in data["leader_sequences"]: + keyboard_part_2 += " {" + reduce(comma_separator, sequence["sequence"] + ["0"] * (data["parameters"]["leader_max_length"] - len(sequence["sequence"]))) + "},\n" + keyboard_part_2 += "};\n\n" + keyboard_part_2 += "void (*leader_functions[]) (void) = {\n" + keyboard_part_2 += " " + reduce(comma_separator, ["&" + sequence["name"] for sequence in data["leader_sequences"]]) + "\n" + keyboard_part_2 += "};\n" + else: + keyboard_part_2 += "const uint16_t** const leader_triggers PROGMEM = NULL;\n" + keyboard_part_2 += "void (*leader_functions[]) (void) = {};\n" + keyboard_part_2 += "\n" + + keyboard_part_2 += "#define NUMBER_OF_CHORDS " + str(number_of_chords) + "\n" + keyboard_part_2 += "#define NUMBER_OF_LEADER_COMBOS " + str(len(data["leader_sequences"])) + + return keyboard_part_2 + "\n\n" + +def parse_strings_for_chords(data): + keyboard_part_1 = "" + + for string, i in zip(strings, range(0, len(strings))): + keyboard_part_1 += "const char string_" + str(i) + " [] PROGMEM = \"" + string + "\";\n" + + keyboard_part_1 += "\n" + keyboard_part_1 += "const char * const strings[] PROGMEM = {\n" + if len(strings) > 0: + keyboard_part_1 += " " + reduce(comma_separator, ["string_" + str(i) for i in range(0, len(strings))]) + keyboard_part_1 += "\n};\n" + + return keyboard_part_1 + +def main(): + if len(sys.argv) != 3: + raise Exception("Wrong number of arguments.\n\nUsage: python parser.py keymap.json keymap.c") + + input_filepath = sys.argv[1] + output_filepath = sys.argv[2] + + with open(input_filepath, "r") as read_file: + data = json.load(read_file) + + keyboard_part_0 = parse_keyboard_specifics(data) + keyboard_part_1 = parse_strings_for_chords(data) + keyboard_part_2 = parse_chords(data) + + engine_part_1 = open("engine.part.1", "r").read() + engine_part_2 = open("engine.part.2", "r").read() + "\n" + engine_part_3 = open("engine.part.3", "r").read() + + output_buffer = keyboard_part_0 + output_buffer += engine_part_1 + + if len(data["extra_code"]) > 0: + output_buffer += data["extra_code"] + "\n" + + output_buffer += keyboard_part_1 + output_buffer += engine_part_2 + output_buffer += keyboard_part_2 + output_buffer += engine_part_3 + + with open(output_filepath, "w") as write_file: + write_file.write(output_buffer) + +if __name__ == "__main__": + main()
\ No newline at end of file diff --git a/users/dennytom/chording_engine/state_machine.dot b/users/dennytom/chording_engine/state_machine.dot new file mode 100644 index 0000000000..431e6f69b6 --- /dev/null +++ b/users/dennytom/chording_engine/state_machine.dot @@ -0,0 +1,49 @@ +digraph { + IDLE + READY + ACTIVATED + DEACTIVATED + PRESS_FROM_ACTIVE + FINISHED_FROM_ACTIVE + IDLE_IN_DANCE + READY_IN_DANCE + FINISHED + LOCKED + READY_LOCKED + RESTART + IN_ONE_SHOT + + // common + FINISHED -> RESTART; + RESTART -> IDLE; + DEACTIVATED -> IDLE_IN_DANCE; + + // kill_one_shots() + IN_ONE_SHOT -> RESTART [label="non-one-shot key went through", color="blue"]; + + // process_finished_dances() + ACTIVATED -> PRESS_FROM_ACTIVE [label="dance timer", color="green"]; + IDLE_IN_DANCE -> FINISHED [label="dance timer", color="green"]; + PRESS_FROM_ACTIVE -> FINISHED_FROM_ACTIVE [label="dance timer", color="green"]; + + // remove_subchords() + READY -> IDLE [label="superchord active", color="red"]; + READY_IN_DANCE -> IDLE_IN_DANCE [label="superchord active", color="red"]; + READY_LOCKED -> LOCKED [label="superchord active", color="red"]; + + // process_ready_chords() + LOCKED -> READY_LOCKED [label="all keys pressed", color="orange"]; + IDLE -> READY [label="all keys pressed", color="orange"]; + IDLE_IN_DANCE -> READY_IN_DANCE [label="all keys pressed", color="orange"]; + + READY_LOCKED -> RESTART [label="chord timer", color="orange"]; + READY -> ACTIVATED [label="chord timer", color="orange"]; + READY_IN_DANCE -> ACTIVATED [label="chord timer", color="orange"]; + ACTIVATED -> PRESS_FROM_ACTIVE [label="lock next", color="orange"]; + PRESS_FROM_ACTIVE -> LOCKED [label="lock next", color="orange"]; + + // deactivate_active_chords() + ACTIVATED -> DEACTIVATED [label="a key lifted", color="purple"]; + PRESS_FROM_ACTIVE -> RESTART [label="a key lifted", color="orange"]; + FINISHED_FROM_ACTIVE -> DEACTIVATED [label="a key lifted", color="orange"]; +}
\ No newline at end of file diff --git a/users/dennytom/chording_engine/state_machine.svg b/users/dennytom/chording_engine/state_machine.svg new file mode 100644 index 0000000000..7731689883 --- /dev/null +++ b/users/dennytom/chording_engine/state_machine.svg @@ -0,0 +1,235 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" + "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<!-- Generated by graphviz version 2.40.1 (20161225.0304) + --> +<!-- Title: %0 Pages: 1 --> +<svg width="829pt" height="754pt" + viewBox="0.00 0.00 829.35 754.40" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> +<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 750.4)"> +<title>%0</title> +<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-750.4 825.3486,-750.4 825.3486,4 -4,4"/> +<!-- IDLE --> +<g id="node1" class="node"> +<title>IDLE</title> +<ellipse fill="none" stroke="#000000" cx="492" cy="-728.4" rx="33.043" ry="18"/> +<text text-anchor="middle" x="492" y="-724.2" font-family="Times,serif" font-size="14.00" fill="#000000">IDLE</text> +</g> +<!-- READY --> +<g id="node2" class="node"> +<title>READY</title> +<ellipse fill="none" stroke="#000000" cx="404" cy="-639.6" rx="44.0814" ry="18"/> +<text text-anchor="middle" x="404" y="-635.4" font-family="Times,serif" font-size="14.00" fill="#000000">READY</text> +</g> +<!-- IDLE->READY --> +<g id="edge12" class="edge"> +<title>IDLE->READY</title> +<path fill="none" stroke="#ffa500" d="M487.6897,-710.0931C484.347,-699.0742 478.772,-685.3407 470,-675.6 463.1872,-668.0349 454.3989,-661.7377 445.4714,-656.6382"/> +<polygon fill="#ffa500" stroke="#ffa500" points="447.0426,-653.5099 436.5654,-651.9352 443.7738,-659.6998 447.0426,-653.5099"/> +<text text-anchor="middle" x="524.317" y="-679.8" font-family="Times,serif" font-size="14.00" fill="#000000">all keys pressed</text> +</g> +<!-- READY->IDLE --> +<g id="edge8" class="edge"> +<title>READY->IDLE</title> +<path fill="none" stroke="#ff0000" d="M383.1899,-655.7528C371.9777,-666.4401 362.0803,-680.6044 370.88,-692.4 380.5143,-705.3144 418.9714,-715.2612 450.0017,-721.3939"/> +<polygon fill="#ff0000" stroke="#ff0000" points="449.7109,-724.9011 460.188,-723.3263 451.0156,-718.0238 449.7109,-724.9011"/> +<text text-anchor="middle" x="420.56" y="-679.8" font-family="Times,serif" font-size="14.00" fill="#000000">superchord active</text> +</g> +<!-- ACTIVATED --> +<g id="node3" class="node"> +<title>ACTIVATED</title> +<ellipse fill="none" stroke="#000000" cx="404" cy="-550.8" rx="66.0512" ry="18"/> +<text text-anchor="middle" x="404" y="-546.6" font-family="Times,serif" font-size="14.00" fill="#000000">ACTIVATED</text> +</g> +<!-- READY->ACTIVATED --> +<g id="edge15" class="edge"> +<title>READY->ACTIVATED</title> +<path fill="none" stroke="#ffa500" d="M404,-621.2006C404,-609.0949 404,-593.0076 404,-579.2674"/> +<polygon fill="#ffa500" stroke="#ffa500" points="407.5001,-578.872 404,-568.872 400.5001,-578.8721 407.5001,-578.872"/> +<text text-anchor="middle" x="436.4611" y="-591" font-family="Times,serif" font-size="14.00" fill="#000000">chord timer</text> +</g> +<!-- DEACTIVATED --> +<g id="node4" class="node"> +<title>DEACTIVATED</title> +<ellipse fill="none" stroke="#000000" cx="301" cy="-284.4" rx="79.2922" ry="18"/> +<text text-anchor="middle" x="301" y="-280.2" font-family="Times,serif" font-size="14.00" fill="#000000">DEACTIVATED</text> +</g> +<!-- ACTIVATED->DEACTIVATED --> +<g id="edge19" class="edge"> +<title>ACTIVATED->DEACTIVATED</title> +<path fill="none" stroke="#a020f0" d="M414.457,-532.6765C417.1337,-527.1214 419.6389,-520.8699 421,-514.8 426.1765,-491.7151 456.5634,-425.2497 416,-355.2 402.3607,-331.646 377.4429,-314.8951 354.2805,-303.6207"/> +<polygon fill="#a020f0" stroke="#a020f0" points="355.7259,-300.433 345.1798,-299.4173 352.7907,-306.7879 355.7259,-300.433"/> +<text text-anchor="middle" x="468.4881" y="-413.4" font-family="Times,serif" font-size="14.00" fill="#000000">a key lifted</text> +</g> +<!-- PRESS_FROM_ACTIVE --> +<g id="node5" class="node"> +<title>PRESS_FROM_ACTIVE</title> +<ellipse fill="none" stroke="#000000" cx="279" cy="-462" rx="111.797" ry="18"/> +<text text-anchor="middle" x="279" y="-457.8" font-family="Times,serif" font-size="14.00" fill="#000000">PRESS_FROM_ACTIVE</text> +</g> +<!-- ACTIVATED->PRESS_FROM_ACTIVE --> +<g id="edge5" class="edge"> +<title>ACTIVATED->PRESS_FROM_ACTIVE</title> +<path fill="none" stroke="#00ff00" d="M381.0189,-533.8085C363.6663,-521.0049 341.3076,-504.5706 332,-498 326.1999,-493.9054 319.9973,-489.6147 313.9535,-485.4802"/> +<polygon fill="#00ff00" stroke="#00ff00" points="315.5139,-482.3085 305.2776,-479.5755 311.5753,-488.0954 315.5139,-482.3085"/> +<text text-anchor="middle" x="387.8454" y="-502.2" font-family="Times,serif" font-size="14.00" fill="#000000">dance timer</text> +</g> +<!-- ACTIVATED->PRESS_FROM_ACTIVE --> +<g id="edge17" class="edge"> +<title>ACTIVATED->PRESS_FROM_ACTIVE</title> +<path fill="none" stroke="#ffa500" d="M346.8191,-541.6158C317.1162,-535.5544 285.1886,-526.5544 276.2896,-514.8 271.0903,-507.9325 270.0671,-499.0047 270.857,-490.45"/> +<polygon fill="#ffa500" stroke="#ffa500" points="274.3462,-490.8071 272.5608,-480.3638 267.444,-489.6411 274.3462,-490.8071"/> +<text text-anchor="middle" x="302.8552" y="-502.2" font-family="Times,serif" font-size="14.00" fill="#000000">lock next</text> +</g> +<!-- IDLE_IN_DANCE --> +<g id="node7" class="node"> +<title>IDLE_IN_DANCE</title> +<ellipse fill="none" stroke="#000000" cx="293" cy="-195.6" rx="86.2367" ry="18"/> +<text text-anchor="middle" x="293" y="-191.4" font-family="Times,serif" font-size="14.00" fill="#000000">IDLE_IN_DANCE</text> +</g> +<!-- DEACTIVATED->IDLE_IN_DANCE --> +<g id="edge3" class="edge"> +<title>DEACTIVATED->IDLE_IN_DANCE</title> +<path fill="none" stroke="#000000" d="M299.3424,-266.0006C298.241,-253.775 296.7738,-237.4887 295.5279,-223.6599"/> +<polygon fill="#000000" stroke="#000000" points="299.0114,-223.3176 294.6281,-213.672 292.0396,-223.9458 299.0114,-223.3176"/> +</g> +<!-- FINISHED_FROM_ACTIVE --> +<g id="node6" class="node"> +<title>FINISHED_FROM_ACTIVE</title> +<ellipse fill="none" stroke="#000000" cx="280" cy="-373.2" rx="127.3672" ry="18"/> +<text text-anchor="middle" x="280" y="-369" font-family="Times,serif" font-size="14.00" fill="#000000">FINISHED_FROM_ACTIVE</text> +</g> +<!-- PRESS_FROM_ACTIVE->FINISHED_FROM_ACTIVE --> +<g id="edge7" class="edge"> +<title>PRESS_FROM_ACTIVE->FINISHED_FROM_ACTIVE</title> +<path fill="none" stroke="#00ff00" d="M279.2072,-443.6006C279.3435,-431.4949 279.5247,-415.4076 279.6794,-401.6674"/> +<polygon fill="#00ff00" stroke="#00ff00" points="283.1836,-401.3108 279.7965,-391.272 276.184,-401.2319 283.1836,-401.3108"/> +<text text-anchor="middle" x="312.8454" y="-413.4" font-family="Times,serif" font-size="14.00" fill="#000000">dance timer</text> +</g> +<!-- LOCKED --> +<g id="node10" class="node"> +<title>LOCKED</title> +<ellipse fill="none" stroke="#000000" cx="84" cy="-373.2" rx="50.38" ry="18"/> +<text text-anchor="middle" x="84" y="-369" font-family="Times,serif" font-size="14.00" fill="#000000">LOCKED</text> +</g> +<!-- PRESS_FROM_ACTIVE->LOCKED --> +<g id="edge18" class="edge"> +<title>PRESS_FROM_ACTIVE->LOCKED</title> +<path fill="none" stroke="#ffa500" d="M241.402,-444.8785C207.8161,-429.584 158.7472,-407.2387 124.3482,-391.574"/> +<polygon fill="#ffa500" stroke="#ffa500" points="125.6113,-388.3034 115.06,-387.3442 122.7102,-394.6739 125.6113,-388.3034"/> +<text text-anchor="middle" x="224.8552" y="-413.4" font-family="Times,serif" font-size="14.00" fill="#000000">lock next</text> +</g> +<!-- RESTART --> +<g id="node12" class="node"> +<title>RESTART</title> +<ellipse fill="none" stroke="#000000" cx="201" cy="-18" rx="53.9098" ry="18"/> +<text text-anchor="middle" x="201" y="-13.8" font-family="Times,serif" font-size="14.00" fill="#000000">RESTART</text> +</g> +<!-- PRESS_FROM_ACTIVE->RESTART --> +<g id="edge20" class="edge"> +<title>PRESS_FROM_ACTIVE->RESTART</title> +<path fill="none" stroke="#ffa500" d="M190.3393,-450.9993C108.6441,-438.3099 0,-413.8018 0,-373.2 0,-373.2 0,-373.2 0,-106.8 0,-74.7037 86.8374,-46.4364 146.3579,-30.8311"/> +<polygon fill="#ffa500" stroke="#ffa500" points="147.578,-34.1313 156.3916,-28.2515 145.835,-27.3517 147.578,-34.1313"/> +<text text-anchor="middle" x="31.4881" y="-235.8" font-family="Times,serif" font-size="14.00" fill="#000000">a key lifted</text> +</g> +<!-- FINISHED_FROM_ACTIVE->DEACTIVATED --> +<g id="edge21" class="edge"> +<title>FINISHED_FROM_ACTIVE->DEACTIVATED</title> +<path fill="none" stroke="#ffa500" d="M284.3512,-354.8006C287.2424,-342.575 291.0939,-326.2887 294.3642,-312.4599"/> +<polygon fill="#ffa500" stroke="#ffa500" points="297.8308,-313.0091 296.7262,-302.472 291.0187,-311.3981 297.8308,-313.0091"/> +<text text-anchor="middle" x="324.4881" y="-324.6" font-family="Times,serif" font-size="14.00" fill="#000000">a key lifted</text> +</g> +<!-- READY_IN_DANCE --> +<g id="node8" class="node"> +<title>READY_IN_DANCE</title> +<ellipse fill="none" stroke="#000000" cx="402" cy="-106.8" rx="97.2741" ry="18"/> +<text text-anchor="middle" x="402" y="-102.6" font-family="Times,serif" font-size="14.00" fill="#000000">READY_IN_DANCE</text> +</g> +<!-- IDLE_IN_DANCE->READY_IN_DANCE --> +<g id="edge13" class="edge"> +<title>IDLE_IN_DANCE->READY_IN_DANCE</title> +<path fill="none" stroke="#ffa500" d="M285.2465,-177.3414C281.8879,-166.3406 280.1649,-152.6093 287.366,-142.8 292.9374,-135.2107 308.8319,-128.4976 327.077,-122.9864"/> +<polygon fill="#ffa500" stroke="#ffa500" points="328.1338,-126.3246 336.79,-120.2157 326.2135,-119.5932 328.1338,-126.3246"/> +<text text-anchor="middle" x="332.317" y="-147" font-family="Times,serif" font-size="14.00" fill="#000000">all keys pressed</text> +</g> +<!-- FINISHED --> +<g id="node9" class="node"> +<title>FINISHED</title> +<ellipse fill="none" stroke="#000000" cx="201" cy="-106.8" rx="55.0323" ry="18"/> +<text text-anchor="middle" x="201" y="-102.6" font-family="Times,serif" font-size="14.00" fill="#000000">FINISHED</text> +</g> +<!-- IDLE_IN_DANCE->FINISHED --> +<g id="edge6" class="edge"> +<title>IDLE_IN_DANCE->FINISHED</title> +<path fill="none" stroke="#00ff00" d="M231.9976,-182.6889C220.3684,-177.4272 209.5756,-170.022 202.3092,-159.6 197.3878,-152.5413 195.8986,-143.5625 195.9866,-135.0199"/> +<polygon fill="#00ff00" stroke="#00ff00" points="199.4821,-135.2114 196.7515,-124.9745 192.5023,-134.6799 199.4821,-135.2114"/> +<text text-anchor="middle" x="235.8454" y="-147" font-family="Times,serif" font-size="14.00" fill="#000000">dance timer</text> +</g> +<!-- READY_IN_DANCE->ACTIVATED --> +<g id="edge16" class="edge"> +<title>READY_IN_DANCE->ACTIVATED</title> +<path fill="none" stroke="#ffa500" d="M460.9306,-121.2262C473.3432,-126.4214 485.5301,-133.4169 495,-142.8 512.9398,-160.5753 516,-170.3454 516,-195.6 516,-462 516,-462 516,-462 516,-495.4749 484.8997,-518.3284 455.476,-532.4591"/> +<polygon fill="#ffa500" stroke="#ffa500" points="453.6869,-529.4272 446.0233,-536.7429 456.5764,-535.803 453.6869,-529.4272"/> +<text text-anchor="middle" x="548.4611" y="-324.6" font-family="Times,serif" font-size="14.00" fill="#000000">chord timer</text> +</g> +<!-- READY_IN_DANCE->IDLE_IN_DANCE --> +<g id="edge9" class="edge"> +<title>READY_IN_DANCE->IDLE_IN_DANCE</title> +<path fill="none" stroke="#ff0000" d="M398.1917,-124.942C395.0071,-136.1761 389.421,-150.2021 380,-159.6 372.9696,-166.6132 364.3766,-172.3251 355.3586,-176.9585"/> +<polygon fill="#ff0000" stroke="#ff0000" points="353.8046,-173.8215 346.241,-181.2406 356.7803,-180.1575 353.8046,-173.8215"/> +<text text-anchor="middle" x="441.56" y="-147" font-family="Times,serif" font-size="14.00" fill="#000000">superchord active</text> +</g> +<!-- FINISHED->RESTART --> +<g id="edge1" class="edge"> +<title>FINISHED->RESTART</title> +<path fill="none" stroke="#000000" d="M201,-88.4006C201,-76.2949 201,-60.2076 201,-46.4674"/> +<polygon fill="#000000" stroke="#000000" points="204.5001,-46.072 201,-36.072 197.5001,-46.0721 204.5001,-46.072"/> +</g> +<!-- READY_LOCKED --> +<g id="node11" class="node"> +<title>READY_LOCKED</title> +<ellipse fill="none" stroke="#000000" cx="116" cy="-284.4" rx="88.0442" ry="18"/> +<text text-anchor="middle" x="116" y="-280.2" font-family="Times,serif" font-size="14.00" fill="#000000">READY_LOCKED</text> +</g> +<!-- LOCKED->READY_LOCKED --> +<g id="edge11" class="edge"> +<title>LOCKED->READY_LOCKED</title> +<path fill="none" stroke="#ffa500" d="M62.8266,-356.7262C52.2277,-346.3972 43.0571,-332.745 50.366,-320.4 53.6683,-314.8223 58.175,-310.0516 63.2916,-305.985"/> +<polygon fill="#ffa500" stroke="#ffa500" points="65.4987,-308.7148 71.7485,-300.1596 61.5278,-302.9501 65.4987,-308.7148"/> +<text text-anchor="middle" x="95.317" y="-324.6" font-family="Times,serif" font-size="14.00" fill="#000000">all keys pressed</text> +</g> +<!-- READY_LOCKED->LOCKED --> +<g id="edge10" class="edge"> +<title>READY_LOCKED->LOCKED</title> +<path fill="none" stroke="#ff0000" d="M134.3377,-302.181C142.7003,-312.508 149.4503,-325.708 143,-337.2 139.1182,-344.1159 133.3081,-349.8603 126.8241,-354.5772"/> +<polygon fill="#ff0000" stroke="#ff0000" points="124.8745,-351.6695 118.3451,-360.0132 128.6526,-357.5624 124.8745,-351.6695"/> +<text text-anchor="middle" x="195.56" y="-324.6" font-family="Times,serif" font-size="14.00" fill="#000000">superchord active</text> +</g> +<!-- READY_LOCKED->RESTART --> +<g id="edge14" class="edge"> +<title>READY_LOCKED->RESTART</title> +<path fill="none" stroke="#ffa500" d="M114.0574,-266.3175C111.0132,-230.457 108.1435,-148.6335 137,-88.8 145.6041,-70.9596 160.1275,-54.343 173.1661,-41.6972"/> +<polygon fill="#ffa500" stroke="#ffa500" points="175.702,-44.1178 180.6155,-34.7312 170.9209,-39.0049 175.702,-44.1178"/> +<text text-anchor="middle" x="152.4611" y="-147" font-family="Times,serif" font-size="14.00" fill="#000000">chord timer</text> +</g> +<!-- RESTART->IDLE --> +<g id="edge2" class="edge"> +<title>RESTART->IDLE</title> +<path fill="none" stroke="#000000" d="M251.8307,-24.1482C358.5139,-37.7418 596,-71.9196 596,-106.8 596,-639.6 596,-639.6 596,-639.6 596,-665.1965 591.0323,-674.2337 573,-692.4 561.7252,-703.7586 546.243,-711.8298 531.8327,-717.4099"/> +<polygon fill="#000000" stroke="#000000" points="530.3349,-714.2281 522.0925,-720.8849 532.6871,-720.8211 530.3349,-714.2281"/> +</g> +<!-- IN_ONE_SHOT --> +<g id="node13" class="node"> +<title>IN_ONE_SHOT</title> +<ellipse fill="none" stroke="#000000" cx="700" cy="-106.8" rx="75.8643" ry="18"/> +<text text-anchor="middle" x="700" y="-102.6" font-family="Times,serif" font-size="14.00" fill="#000000">IN_ONE_SHOT</text> +</g> +<!-- IN_ONE_SHOT->RESTART --> +<g id="edge4" class="edge"> +<title>IN_ONE_SHOT->RESTART</title> +<path fill="none" stroke="#0000ff" d="M676.9312,-89.3704C659.5151,-77.2164 634.5042,-61.8271 610,-54 547.5343,-34.0473 363.5933,-24.1795 265.053,-20.2067"/> +<polygon fill="#0000ff" stroke="#0000ff" points="265.0515,-16.704 254.9213,-19.8069 264.7755,-23.6986 265.0515,-16.704"/> +<text text-anchor="middle" x="733.6743" y="-58.2" font-family="Times,serif" font-size="14.00" fill="#000000">non-one-shot key went through</text> +</g> +</g> +</svg> diff --git a/users/dennytom/chording_engine/tests/minunit.h b/users/dennytom/chording_engine/tests/minunit.h new file mode 100644 index 0000000000..ed71b62533 --- /dev/null +++ b/users/dennytom/chording_engine/tests/minunit.h @@ -0,0 +1,288 @@ +#define mu_assert(message, test) \ + do { \ + if (!(test)) { \ + return message; \ + } \ + } while (0) + +#define RED "\033[0;31m" +#define GREEN "\033[0;32m" +#define NC "\033[0m" + +enum ASSERT_TYPES { + UINT, + INT +}; + +#define BUFF_SIZE 1024 +char buffer[BUFF_SIZE]; + +#define ASSERT_EQ(type, actual, expected) \ + do { \ + if (actual != expected) { \ + switch (type) { \ + case UINT: \ + snprintf(buffer, BUFF_SIZE, "\nline %d\nvar %s\nactual = %u\nexpected = %u\n", __LINE__, #actual, actual, expected); \ + break; \ + case INT: \ + snprintf(buffer, BUFF_SIZE, "\nline %d\nvar %s\nactual = %d\nexpected = %d\n", __LINE__, #actual, actual, expected); \ + break; \ + default: \ + snprintf(buffer, BUFF_SIZE, "\nline %d\nunsupported ASSERT_EQ type\n", __LINE__); \ + break; \ + } \ + printf("%s\n", buffer); \ + passed = false; \ + all_passed = false; \ + } \ + } while (0) + +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <string.h> + +#define MATRIX_ROWS 2 +#define MATRIX_COLS 10 +#define LAYOUT_test( \ + k09, k08, k07, k06, k05, k04, k03, k02, k01, k00, \ + k19, k18, k17, k16, k15, k14, k13, k12, k11, k10 \ +) { \ + { k00, k01, k02, k03, k04, k05, k06, k07, k08, k09}, \ + { k10, k11, k12, k13, k14, k15, k16, k17, k18, k19}, \ +} + +#define PROGMEM +#define memcpy_P memcpy +const struct Chord* pgm_read_word(const struct Chord* const* chord) {return *chord;} + +typedef struct { + uint8_t col; + uint8_t row; +} keypos_t; + +typedef struct { + keypos_t key; + bool pressed; + uint16_t time; +} keyevent_t; + +typedef struct { + bool interrupted :1; + bool reserved2 :1; + bool reserved1 :1; + bool reserved0 :1; + uint8_t count :4; +} tap_t; + +typedef struct { + keyevent_t event; + tap_t tap; +} keyrecord_t; + +keyrecord_t pressed = {{{0,0},true,0}, {0,0,0,0,0}}; +keyrecord_t depressed = {{{0,0},false,0}, {0,0,0,0,0}}; + +enum keycodes { + KC_NO, + KC_TILDE, + KC_GRAVE, + KC_EXCLAIM, + KC_1, + KC_AT, + KC_2, + KC_HASH, + KC_3, + KC_DOLLAR, + KC_4, + KC_PERCENT, + KC_5, + KC_CIRCUMFLEX, + KC_6, + KC_AMPERSAND, + KC_7, + KC_ASTERISK, + KC_8, + KC_LEFT_PAREN, + KC_9, + KC_RIGHT_PAREN, + KC_0, + KC_UNDERSCORE, + KC_MINUS, + KC_PLUS, + KC_EQUAL, + KC_LEFT_CURLY_BRACE, + KC_LBRACKET, + KC_RIGHT_CURLY_BRACE, + KC_RBRACKET, + KC_PIPE, + KC_BSLASH, + KC_COLON, + KC_SCOLON, + KC_DOUBLE_QUOTE, + KC_QUOTE, + KC_LEFT_ANGLE_BRACKET, + KC_COMMA, + KC_RIGHT_ANGLE_BRACKET, + KC_DOT, + KC_QUESTION, + KC_SLASH, + KC_Q, + KC_W, + KC_E, + KC_R, + KC_T, + KC_Y, + KC_U, + KC_I, + KC_O, + KC_P, + KC_A, + KC_S, + KC_D, + KC_F, + KC_G, + KC_H, + KC_J, + KC_K, + KC_L, + KC_Z, + KC_X, + KC_C, + KC_V, + KC_B, + KC_N, + KC_M, + KC_ESC, + KC_LSFT, + KC_LCTL, + KC_LGUI, + KC_LALT, + KC_RALT, + KC_RCTL, + KC_RGUI, + KC_RSFT, + KC_TAB, + KC_DEL, + KC_INS, + KC_BSPC, + KC_ENTER, + KC_SPACE, + KC_F1, + KC_F2, + KC_F3, + KC_F4, + KC_F5, + KC_F6, + KC_F7, + KC_F8, + KC_F9, + KC_F10, + KC_F11, + KC_F12, + KC_LEFT, + KC_DOWN, + KC_UP, + KC_RIGHT, + + SAFE_RANGE +}; + +#define HISTORY 20 + +int16_t current_time; +uint8_t keyboard_history[HISTORY][SAFE_RANGE-1]; +int16_t time_history[HISTORY]; +uint8_t history_index; + +void register_code(int16_t keycode) { + history_index++; + for (int j = 0; j < SAFE_RANGE-1; j++) { + keyboard_history[history_index][j] = keyboard_history[history_index-1][j]; + } + keyboard_history[history_index][keycode] = 1; + time_history[history_index] = current_time; +}; +void unregister_code(int16_t keycode) { + history_index++; + for (int j = 0; j < SAFE_RANGE-1; j++) { + keyboard_history[history_index][j] = keyboard_history[history_index-1][j]; + } + keyboard_history[history_index][keycode] = 0; + time_history[history_index] = current_time; +}; +void send_keyboard_report(void) { /*still don't know what this does*/ }; +void matrix_scan_user (void); +void wait_ms(uint16_t ms) { + current_time += ms; +}; +uint16_t timer_read(void) { + uint16_t result = current_time; + return result; +}; +uint16_t timer_elapsed(uint16_t timer) { + uint16_t result = current_time - timer; + return result; +}; +void layer_move(int16_t layer) { /*ignoring for now*/ }; +void clear_keyboard(void) { + history_index++; + for (int j = 0; j < SAFE_RANGE-1; j++) { + keyboard_history[history_index][j] = 0; + } + time_history[history_index] = current_time; +}; +void reset_keyboard(void) { /*ignoring for now*/ }; + +void pause_ms(uint16_t ms) { + for (int i = 0; i < ms; i++) { + current_time++; + matrix_scan_user(); + } +}; + +#define TEST(name) \ + do { \ + printf("%s\n", name); \ + passed = true; \ + do { \ + uint8_t clear_state = ACTIVATED; \ + struct Chord clear_chord PROGMEM = {0, QWERTY, &clear_state, NULL, 0, 0, clear}; \ + clear_chord.function(&clear_chord); \ + } while (0); \ + current_time = 0; \ + history_index = 0; \ + for (int j = 0; j < SAFE_RANGE-1; j++) { \ + keyboard_history[0][j] = 0; \ + } \ + time_history[0] = 0; \ + for (int i = 1; i < HISTORY; i++) { \ + for (int j = 0; j < SAFE_RANGE-1; j++) { \ + keyboard_history[i][j] = -1; \ + } \ + time_history[i] = -1; \ + } + +#define END_TEST \ + if (passed) { \ + printf(GREEN"PASSED"NC"\n"); \ + } else { \ + printf(RED"FAILED"NC"\n"); \ + } \ + } while(0); + +#define MAIN \ +int main(int argc, char **argv) { \ + bool passed = true; \ + bool all_passed = true; + +#define END \ + printf("\n"); \ + if (all_passed) { \ + printf(GREEN"ALL TESTS PASSED"NC"\n"); \ + } else { \ + printf(RED"TESTS FAILED"NC"\n"); \ + } \ + return 1 - all_passed; \ +}
\ No newline at end of file diff --git a/users/dennytom/chording_engine/tests/test.c b/users/dennytom/chording_engine/tests/test.c new file mode 100644 index 0000000000..0cc172f0a8 --- /dev/null +++ b/users/dennytom/chording_engine/tests/test.c @@ -0,0 +1,1259 @@ +#include "minunit.h" +#include "test_keymap.c" + +MAIN + +// CLEAR_KB +TEST("clear") + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + struct Chord* chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + struct Chord chord_storage; + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + struct Chord* chord = &chord_storage; + + *chord->state = READY; + + if (chord->counter) { + *chord->counter = 1; + } + } + + history_index++; + for (int j = 0; j < SAFE_RANGE-1; j++) { + keyboard_history[history_index][j] = 1; + } + + current_pseudolayer = 5; + lock_next = true; + autoshift_mode = false; + command_mode = 1; + in_leader_mode = true; + dynamic_macro_mode = true; + a_key_went_through = true; + + for (int i = 0; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + dynamic_macro_buffer[i] = 1; + } + + uint8_t clear_state = ACTIVATED; + struct Chord clear_chord PROGMEM = {0, QWERTY, &clear_state, NULL, 0, 0, clear}; + clear_chord.function(&clear_chord); + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + struct Chord* chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + struct Chord chord_storage; + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + struct Chord* chord = &chord_storage; + + ASSERT_EQ(UINT, *chord->state, IDLE); + + if (chord->counter) { + ASSERT_EQ(UINT, *chord->counter, 0); + } + } + + for (int j = 0; j < SAFE_RANGE-1; j++) { + ASSERT_EQ(UINT, keyboard_history[history_index][j], 0); + } + + ASSERT_EQ(UINT, current_pseudolayer, 1); + ASSERT_EQ(UINT, lock_next, false); + ASSERT_EQ(UINT, autoshift_mode, true); + ASSERT_EQ(UINT, command_mode, 0); + ASSERT_EQ(UINT, in_leader_mode, false); + ASSERT_EQ(UINT, leader_ind, 0); + ASSERT_EQ(UINT, dynamic_macro_mode, false); + ASSERT_EQ(UINT, a_key_went_through, false); + + for (int i = 0; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + ASSERT_EQ(UINT, dynamic_macro_buffer[i], 0); + } +END_TEST + +TEST("pause_ms") + pause_ms(500); + ASSERT_EQ(UINT, current_time, 500); +END_TEST + +// KC +TEST("single_dance_held_states") + ASSERT_EQ(UINT, state_1, IDLE); + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT); + ASSERT_EQ(UINT, state_1, IDLE); + pause_ms(1); + ASSERT_EQ(UINT, state_1, ACTIVATED); + pause_ms(DANCE_TIMEOUT); + ASSERT_EQ(UINT, state_1, ACTIVATED); + pause_ms(1); + ASSERT_EQ(UINT, state_1, PRESS_FROM_ACTIVE); + pause_ms(DANCE_TIMEOUT); + ASSERT_EQ(UINT, state_1, PRESS_FROM_ACTIVE); + pause_ms(1); + ASSERT_EQ(UINT, state_1, FINISHED_FROM_ACTIVE); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, state_1, IDLE); +END_TEST + +TEST("single_dance_held_codes") + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + pause_ms(1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + pause_ms(DANCE_TIMEOUT); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + pause_ms(1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + pause_ms(DANCE_TIMEOUT); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + pause_ms(1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); +END_TEST + +TEST("single_dance_tapped_states") + ASSERT_EQ(UINT, state_1, IDLE); + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT); + ASSERT_EQ(UINT, state_1, IDLE); + pause_ms(1); + ASSERT_EQ(UINT, state_1, ACTIVATED); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, state_1, IDLE); +END_TEST + +TEST("single_dance_tapped_codes") + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + pause_ms(1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); +END_TEST + +// I can not actually track the states if the tap is faster than chord timeout + +TEST("single_dance_tapped_fast_codes") + ASSERT_EQ(UINT, state_0, IDLE); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, keyboard_history[0][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_Q], 0); +END_TEST + +TEST("subchords_are_ignored") + ASSERT_EQ(UINT, state_0, IDLE); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_W], 0); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_ESC], 1); +END_TEST + +TEST("multiple_chords_at_once") + ASSERT_EQ(UINT, state_0, IDLE); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_E], 1); +END_TEST + +// MO +TEST("momentary_layer") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT7, &pressed); + pause_ms(1); + process_record_user(BOT8, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + process_record_user(BOT7, &depressed); + pause_ms(1); + process_record_user(BOT8, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); +END_TEST + +TEST("momentary_layer_reset") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT7, &pressed); + pause_ms(1); + process_record_user(BOT8, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + pause_ms(DANCE_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + process_record_user(BOT7, &depressed); + pause_ms(1); + process_record_user(BOT8, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); +END_TEST + +TEST("momentary_layer_alt") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + + process_record_user(TOP8, &pressed); + pause_ms(1); + process_record_user(TOP9, &pressed); + pause_ms(1); + process_record_user(TOP0, &pressed); + pause_ms(1); + process_record_user(BOT8, &pressed); + pause_ms(1); + process_record_user(BOT9, &pressed); + pause_ms(1); + process_record_user(BOT0, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + process_record_user(TOP8, &depressed); + pause_ms(1); + process_record_user(TOP9, &depressed); + pause_ms(1); + process_record_user(TOP0, &depressed); + pause_ms(1); + process_record_user(BOT8, &depressed); + pause_ms(1); + process_record_user(BOT9, &depressed); + pause_ms(1); + process_record_user(BOT0, &depressed); + + ASSERT_EQ(UINT, current_pseudolayer, FNC); +END_TEST + +// DF +TEST("permanent_layer") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT9, &pressed); + pause_ms(1); + process_record_user(BOT0, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + process_record_user(BOT9, &depressed); + pause_ms(1); + process_record_user(BOT0, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + pause_ms(1000); + ASSERT_EQ(UINT, current_pseudolayer, NUM); +END_TEST + +// AT +TEST("autoshift_toggle") + ASSERT_EQ(UINT, autoshift_mode, 1); + uint8_t state = ACTIVATED; + struct Chord chord PROGMEM = {0, QWERTY, &state, NULL, 0, 0, autoshift_toggle}; + chord.function(&chord); + ASSERT_EQ(UINT, autoshift_mode, 0); + state = ACTIVATED; + chord.function(&chord); + ASSERT_EQ(UINT, autoshift_mode, 1); +END_TEST + +// AS +TEST("autoshift_tap") + process_record_user(BOT1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(BOT1, &depressed); + + ASSERT_EQ(UINT, keyboard_history[0][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_Z], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[2][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_LSFT], 0); +END_TEST + +TEST("autoshift_hold") + process_record_user(BOT1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(LONG_PRESS_MULTIPLIER * (DANCE_TIMEOUT + 1)); + process_record_user(BOT1, &depressed); + + ASSERT_EQ(UINT, keyboard_history[0][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[2][KC_Z], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[3][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[4][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_LSFT], 0); +END_TEST + +TEST("autoshift_hold_off") + autoshift_mode = 0; + process_record_user(BOT1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(LONG_PRESS_MULTIPLIER * (DANCE_TIMEOUT + 1)); + process_record_user(BOT1, &depressed); + + ASSERT_EQ(UINT, keyboard_history[0][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_Z], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[2][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_LSFT], 0); +END_TEST + +// LOCK +TEST("lock") + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT1, &pressed); + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + process_record_user(BOT1, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + pause_ms(1); + process_record_user(BOT2, &depressed); + pause_ms(1); + process_record_user(TOP1, &pressed); + process_record_user(TOP2, &pressed); + process_record_user(BOT1, &pressed); + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(TOP1, &depressed); + pause_ms(1); + process_record_user(TOP2, &depressed); + process_record_user(BOT1, &depressed); + process_record_user(BOT2, &depressed); + pause_ms(1); + process_record_user(BOT1, &pressed); + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + process_record_user(BOT1, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + pause_ms(1); + process_record_user(BOT2, &depressed); + pause_ms(1000); + process_record_user(BOT1, &pressed); + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT1, &depressed); + pause_ms(1); + process_record_user(BOT2, &depressed); + pause_ms(1000); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); +END_TEST + +// OSK +TEST("one_shot_key_tap") + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT2, &pressed); + process_record_user(BOT3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT2, &depressed); + pause_ms(1); + process_record_user(BOT3, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + pause_ms(1000); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); +END_TEST + +TEST("one_shot_key_hold") + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT2, &pressed); + process_record_user(BOT3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(DANCE_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + + process_record_user(BOT2, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); +END_TEST + +TEST("one_shot_key_retrotapping") + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT2, &pressed); + process_record_user(BOT3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(DANCE_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + + pause_ms(1000); + + process_record_user(BOT2, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); +END_TEST + +// OSL +TEST("one_shot_layer_tap") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT6, &pressed); + process_record_user(BOT7, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT6, &depressed); + pause_ms(1); + process_record_user(BOT7, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + pause_ms(1000); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); +END_TEST + +TEST("one_shot_layer_hold") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT6, &pressed); + process_record_user(BOT7, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(DANCE_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + process_record_user(BOT6, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); +END_TEST + +TEST("one_shot_layer_retrotapping") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT6, &pressed); + process_record_user(BOT7, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(DANCE_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + pause_ms(1000); + + process_record_user(BOT6, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, NUM); +END_TEST + +// CMD +TEST("command_mode") + // start recording + process_record_user(TOP5, &pressed); + process_record_user(TOP6, &pressed); + process_record_user(BOT5, &pressed); + process_record_user(BOT6, &pressed); + pause_ms(1); + process_record_user(TOP5, &depressed); + process_record_user(TOP6, &depressed); + process_record_user(BOT5, &depressed); + process_record_user(BOT6, &depressed); + + ASSERT_EQ(UINT, command_mode, 1); + + // record shift+q + process_record_user(BOT1, &pressed); + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT1, &depressed); + process_record_user(BOT2, &depressed); + pause_ms(1000); + + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(TOP1, &depressed); + pause_ms(1000); + + + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + // execute + process_record_user(TOP5, &pressed); + process_record_user(TOP6, &pressed); + process_record_user(BOT5, &pressed); + process_record_user(BOT6, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + + ASSERT_EQ(UINT, command_mode, 0); + + // test history + ASSERT_EQ(UINT, keyboard_history[0][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[2][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[3][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[3][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[4][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[5][KC_Q], 255); + ASSERT_EQ(UINT, keyboard_history[5][KC_LSFT], 255); +END_TEST + +// KK +TEST("key_key_dance_tap") + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(BOT2, &depressed); + + ASSERT_EQ(UINT, keyboard_history[0][KC_X], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_LCTL], 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_X], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_LCTL], 0); + + ASSERT_EQ(UINT, keyboard_history[2][KC_X], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_LCTL], 0); +END_TEST + +TEST("key_key_dance_hold") + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(DANCE_TIMEOUT + 1); + process_record_user(BOT2, &depressed); + + ASSERT_EQ(UINT, keyboard_history[0][KC_X], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_LCTL], 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_X], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_LCTL], 1); + + ASSERT_EQ(UINT, keyboard_history[2][KC_X], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_LCTL], 0); +END_TEST + +// KL +TEST("key_layer_tap") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + process_record_user(BOT3, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[0][KC_C], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_C], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_C], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_C], 255); +END_TEST + +TEST("key_layer_retrotapping") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT3, &pressed); + pause_ms(1000); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + process_record_user(BOT3, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[0][KC_C], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_C], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_C], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_C], 255); +END_TEST + +TEST("key_layer_hold_quick_typist") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + pause_ms(1); + + process_record_user(BOT3, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + + ASSERT_EQ(UINT, keyboard_history[0][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[6][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[7][KC_1], 255); +END_TEST + +TEST("key_layer_hold_slow_typist") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + pause_ms(1000); + process_record_user(TOP1, &pressed); + pause_ms(1000); + process_record_user(TOP1, &depressed); + pause_ms(1000); + process_record_user(TOP1, &pressed); + pause_ms(1000); + process_record_user(TOP1, &depressed); + pause_ms(1000); + process_record_user(TOP1, &pressed); + pause_ms(1000); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + pause_ms(1); + + process_record_user(BOT3, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + + ASSERT_EQ(UINT, keyboard_history[0][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[6][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[7][KC_1], 255); +END_TEST + +// KM +TEST("key_mod_tap") + ASSERT_EQ(UINT, keyboard_history[0][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_V], 0); + process_record_user(BOT4, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_V], 0); + process_record_user(BOT4, &depressed); + ASSERT_EQ(UINT, keyboard_history[2][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_V], 0); + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[3][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_V], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_LALT], 255); + ASSERT_EQ(UINT, keyboard_history[5][KC_V], 255); +END_TEST + +TEST("key_mod_retrotapping") + ASSERT_EQ(UINT, keyboard_history[0][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_V], 0); + process_record_user(BOT4, &pressed); + pause_ms(1000); + ASSERT_EQ(UINT, keyboard_history[1][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_V], 0); + process_record_user(BOT4, &depressed); + ASSERT_EQ(UINT, keyboard_history[2][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_V], 0); + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[3][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_V], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_LALT], 255); + ASSERT_EQ(UINT, keyboard_history[5][KC_V], 255); +END_TEST + +TEST("key_mod_hold_quick_typist") + process_record_user(BOT4, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + pause_ms(1); + + process_record_user(BOT4, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + + ASSERT_EQ(UINT, keyboard_history[0][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[3][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[5][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[6][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[6][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[7][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[7][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[8][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[8][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[9][KC_LALT], 255); + ASSERT_EQ(UINT, keyboard_history[9][KC_V], 255); +END_TEST + +TEST("key_mod_hold_slow_typist") + process_record_user(BOT4, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + + pause_ms(1000); + process_record_user(TOP1, &pressed); + pause_ms(1000); + process_record_user(TOP1, &depressed); + pause_ms(1000); + process_record_user(TOP1, &pressed); + pause_ms(1000); + process_record_user(TOP1, &depressed); + pause_ms(1000); + process_record_user(TOP1, &pressed); + pause_ms(1000); + process_record_user(TOP1, &depressed); + pause_ms(1000); + + process_record_user(BOT4, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + + ASSERT_EQ(UINT, keyboard_history[0][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[3][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[3][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[5][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[5][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[6][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[6][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[6][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[7][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[7][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[7][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[8][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[8][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[8][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[9][KC_LALT], 255); + ASSERT_EQ(UINT, keyboard_history[9][KC_V], 255); + ASSERT_EQ(UINT, keyboard_history[9][KC_Q], 255); +END_TEST + +// LEADER +TEST("leader_triggers_global") + uint8_t state = ACTIVATED; + struct Chord chord PROGMEM = {0, QWERTY, &state, NULL, 0, 0, leader}; + chord.function(&chord); + + ASSERT_EQ(UINT, in_leader_mode, 1); +END_TEST + +TEST("leader_no_follow") + uint8_t state = ACTIVATED; + struct Chord chord PROGMEM = {0, QWERTY, &state, NULL, 0, 0, leader}; + chord.function(&chord); + + ASSERT_EQ(UINT, in_leader_mode, 1); + + pause_ms(1000); + + ASSERT_EQ(UINT, in_leader_mode, 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_O], 255); +END_TEST + +TEST("leader_wrong_follow") + process_record_user(TOP2, &pressed); + process_record_user(TOP3, &pressed); + process_record_user(BOT2, &pressed); + process_record_user(BOT3, &pressed); + pause_ms(1); + process_record_user(TOP2, &depressed); + process_record_user(TOP3, &depressed); + process_record_user(BOT2, &depressed); + process_record_user(BOT3, &depressed); + + ASSERT_EQ(UINT, in_leader_mode, 1); + + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + pause_ms(1); + process_record_user(TOP2, &pressed); + pause_ms(1); + process_record_user(TOP2, &depressed); + + pause_ms(LEADER_TIMEOUT); + pause_ms(1); + + ASSERT_EQ(UINT, in_leader_mode, 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_Q], 255); +END_TEST + +TEST("leader_correct_follow") + process_record_user(TOP2, &pressed); + process_record_user(TOP3, &pressed); + process_record_user(BOT2, &pressed); + process_record_user(BOT3, &pressed); + pause_ms(1); + process_record_user(TOP2, &depressed); + process_record_user(TOP3, &depressed); + process_record_user(BOT2, &depressed); + process_record_user(BOT3, &depressed); + + ASSERT_EQ(UINT, in_leader_mode, 1); + + pause_ms(1); + process_record_user(TOP0, &pressed); + pause_ms(1); + process_record_user(TOP0, &depressed); + pause_ms(1); + process_record_user(TOP9, &pressed); + pause_ms(1); + process_record_user(TOP9, &depressed); + + pause_ms(LEADER_TIMEOUT); + ASSERT_EQ(UINT, in_leader_mode, 1); + + pause_ms(1); + ASSERT_EQ(UINT, in_leader_mode, 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_O], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_P], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_A], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_S], 1); + + ASSERT_EQ(UINT, keyboard_history[2][KC_O], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_P], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_A], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_S], 0); + + ASSERT_EQ(UINT, keyboard_history[3][KC_O], 255); + ASSERT_EQ(UINT, keyboard_history[3][KC_P], 255); + ASSERT_EQ(UINT, keyboard_history[3][KC_A], 255); + ASSERT_EQ(UINT, keyboard_history[3][KC_S], 255); + + ASSERT_EQ(UINT, keyboard_history[4][KC_O], 255); + ASSERT_EQ(UINT, keyboard_history[4][KC_P], 255); + ASSERT_EQ(UINT, keyboard_history[4][KC_A], 255); + ASSERT_EQ(UINT, keyboard_history[4][KC_S], 255); + + ASSERT_EQ(UINT, keyboard_history[5][KC_Q], 255); +END_TEST + +// DYNAMIC MACRO +TEST("dynamic_macro_record_mode") + current_pseudolayer = NUM; + + // record + ASSERT_EQ(UINT, dynamic_macro_mode, 0); + process_record_user(BOT7, &pressed); + process_record_user(BOT7, &depressed); + ASSERT_EQ(UINT, dynamic_macro_mode, 1); + pause_ms(1000); + ASSERT_EQ(UINT, dynamic_macro_mode, 1); +END_TEST + +TEST("dynamic_macro_record_mode_off") + current_pseudolayer = NUM; + + process_record_user(BOT7, &pressed); + process_record_user(BOT7, &depressed); + ASSERT_EQ(UINT, dynamic_macro_mode, 1); + + process_record_user(BOT9, &pressed); + process_record_user(BOT9, &depressed); + ASSERT_EQ(UINT, dynamic_macro_mode, 0); +END_TEST + +TEST("dynamic_macro_record_one") + current_pseudolayer = NUM; + + process_record_user(BOT7, &pressed); + process_record_user(BOT7, &depressed); + ASSERT_EQ(UINT, dynamic_macro_mode, 1); + + process_record_user(TOP1, &pressed); + process_record_user(TOP1, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 255); + + process_record_user(BOT9, &pressed); + process_record_user(BOT9, &depressed); + + pause_ms(1000); + + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 255); + + pause_ms(1000); + + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 255); +END_TEST + +TEST("dynamic_macro_record_two") + current_pseudolayer = NUM; + + process_record_user(BOT7, &pressed); + process_record_user(BOT7, &depressed); + ASSERT_EQ(UINT, dynamic_macro_mode, 1); + + process_record_user(TOP1, &pressed); + process_record_user(TOP1, &depressed); + + process_record_user(TOP2, &pressed); + process_record_user(TOP2, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 255); + + process_record_user(BOT9, &pressed); + process_record_user(BOT9, &depressed); + + pause_ms(1000); + + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 255); +END_TEST + +TEST("dynamic_macro_record_two_parts") + current_pseudolayer = NUM; + + process_record_user(BOT7, &pressed); + process_record_user(BOT7, &depressed); + ASSERT_EQ(UINT, dynamic_macro_mode, 1); + + process_record_user(TOP1, &pressed); + process_record_user(TOP1, &depressed); + + process_record_user(TOP2, &pressed); + process_record_user(TOP2, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 255); + + process_record_user(BOT8, &pressed); + process_record_user(BOT8, &depressed); + + process_record_user(TOP3, &pressed); + process_record_user(TOP3, &depressed); + + process_record_user(BOT9, &pressed); + process_record_user(BOT9, &depressed); + + pause_ms(1000); + + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_3], 0); + + ASSERT_EQ(UINT, keyboard_history[2][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_3], 0); + + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[3][KC_3], 0); + + ASSERT_EQ(UINT, keyboard_history[4][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_3], 0); + + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_3], 1); + + ASSERT_EQ(UINT, keyboard_history[6][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[6][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[6][KC_3], 0); + + ASSERT_EQ(UINT, keyboard_history[7][KC_1], 255); +END_TEST + +// dance + M() + +TEST("dance_tap") + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[1][KC_9], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_0], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_9], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_0], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_9], 255); +END_TEST + +TEST("dance_hold") + process_record_user(BOT0, &pressed); + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[1][KC_9], 1); + + process_record_user(BOT0, &depressed); + ASSERT_EQ(UINT, keyboard_history[2][KC_9], 0); +END_TEST + +TEST("dance_tap_tap") + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[1][KC_9], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_0], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_9], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_0], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_9], 255); +END_TEST + +TEST("dance_tap_hold") + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + pause_ms(1); + process_record_user(BOT0, &pressed); + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[1][KC_0], 1); + + process_record_user(BOT0, &depressed); + ASSERT_EQ(UINT, keyboard_history[2][KC_0], 0); +END_TEST + +// MK +TEST("multiple_keys") + current_pseudolayer = NUM; + + process_record_user(BOT1, &pressed); + process_record_user(BOT1, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_LCTL], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[2][KC_LCTL], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[3][KC_LCTL], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[4][KC_LCTL], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[5][KC_LCTL], 255); +END_TEST + +TEST("multiple_keys_interleaved") + current_pseudolayer = NUM; + + process_record_user(BOT1, &pressed); + pause_ms(CHORD_TIMEOUT+1); + + process_record_user(TOP1, &pressed); + process_record_user(TOP1, &depressed); + process_record_user(TOP1, &pressed); + process_record_user(TOP1, &depressed); + process_record_user(TOP1, &pressed); + process_record_user(TOP1, &depressed); + + process_record_user(BOT1, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_LCTL], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[2][KC_LCTL], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[6][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[7][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[8][KC_1], 0); + + ASSERT_EQ(UINT, keyboard_history[9][KC_LCTL], 0); + ASSERT_EQ(UINT, keyboard_history[9][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[10][KC_LCTL], 0); + ASSERT_EQ(UINT, keyboard_history[10][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[11][KC_LCTL], 255); +END_TEST + +// D +TEST("dance_one") + current_pseudolayer = NUM; + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 255); + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 255); +END_TEST + +TEST("dance_two") + current_pseudolayer = NUM; + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_2], 255); + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_2], 255); +END_TEST + +TEST("dance_three") + current_pseudolayer = NUM; + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_3], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_3], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_3], 255); + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_3], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_3], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_3], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_3], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_3], 255); +END_TEST + +TEST("dance_two_held") + current_pseudolayer = NUM; + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_2], 255); + + process_record_user(BOT3, &depressed); + ASSERT_EQ(UINT, keyboard_history[2][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_2], 255); +END_TEST + +// These two are leaving the chording engine, they kinda have to be tested manually +// TO +// RESET + +END diff --git a/users/dennytom/chording_engine/tests/test_full.sh b/users/dennytom/chording_engine/tests/test_full.sh new file mode 100644 index 0000000000..ea93aec8f9 --- /dev/null +++ b/users/dennytom/chording_engine/tests/test_full.sh @@ -0,0 +1,11 @@ +#!/bin/sh +cd .. +python3 parser.py tests/test_keymap_def.json tests/test_keymap.c && \ +gcc -g tests/test.c -o tests/test && \ +tests/test && \ +python3 parser.py ../../../keyboards/butterstick/keymaps/tomas/keymap_def.json ../../../keyboards/butterstick/keymaps/tomas/keymap.c && \ +python3 parser.py ../../../keyboards/georgi/keymaps/tomas/keymap_def.json ../../../keyboards/georgi/keymaps/tomas/keymap.c && \ +python3 parser.py ../../../keyboards/georgi/keymaps/buttery/keymap_def.json ../../../keyboards/georgi/keymaps/buttery/keymap.c && \ +cd ../../../ && \ +make butterstick && \ +make georgi
\ No newline at end of file diff --git a/users/dennytom/chording_engine/tests/test_keymap_def.json b/users/dennytom/chording_engine/tests/test_keymap_def.json new file mode 100644 index 0000000000..eae2ed37cf --- /dev/null +++ b/users/dennytom/chording_engine/tests/test_keymap_def.json @@ -0,0 +1,145 @@ +{ + "keys": [ + "TOP1", "TOP2", "TOP3", "TOP4", "TOP5", "TOP6", "TOP7", "TOP8", "TOP9", "TOP0", + "BOT1", "BOT2", "BOT3", "BOT4", "BOT5", "BOT6", "BOT7", "BOT8", "BOT9", "BOT0" + ], + "parameters": { + "do_not_include_QMK": true, + "layout_function_name": "LAYOUT_test", + "chord_timeout": 100, + "dance_timeout": 200, + "leader_timeout": 750, + "tap_timeout": 50, + "command_max_length": 5, + "leader_max_length": 5, + "dynamic_macro_max_length": 20, + "string_max_length": 16, + "long_press_multiplier": 3, + "default_pseudolayer": "QWERTY" + }, + "layers": [ + { + "type": "auto" + }, + { + "type": "manual", + "keycodes": ["KC_1", "KC_2", "KC_3", "KC_4", "KC_5", "KC_6", "KC_7", "KC_8", "KC_9", "KC_0", + "KC_Q", "KC_W", "KC_E", "KC_R", "KC_T", "KC_Y", "KC_U", "KC_I", "KC_O", "KC_P" + ] + } + ], + "chord_sets": [ + { + "name": "rows", + "chords": [ + ["TOP1"], ["TOP2"], ["TOP3"], ["TOP4"], ["TOP5"], ["TOP6"], ["TOP7"], ["TOP8"], ["TOP9"], ["TOP0"], + ["TOP1", "BOT1"], ["TOP2", "BOT2"], ["TOP3", "BOT3"], ["TOP4", "BOT4"], ["TOP5", "BOT5"], ["TOP6", "BOT6"], ["TOP7", "BOT7"], ["TOP8", "BOT8"], ["TOP9", "BOT9"], ["TOP0", "BOT0"], + ["BOT1"], ["BOT2"], ["BOT3"], ["BOT4"], ["BOT5"], ["BOT6"], ["BOT7"], ["BOT8"], ["BOT9"], ["BOT0"] + ] + }, + { + "name": "cols", + "chords": [ + ["TOP1", "TOP2"], ["TOP2", "TOP3"], ["TOP3", "TOP4"], ["TOP4", "TOP5"], ["TOP5", "TOP6"], ["TOP6", "TOP7"], ["TOP7", "TOP8"], ["TOP8", "TOP9"], ["TOP9", "TOP0"], + ["TOP1", "TOP2", "BOT1", "BOT2"], ["TOP2", "TOP3", "BOT2", "BOT3"], ["TOP3", "TOP4", "BOT3", "BOT4"], ["TOP4", "TOP5", "BOT4", "BOT5"], ["TOP5", "TOP6", "BOT5", "BOT6"], ["TOP6", "TOP7", "BOT6", "BOT7"], ["TOP7", "TOP8", "BOT7", "BOT8"], ["TOP8", "TOP9", "BOT8", "BOT9"], ["TOP9", "TOP0", "BOT9", "BOT0"], + ["BOT1", "BOT2"], ["BOT2", "BOT3"], ["BOT3", "BOT4"], ["BOT4", "BOT5"], ["BOT5", "BOT6"], ["BOT6", "BOT7"], ["BOT7", "BOT8"], ["BOT8", "BOT9"], ["BOT9", "BOT0"] + ] + }, + { + "name": "asetniop", + "chords": [ + ["TOP1"], ["TOP2"], ["TOP3"], ["TOP4"], ["TOP7"], ["TOP8"], ["TOP9"], ["TOP0"], + ["TOP1", "TOP2"], ["TOP2", "TOP3"], ["TOP3", "TOP4"], ["TOP4", "TOP7"], ["TOP7", "TOP8"], ["TOP8", "TOP9"], ["TOP9", "TOP0"], + ["TOP1", "TOP3"], ["TOP2", "TOP4"], ["TOP3", "TOP7"], ["TOP4", "TOP8"], ["TOP7", "TOP9"], ["TOP8", "TOP0"], + ["TOP1", "TOP4"], ["TOP2", "TOP7"], ["TOP3", "TOP8"], ["TOP4", "TOP9"], ["TOP7", "TOP0"], + ["TOP1", "TOP7"], ["TOP2", "TOP8"], ["TOP3", "TOP9"], ["TOP4", "TOP0"], + ["TOP1", "TOP8"], ["TOP2", "TOP9"], ["TOP3", "TOP0"], + ["TOP1", "TOP9"], ["TOP2", "TOP0"], + ["TOP1", "TOP0"] + ] + } + ], + "pseudolayers": [ + { + "name": "ALWAYS_ON", + "chords": [ + { + "type": "visual", + "chord": [ + " ", " ", " ", " ", " ", " ", " ", "X", "X", "X", + " ", " ", " ", " ", " ", " ", " ", "X", "X", "X" + ], + "keycode": "MO(FNC, NUM)" + } + ] + }, + { + "name": "QWERTY", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", + "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", + "AS(Z)", "KK(X, LCTL)", "KL(C, NUM)", "KM(V, LALT)", "B", "N", "M", "COMMA", ".", "M(double_dance, KC_9, KC_0)" + ] + }, + { + "type": "chord_set", + "set": "cols", + "keycodes": [ + "ESC", "", "", "", "", "", "", "", "", + "", "LEAD", "", "", "CMD", "", "", "", "", + "LSFT", "O(LSFT)", "", "", "", "O(NUM)", "MO(NUM)", "", "DF(NUM)" + ] + }, + { + "type": "visual", + "chord": [ + "X", "X", " ", " ", " ", " ", " ", " ", " ", " ", + "X", "X", " ", " ", " ", " ", " ", " ", " ", " " + ], + "keycode": "LOCK" + } + ] + }, + { + "name": "NUM", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", + "", "", "", "", "", "", "", "", "", "", + "", "KC_LEFT", "D(KC_1, KC_2, KC_3)", "", "", "", "DM_RECORD", "DM_NEXT", "DM_END", "DM_PLAY" + ] + }, + { + "type": "simple", + "chord": ["BOT1"], + "keycode": "MK(KC_LCTL, KC_LSFT)" + } + ] + }, + { + "name": "FNC", + "chords": [] + } + ], + "leader_sequences": [ + { + "name": "fnc_L1", + "function": "void fnc_L1(void) { key_in(KC_A); clear_keyboard(); }", + "sequence": ["KC_O", "KC_P"] + }, + { + "name": "fnc_L2", + "function": "void fnc_L2(void) { key_in(KC_S); clear_keyboard(); }", + "sequence": ["KC_P", "KC_O"] + } + ], + "extra_code": "void double_dance(const struct Chord* self) {\n switch (*self->state) {\n case ACTIVATED:\n *self->counter = (*self->counter + 1) % 2;\n break;\n case PRESS_FROM_ACTIVE:\n if (*self->counter == 1) {\n key_in(self->value1);\n } else {\n key_in(self->value2);\n }\n *self->state = FINISHED_FROM_ACTIVE;\n break;\n case FINISHED:\n if (*self->counter == 1) {\n tap_key(self->value1);\n } else {\n tap_key(self->value2);\n }\n *self->counter = 0;\n *self->state = IDLE;\n break;\n case RESTART:\n if (*self->counter == 1) {\n key_out(self->value1);\n } else {\n key_out(self->value2);\n }\n *self->counter = 0;\n break;\n default:\n break;\n }\n}\n", + "extra_dependencies": [] +}
\ No newline at end of file diff --git a/users/dennytom/chording_engine/tests/test_quick.sh b/users/dennytom/chording_engine/tests/test_quick.sh new file mode 100644 index 0000000000..3740122e27 --- /dev/null +++ b/users/dennytom/chording_engine/tests/test_quick.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +cd .. +python3 parser.py tests/test_keymap_def.json tests/test_keymap.c && \ +gcc -g tests/test.c -o tests/test && \ +tests/test
\ No newline at end of file |