Skip to content

Commit ed48d66

Browse files
committed
fixes keypad driver, a better way
1 parent a805030 commit ed48d66

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

display_configs/LilyGo-TDeck/keyboard_s3.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55

66

77
class Keyboard(keypad_framework.KeypadDriver):
8-
def __init__(self, device): # NOQA
8+
def __init__(self, device, debug): # NOQA
99
self._device = device
10-
self._buf = bytearray(1)
11-
self._mv = memoryview(self._buf)
12-
10+
self._debug = debug
1311
super().__init__()
1412

1513
def _get_key(self):
@@ -19,9 +17,7 @@ def _get_key(self):
1917
# lv.KEY.PREV = 0x0B
2018
# lv.KEY.HOME = 0x02
2119
# lv.KEY.END = 0x03
22-
self._device.read(buf=self._mv)
23-
key = self._buf[0]
24-
20+
key = bytearray(self._device.read(1))[0]
2521
if key == 0x00: # no key
2622
return None
2723
elif key == 0x08: # backspace
@@ -31,5 +27,16 @@ def _get_key(self):
3127
elif key == 0x0C: # alt + c
3228
return None
3329

30+
if self._debug:
31+
k = key
32+
# check if key is in human readable ascii range and if it
33+
# is then convert it form it's decimal value to the actual ascii
34+
# key else convert to hex
35+
if 127 > k >= 32:
36+
k = chr(k)
37+
else:
38+
k = hex(k)
39+
print('RAW KEY:', hex(k))
40+
3441
return self.PRESSED, key
3542

0 commit comments

Comments
 (0)