From 751cd7707e39d1eb20e768c5557a030b53e94ddc Mon Sep 17 00:00:00 2001 From: "Peter D. Gray" Date: Mon, 15 Apr 2024 11:01:01 -0400 Subject: [PATCH] fix keyboard during login ux --- shared/mempad.py | 38 ++++++++++++++++++++++---------------- shared/numpad.py | 3 +-- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/shared/mempad.py b/shared/mempad.py index 97ec7f70..661a0e5c 100644 --- a/shared/mempad.py +++ b/shared/mempad.py @@ -40,7 +40,10 @@ class MembraneNumpad(NumpadBase): # each full scan is pushed onto this, only last one kept if overflow self.scans = deque((), 50, 0) - # internal to timer irq handler + # have we given this specific key to higher layers yet? + self._char_reported = set() + + # internal state for timer irq handler self._history = None # see _start_scan self._scan_count = 0 self._cycle = 0 @@ -56,21 +59,22 @@ class MembraneNumpad(NumpadBase): # ready to start def anypress_irq(self, pin): - # come here for any change, high or low + # come here for any change on column inputs, high or low if self.waiting_for_any: # something was pressed, but we don't know what.. start a scan+debounce self._start_scan() def start(self): - # Begin scanning for events + # begin scanning for events self._wait_any() def _wait_any(self): - # wait for any press. + # wait for any press but stop continuously scanning for now self.timer.deinit() for r in self.rows: r.off() + self.waiting_for_any = True def _start_scan(self): @@ -121,17 +125,16 @@ class MembraneNumpad(NumpadBase): # handle debounce, which happens in both directions: press and release # - all samples must be in agreement to count as either up or down - # - only handling single key-down at a time. if sum(self._history) == 0: # all are up, and debounced as such self.scans.append(0xff) + else: + for i in range(NUM_ROWS * NUM_COLS): + if self._history[i] == NUM_SAMPLES: + # down + self.scans.append(i) - for i in range(NUM_ROWS * NUM_COLS): - if self._history[i] == NUM_SAMPLES: - # down - self.scans.append(i) - - self._history[i] = 0 + self._history[i] = 0 async def _finish_scan(self): # we're done a full scan (mulitple times: NUM_SAMPLES) @@ -141,16 +144,19 @@ class MembraneNumpad(NumpadBase): if event == 0xff: # all keys are now up - if self.key_pressed: + if self._char_reported: + self._char_reported.clear() self._key_event('') else: # indicated key was found to be down - key = DECODER[event] - self._key_event(key) + ch = DECODER[event] + if ch not in self._char_reported: + self._char_reported.add(ch) + self._key_event(ch) - self.lp_time = utime.ticks_ms() + self.lp_time = utime.ticks_ms() - if not self.key_pressed and utime.ticks_diff(utime.ticks_ms(), self.lp_time) > 250: + if not self._char_reported and utime.ticks_diff(utime.ticks_ms(), self.lp_time) > 250: # stop scanning now... nothing happening self._wait_any() else: diff --git a/shared/numpad.py b/shared/numpad.py index 8b30eb50..0be474e5 100644 --- a/shared/numpad.py +++ b/shared/numpad.py @@ -15,7 +15,7 @@ class NumpadBase: def __init__(self): # once pressed, and released; keys show up in this queue self._changes = Queue(64) - self.key_pressed = '' + self.key_pressed = '' # internal to ABC, should not be used by subclasses self.debug = 0 # 0..2 @@ -55,7 +55,6 @@ class NumpadBase: if self._changes.full(): # no space, but do a "all up" and the new event - print('Q overflow') self._changes.get_nowait() self._changes.get_nowait() if key != '':