Skip to content

Commit 35431b6

Browse files
committed
Add sequences for missing keys on lilygo keyboard
1 parent 4e34356 commit 35431b6

File tree

2 files changed

+62
-58
lines changed

2 files changed

+62
-58
lines changed

PyDOS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def PyDOS():
6767
global envVars
6868
if "envVars" not in globals().keys():
6969
envVars = {}
70-
_VER = "1.27"
70+
_VER = "1.28"
7171
prmpVals = ['>','(',')','&','|','\x1b','\b','<','=',' ',_VER,'\n','$','']
7272

7373
print("Starting Py-DOS...")

cpython/lib/optional/pydos_ui_lilygokbd.py

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ def __init__(self):
1515
self._touched = False
1616
_ADDRESS_KBD = 0x55
1717

18-
self.lastCmdLine = ""
19-
self.commandHistory = []
18+
self.commandHistory = [""]
2019

2120
self._i2c = I2CDevice(Pydos_hw.I2C(), _ADDRESS_KBD)
2221
self.trackball = {
23-
"up": countio.Counter(board.TRACKBALL_UP),
24-
"down": countio.Counter(board.TRACKBALL_DOWN),
25-
"left": countio.Counter(board.TRACKBALL_LEFT),
26-
"right": countio.Counter(board.TRACKBALL_RIGHT)
22+
"A": countio.Counter(board.TRACKBALL_UP),
23+
"B": countio.Counter(board.TRACKBALL_DOWN),
24+
"C": countio.Counter(board.TRACKBALL_RIGHT),
25+
"D": countio.Counter(board.TRACKBALL_LEFT)
2726
}
2827
self.click = keypad.Keys([board.TRACKBALL_CLICK], value_when_pressed=False)
2928

@@ -81,10 +80,15 @@ def input(disp_text=None):
8180
if disp_text != None:
8281
print(disp_text,end="")
8382

83+
bld_chr1 = '_(+'
84+
bld_chr2 = '-+)'
85+
bld_chr = '=[]'
86+
bld_started = [False, False, False]
87+
88+
histPntr = len(Pydos_ui.commandHistory)
89+
8490
keys = ''
8591
editCol = 0
86-
histPntr = len(Pydos_ui.commandHistory)
87-
currEditLine = Pydos_ui.lastCmdLine
8892
loop = True
8993
ctrlkeys = ''
9094
arrow = ''
@@ -95,73 +99,66 @@ def input(disp_text=None):
9599

96100
while loop:
97101
#print(editCol,keys)
98-
# Find the last direction the trackball was moved
99-
# and wait for trackball to stop moving
100102
if ctrlkeys == '':
101103
arrow = ""
102104
trackloop = True
103105
else:
104106
ctrlkeys = ''
105107
trackloop = False
106108

109+
# Find the last direction the trackball was moved
110+
# and wait for trackball to stop moving
107111
largestDir = 0
108112
while trackloop:
109113
trackloop = False
110114
for p,c in Pydos_ui.trackball.items():
111115
if c.count > largestDir:
112116
trackloop = True
113-
arrow = p
114-
largestDir = c.count
117+
if p not in "AB" or onLast:
118+
arrow = p
119+
largestDir = c.count
115120
c.reset()
116121
else:
117122
c.reset()
118123
if arrow != "" and not trackloop:
119-
#time.sleep(.2)
124+
time.sleep(.05)
120125
# clear all counters
121126
for p,c in Pydos_ui.trackball.items():
122127
if c.count > 0:
123128
c.reset()
124129

125-
if arrow == 'up':
130+
if arrow == 'A' or arrow == 'B':
126131
if len(Pydos_ui.commandHistory) > 0:
127-
print('\x08'*(editCol)+" "*(len(keys))+'\x08'*(len(keys)),end="")
132+
print(('\x08'*(editCol))+(" "*(len(keys)+1))+('\x08'*(len(keys)+1)),end="")
128133

129-
histPntr -= 1
130-
if histPntr < 0:
131-
histPntr = len(Pydos_ui.commandHistory) - 1
132-
print(Pydos_ui.commandHistory[histPntr],end="")
133-
keys = Pydos_ui.commandHistory[histPntr]
134-
currEditLine = keys
135-
editCol = len(keys)
136-
onFirst = False
137-
elif arrow == 'down':
138-
if len(Pydos_ui.commandHistory) > 0:
139-
print('\x08'*(editCol)+" "*(len(keys))+'\x08'*(len(keys)),end="")
134+
if arrow == 'A':
135+
histPntr -= 1
136+
else:
137+
histPntr += 1
140138

141-
histPntr += 1
142-
if histPntr >= len(Pydos_ui.commandHistory):
143-
histPntr = 0
139+
histPntr = histPntr % len(Pydos_ui.commandHistory)
144140
print(Pydos_ui.commandHistory[histPntr],end="")
145141
keys = Pydos_ui.commandHistory[histPntr]
146-
currEditLine = keys
147142
editCol = len(keys)
148-
onFirst = False
149-
elif arrow == 'left':
143+
if editCol == 0:
144+
onFirst = True
145+
else:
146+
onFirst = False
147+
elif arrow == 'D':
150148
if len(keys) > editCol:
151149
print(keys[editCol:editCol+1]+"\x08",end="")
152150
elif editCol == len(keys):
153151
print(" \x08",end="")
154152

155-
editCol += 1
156-
editCol = max(0,editCol-2)
153+
editCol = max(0,editCol-1)
157154
if editCol > 0:
158155
print('\x08',end="")
159156
onLast = False
160157
elif editCol == 0:
161158
if not onFirst:
162159
print('\x08',end="")
163160
onFirst = True
164-
elif arrow == 'right':
161+
elif arrow == 'C':
165162
if len(keys) > editCol:
166163
print(keys[editCol:editCol+1]+"\x08",end="")
167164

@@ -175,30 +172,39 @@ def input(disp_text=None):
175172
print(keys[editCol-1:],end="")
176173
onLast = True
177174

178-
if Pydos_ui.uart_bytes_available() or Pydos_ui.serial_bytes_available():
175+
if Pydos_ui.serial_bytes_available():
179176
if Pydos_ui.uart_bytes_available():
180177
keys = keys[:editCol]+stdin.read(1)+keys[editCol:]
181178
editCol += 1
182179
if keys[editCol-1] == '\x1b':
183180
keys = keys[:editCol-1]+keys[editCol:]
184181
ctrlkeys = stdin.read(2)
185-
if ctrlkeys == '[A':
186-
keys += ' '
187-
arrow = 'up'
188-
elif ctrlkeys == '[B':
189-
keys += ' '
190-
arrow = 'down'
191-
elif ctrlkeys == '[C':
192-
arrow = 'right'
193-
#editCol = min(len(keys),editCol)
194-
elif ctrlkeys == '[D':
195-
arrow = 'left'
196-
#editCol = max(0,editCol-2)
182+
# ctrlkeys = up:[A down:[B right:[C left:[D
183+
arrow = ctrlkeys[1]
197184
else:
198185
keys = keys[:editCol]+Pydos_ui.read_keyboard(1)+keys[editCol:]
199186
editCol += 1
200187

201-
if keys[editCol-1:editCol] == '\x08':
188+
# Convert two character sequences into missing keyboard keys
189+
# '_-' -> '=' '(+' -> '[' '+)' -> ']'
190+
bld_done = False
191+
bcindx = bld_chr2.find(keys[editCol-1:editCol])
192+
if bld_chr1.find(keys[editCol-1:editCol]) != -1 and not True in bld_started and arrow == "":
193+
bld_started[bld_chr1.find(keys[editCol-1:editCol])] = True
194+
elif keys[editCol-2:editCol] == bld_chr1[bcindx]+bld_chr2[bcindx] and bld_started[bcindx]:
195+
bld_started = [False for _ in bld_started]
196+
keys = keys[:editCol-2]+bld_chr[bcindx]+keys[editCol:]
197+
print('\x08'+keys[editCol-2:]+' '+('\x08'*(len(keys[editCol:])+(1 if onLast else 2))),end="")
198+
editCol -= 1
199+
bld_done = True
200+
else:
201+
bld_started = [False for _ in bld_started]
202+
203+
if arrow != "" and ctrlkeys != "":
204+
editCol -= 1
205+
elif arrow !='':
206+
pass
207+
elif keys[editCol-1:editCol] == '\x08':
202208
keys = keys[:max(0,editCol-2)]+keys[editCol:]
203209
if editCol > 1:
204210
print(('\x08'*(editCol-1))+keys+' \x08\x08',end="")
@@ -208,22 +214,20 @@ def input(disp_text=None):
208214
else:
209215
editCol -= 1
210216
onFirst = True
211-
elif arrow == 'left':
212-
editCol -= 1
213-
elif arrow == 'right':
214-
editCol -= 1
215217
elif len(keys[editCol-1:editCol]) > 0 and keys[editCol-1:editCol] in '\n\r':
216218
if len(keys) > editCol:
217219
print(keys[editCol:editCol+1]+"\x08",end="")
218220
elif editCol == len(keys):
219221
print(" \x08",end="")
220222
keys = keys[:editCol-1]+keys[editCol:]
221-
Pydos_ui.commandHistory.append(keys)
222-
if len(Pydos_ui.commandHistory) > 10:
223-
Pydos_ui.commandHistory.pop(0)
223+
if keys.strip() != "":
224+
Pydos_ui.commandHistory.append(keys)
225+
if len(Pydos_ui.commandHistory) > 10:
226+
Pydos_ui.commandHistory.pop(1)
227+
histPntr = len(Pydos_ui.commandHistory)
224228
print()
225229
loop = False
226-
else:
230+
elif not bld_done:
227231
onFirst = False
228232
print(keys[editCol-1:],end="")
229233
if len(keys[editCol-1:]) > 1:

0 commit comments

Comments
 (0)