Skip to content

Commit

Permalink
achordion: Fix bugs related to the achordion timer and 2345=67
Browse files Browse the repository at this point in the history
This fixes a rare bug in the achordion timer, by simplifying
the logic. I'm not sure where the math is wrong.  Just that it
is.

Also make 2345=67 more compatible with achordion to close
up the final bug I found in the whole thing.
  • Loading branch information
ilc committed Oct 5, 2024
1 parent 1cd2d83 commit 25badcf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 7 additions & 5 deletions keyboards/svalboard/keymaps/features/achordion.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static bool pressed_another_key_before_release = false;

#ifdef ACHORDION_STREAK
// Timer for typing streak
static bool streaking = false;
static uint16_t streak_timer = 0;
#else
// When disabled, is_streak is never true
Expand All @@ -66,9 +67,10 @@ static uint8_t achordion_state = STATE_RELEASED;
#ifdef ACHORDION_STREAK
static void update_streak_timer(uint16_t keycode, keyrecord_t* record) {
if (achordion_streak_continue(keycode)) {
// We use 0 to represent an unset timer, so `| 1` to force a nonzero value.
streak_timer = record->event.time | 1;
streaking = true;
streak_timer = record->event.time;
} else {
streaking = false;
streak_timer = 0;
}
}
Expand Down Expand Up @@ -235,7 +237,7 @@ bool process_achordion(uint16_t keycode, keyrecord_t* record) {
const uint16_t s_timeout =
achordion_streak_chord_timeout(tap_hold_keycode, keycode);
const bool is_streak =
streak_timer && s_timeout &&
streaking && s_timeout &&
!timer_expired(record->event.time, (streak_timer + s_timeout));
#endif

Expand Down Expand Up @@ -306,9 +308,9 @@ void achordion_task(void) {

#ifdef ACHORDION_STREAK
#define MAX_STREAK_TIMEOUT 800
if (streak_timer &&
if (streaking &&
timer_expired(timer_read(), (streak_timer + MAX_STREAK_TIMEOUT))) {
streak_timer = 0; // Expired.
streaking = false; // Expired.
}
#endif
}
Expand Down
11 changes: 5 additions & 6 deletions keyboards/svalboard/keymaps/keymap_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,10 @@ void check_layer_67(void) {
bool in_mod_tap = false;
int8_t in_mod_tap_layer = -1;
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {

// Abort additional processing if userspace code did
if (!process_record_user(keycode, record)) { return false;}

if (!global_saved_values.disable_achordion && !process_achordion(keycode, record)) { return false; }
if (!in_mod_tap && !global_saved_values.disable_achordion && !process_achordion(keycode, record)) { return false; }

// We are in a mod tap, with a KC_TRANSPARENT, lets make it transparent...
if (IS_QK_MOD_TAP(keycode) && ((keycode & 0xFF) == KC_TRANSPARENT) &&
Expand All @@ -201,19 +200,19 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
in_mod_tap_layer = get_highest_layer(layer_state);
layer_state = layer_state & ~(1 << in_mod_tap_layer);

action_exec(record->event);

in_mod_tap = true;

return false;
return true;
}

// Fix things up on the release for the mod_tap case.
if (!record->event.pressed && in_mod_tap) {
in_mod_tap = false;
layer_state = layer_state | (1 << in_mod_tap_layer);
in_mod_tap_layer = -1;
return true;
}

// If console is enabled, it will print the matrix position and status of each key pressed
#ifdef CONSOLE_ENABLE
uprintf("KL: kc: 0x%04X, col: %2u, row: %2u, pressed: %u, time: %5u, int: %u, count: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed, record->event.time, record->tap.interrupted, record->tap.count);
Expand Down

0 comments on commit 25badcf

Please sign in to comment.