@@ -15,15 +15,14 @@ def __init__(self):
15
15
self ._touched = False
16
16
_ADDRESS_KBD = 0x55
17
17
18
- self .lastCmdLine = ""
19
- self .commandHistory = []
18
+ self .commandHistory = ["" ]
20
19
21
20
self ._i2c = I2CDevice (Pydos_hw .I2C (), _ADDRESS_KBD )
22
21
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 )
27
26
}
28
27
self .click = keypad .Keys ([board .TRACKBALL_CLICK ], value_when_pressed = False )
29
28
@@ -81,10 +80,15 @@ def input(disp_text=None):
81
80
if disp_text != None :
82
81
print (disp_text ,end = "" )
83
82
83
+ bld_chr1 = '_(+'
84
+ bld_chr2 = '-+)'
85
+ bld_chr = '=[]'
86
+ bld_started = [False , False , False ]
87
+
88
+ histPntr = len (Pydos_ui .commandHistory )
89
+
84
90
keys = ''
85
91
editCol = 0
86
- histPntr = len (Pydos_ui .commandHistory )
87
- currEditLine = Pydos_ui .lastCmdLine
88
92
loop = True
89
93
ctrlkeys = ''
90
94
arrow = ''
@@ -95,73 +99,66 @@ def input(disp_text=None):
95
99
96
100
while loop :
97
101
#print(editCol,keys)
98
- # Find the last direction the trackball was moved
99
- # and wait for trackball to stop moving
100
102
if ctrlkeys == '' :
101
103
arrow = ""
102
104
trackloop = True
103
105
else :
104
106
ctrlkeys = ''
105
107
trackloop = False
106
108
109
+ # Find the last direction the trackball was moved
110
+ # and wait for trackball to stop moving
107
111
largestDir = 0
108
112
while trackloop :
109
113
trackloop = False
110
114
for p ,c in Pydos_ui .trackball .items ():
111
115
if c .count > largestDir :
112
116
trackloop = True
113
- arrow = p
114
- largestDir = c .count
117
+ if p not in "AB" or onLast :
118
+ arrow = p
119
+ largestDir = c .count
115
120
c .reset ()
116
121
else :
117
122
c .reset ()
118
123
if arrow != "" and not trackloop :
119
- # time.sleep(.2 )
124
+ time .sleep (.05 )
120
125
# clear all counters
121
126
for p ,c in Pydos_ui .trackball .items ():
122
127
if c .count > 0 :
123
128
c .reset ()
124
129
125
- if arrow == 'up ' :
130
+ if arrow == 'A' or arrow == 'B ' :
126
131
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 = "" )
128
133
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
140
138
141
- histPntr += 1
142
- if histPntr >= len (Pydos_ui .commandHistory ):
143
- histPntr = 0
139
+ histPntr = histPntr % len (Pydos_ui .commandHistory )
144
140
print (Pydos_ui .commandHistory [histPntr ],end = "" )
145
141
keys = Pydos_ui .commandHistory [histPntr ]
146
- currEditLine = keys
147
142
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' :
150
148
if len (keys ) > editCol :
151
149
print (keys [editCol :editCol + 1 ]+ "\x08 " ,end = "" )
152
150
elif editCol == len (keys ):
153
151
print (" \x08 " ,end = "" )
154
152
155
- editCol += 1
156
- editCol = max (0 ,editCol - 2 )
153
+ editCol = max (0 ,editCol - 1 )
157
154
if editCol > 0 :
158
155
print ('\x08 ' ,end = "" )
159
156
onLast = False
160
157
elif editCol == 0 :
161
158
if not onFirst :
162
159
print ('\x08 ' ,end = "" )
163
160
onFirst = True
164
- elif arrow == 'right ' :
161
+ elif arrow == 'C ' :
165
162
if len (keys ) > editCol :
166
163
print (keys [editCol :editCol + 1 ]+ "\x08 " ,end = "" )
167
164
@@ -175,30 +172,39 @@ def input(disp_text=None):
175
172
print (keys [editCol - 1 :],end = "" )
176
173
onLast = True
177
174
178
- if Pydos_ui .uart_bytes_available () or Pydos_ui . serial_bytes_available ():
175
+ if Pydos_ui .serial_bytes_available ():
179
176
if Pydos_ui .uart_bytes_available ():
180
177
keys = keys [:editCol ]+ stdin .read (1 )+ keys [editCol :]
181
178
editCol += 1
182
179
if keys [editCol - 1 ] == '\x1b ' :
183
180
keys = keys [:editCol - 1 ]+ keys [editCol :]
184
181
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 ]
197
184
else :
198
185
keys = keys [:editCol ]+ Pydos_ui .read_keyboard (1 )+ keys [editCol :]
199
186
editCol += 1
200
187
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 ' :
202
208
keys = keys [:max (0 ,editCol - 2 )]+ keys [editCol :]
203
209
if editCol > 1 :
204
210
print (('\x08 ' * (editCol - 1 ))+ keys + ' \x08 \x08 ' ,end = "" )
@@ -208,22 +214,20 @@ def input(disp_text=None):
208
214
else :
209
215
editCol -= 1
210
216
onFirst = True
211
- elif arrow == 'left' :
212
- editCol -= 1
213
- elif arrow == 'right' :
214
- editCol -= 1
215
217
elif len (keys [editCol - 1 :editCol ]) > 0 and keys [editCol - 1 :editCol ] in '\n \r ' :
216
218
if len (keys ) > editCol :
217
219
print (keys [editCol :editCol + 1 ]+ "\x08 " ,end = "" )
218
220
elif editCol == len (keys ):
219
221
print (" \x08 " ,end = "" )
220
222
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 )
224
228
print ()
225
229
loop = False
226
- else :
230
+ elif not bld_done :
227
231
onFirst = False
228
232
print (keys [editCol - 1 :],end = "" )
229
233
if len (keys [editCol - 1 :]) > 1 :
0 commit comments