Skip to content

Commit b15b49f

Browse files
3rdIterationclaude
andcommitted
fix: physical keyboard handling in mnemonic entry + trackball sensitivity
Mnemonic word entry only understood the on-screen keyboard: - letters: the screen posts uppercase A-Z, but the T-Deck keyboard sends lowercase ascii, so typed letters were ignored; accept either case - enter: the on-screen enter button is inactive during mnemonic entry, but a physical keyboard can post BTN_KEYBOARD_ENTER at any time, which set done_entering_words early and tripped the words_entered==nwords assert (mnemonic.c:865); only honour enter when the on-screen button would be active - letter validity: the on-screen keyboard disables letters that match no word, a physical keyboard cannot - reject letters yielding a stem with no matching words (previously would trip the possible_words>0 assert) Also halve trackball sensitivity: require 2 edges per scroll step, with the accumulator reset on direction change or a 300ms pause. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent ab4399a commit b15b49f

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

main/input/tdeck.inc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
// caps the overall scroll rate
2424
#define TB_DEBOUNCE_US 2000
2525

26+
// Edges required per scroll step - raise to reduce sensitivity
27+
#define TB_EDGES_PER_EVENT 2
28+
29+
// Edges further apart than this do not accumulate towards a step
30+
#define TB_GESTURE_TIMEOUT_US 300000
31+
2632
static void tdeck_keyboard_task(void* unused)
2733
{
2834
gpio_set_direction(BOARD_POWERON_GPIO, GPIO_MODE_OUTPUT);
@@ -79,13 +85,26 @@ static QueueHandle_t tb_queue = NULL;
7985
static void tb_isr(void* arg)
8086
{
8187
static int64_t last_event_us = 0;
88+
static tb_nav_t last_nav = TB_NAV_PREV;
89+
static uint8_t edge_count = 0;
90+
8291
const int64_t now = esp_timer_get_time();
83-
if (now - last_event_us < TB_DEBOUNCE_US) {
92+
const int64_t elapsed = now - last_event_us;
93+
if (elapsed < TB_DEBOUNCE_US) {
8494
return;
8595
}
8696
last_event_us = now;
8797

8898
const tb_nav_t nav = (tb_nav_t)(uintptr_t)arg;
99+
if (nav != last_nav || elapsed > TB_GESTURE_TIMEOUT_US) {
100+
last_nav = nav;
101+
edge_count = 0;
102+
}
103+
if (++edge_count < TB_EDGES_PER_EVENT) {
104+
return;
105+
}
106+
edge_count = 0;
107+
89108
BaseType_t higher_priority_woken = pdFALSE;
90109
xQueueSendFromISR(tb_queue, &nav, &higher_priority_woken);
91110
if (higher_priority_woken == pdTRUE) {

main/process/mnemonic.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -818,13 +818,24 @@ static size_t get_wordlist_words(
818818
// Wait for kb button click
819819
gui_activity_wait_event(enter_word_activity, GUI_BUTTON_EVENT, ESP_EVENT_ANY_ID, NULL, &ev_id, NULL, 0);
820820
selected_backspace = (ev_id == BTN_KEYBOARD_BACKSPACE);
821-
done_entering_words = (ev_id == BTN_KEYBOARD_ENTER);
822-
if (!selected_backspace && !done_entering_words) {
823-
// Character/letter was clicked
824-
const char letter_selected = ev_id - BTN_KEYBOARD_ASCII_OFFSET;
821+
// A physical keyboard can send 'enter' at any time - only honour it
822+
// where the on-screen enter button would be active (see enable_relevant_chars)
823+
done_entering_words = (ev_id == BTN_KEYBOARD_ENTER && !is_mnemonic && !char_index);
824+
if (!selected_backspace && ev_id >= BTN_KEYBOARD_ASCII_OFFSET) {
825+
// Character/letter was clicked/typed (physical keyboards send lowercase)
826+
const char letter_selected = toupper((int)(ev_id - BTN_KEYBOARD_ASCII_OFFSET));
825827
if (letter_selected >= 'A' && letter_selected <= 'Z') {
828+
// Only accept a letter if some word still matches the new stem -
829+
// the on-screen keyboard disables impossible letters, but a
830+
// physical keyboard cannot
826831
word[char_index] = tolower(letter_selected);
827-
word[++char_index] = '\0';
832+
word[char_index + 1] = '\0';
833+
if (valid_words(word, char_index + 1, p_filter_words, num_filter_words, possible_word_list,
834+
NUM_WORDS_SELECT, &exact_match)) {
835+
++char_index;
836+
} else {
837+
word[char_index] = '\0';
838+
}
828839
}
829840
}
830841
}

0 commit comments

Comments
 (0)