From 65a8379850ee2b46543a34f1313d09252be58fef Mon Sep 17 00:00:00 2001 From: Ira Cooper Date: Sat, 28 Sep 2024 13:41:12 -0400 Subject: [PATCH] achordion: Fix bugs related to the achordion timer and 2345=67 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. --- keyboards/svalboard/keymaps/features/achordion.c | 12 +++++++----- keyboards/svalboard/keymaps/keymap_support.c | 11 +++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/keyboards/svalboard/keymaps/features/achordion.c b/keyboards/svalboard/keymaps/features/achordion.c index 4968e9d1169..2fb14cd0e5f 100644 --- a/keyboards/svalboard/keymaps/features/achordion.c +++ b/keyboards/svalboard/keymaps/features/achordion.c @@ -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 @@ -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; } } @@ -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 @@ -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 } diff --git a/keyboards/svalboard/keymaps/keymap_support.c b/keyboards/svalboard/keymaps/keymap_support.c index e6a9b777849..afcd81caf36 100644 --- a/keyboards/svalboard/keymaps/keymap_support.c +++ b/keyboards/svalboard/keymaps/keymap_support.c @@ -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) && @@ -201,11 +200,9 @@ 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. @@ -213,7 +210,9 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { 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);