11
11
class PyDOS_UI :
12
12
13
13
def __init__ (self ):
14
+ self .scrollable = False
15
+ self .arrow = ""
16
+ self ._cmdhistlock = False
17
+ self ._seqCnt = 0
14
18
self ._key = bytearray (1 )
15
19
self ._touched = False
16
20
_ADDRESS_KBD = 0x55
@@ -27,26 +31,48 @@ def __init__(self):
27
31
self .click = keypad .Keys ([board .TRACKBALL_CLICK ], value_when_pressed = False )
28
32
29
33
def get_screensize (self ):
30
- #return (round(self._display.height*.04),round(self._display.width*.0817))
31
- #return (
32
- # round(self._display.height/(terminalio.FONT.bitmap.height*displayio.CIRCUITPYTHON_TERMINAL.scale))-1,
33
- # round(self._display.width/((terminalio.FONT.bitmap.width/95)*displayio.CIRCUITPYTHON_TERMINAL.scale))-1
34
- #)
35
- return (19 ,53 )
34
+ return (19 ,51 )
36
35
37
36
def serial_bytes_available (self ):
38
37
if not self ._touched :
39
38
retval = 0
40
- with self ._i2c as i2c :
41
- try :
42
- i2c .readinto (self ._key )
43
- except :
44
- self ._key = bytearray (1 )
45
- if self ._key [0 ] != 0 :
46
- retval = 1
47
- self ._touched = True
48
- else :
49
- retval = self .uart_bytes_available ()
39
+
40
+ # Find the last direction the trackball was moved
41
+ # and wait for trackball to stop moving
42
+ largestDir = 0
43
+ self .arrow = ''
44
+ trackloop = True
45
+ while trackloop :
46
+ trackloop = False
47
+ for p ,c in Pydos_ui .trackball .items ():
48
+ if c .count > largestDir :
49
+ trackloop = True
50
+ if p not in "AB" or not self ._cmdhistlock :
51
+ self .arrow = p
52
+ largestDir = c .count
53
+ c .reset ()
54
+ else :
55
+ c .reset ()
56
+ if self .arrow != "" and not trackloop :
57
+ time .sleep (.05 )
58
+ # clear all counters
59
+ for p ,c in Pydos_ui .trackball .items ():
60
+ if c .count > 0 :
61
+ c .reset ()
62
+ retval = 1
63
+ self ._touched = True
64
+
65
+ if not self ._touched :
66
+ with self ._i2c as i2c :
67
+ try :
68
+ i2c .readinto (self ._key )
69
+ except :
70
+ self ._key = bytearray (1 )
71
+ if self ._key [0 ] != 0 :
72
+ retval = 1
73
+ self ._touched = True
74
+ else :
75
+ retval = self .uart_bytes_available ()
50
76
else :
51
77
retval = 1
52
78
@@ -63,13 +89,29 @@ def read_keyboard(self,num):
63
89
while num > 0 :
64
90
self .serial_bytes_available ()
65
91
if self ._touched :
66
- retval = chr (self ._key [0 ])
67
- self ._touched = False
68
- num -= 1
92
+ if self .arrow != "" :
93
+ if self ._seqCnt == 0 :
94
+ retval += chr (27 )
95
+ self ._seqCnt = 1
96
+ num -= 1
97
+ elif self ._seqCnt == 1 :
98
+ retval += chr (91 )
99
+ self ._seqCnt = 2
100
+ num -= 1
101
+ elif self ._seqCnt == 2 :
102
+ retval += self .arrow
103
+ self ._seqCnt = 0
104
+ self ._touched = False
105
+ self .arrow = ""
106
+ num -= 1
107
+ else :
108
+ retval += chr (self ._key [0 ])
109
+ self ._touched = False
110
+ num -= 1
69
111
else :
70
112
if self .uart_bytes_available ():
71
- retval = stdin .read (1 )
72
- num -= 1
113
+ retval = stdin .read (num )
114
+ num -= len ( retval )
73
115
74
116
return retval
75
117
@@ -86,6 +128,7 @@ def input(disp_text=None):
86
128
bld_started = False
87
129
88
130
histPntr = len (Pydos_ui .commandHistory )
131
+ Pydos_ui ._cmdhistlock = False
89
132
90
133
keys = ''
91
134
editCol = 0
@@ -101,31 +144,8 @@ def input(disp_text=None):
101
144
#print(editCol,keys)
102
145
if ctrlkeys == '' :
103
146
arrow = ""
104
- trackloop = True
105
147
else :
106
148
ctrlkeys = ''
107
- trackloop = False
108
-
109
- # Find the last direction the trackball was moved
110
- # and wait for trackball to stop moving
111
- largestDir = 0
112
- while trackloop :
113
- trackloop = False
114
- for p ,c in Pydos_ui .trackball .items ():
115
- if c .count > largestDir :
116
- trackloop = True
117
- if p not in "AB" or onLast :
118
- arrow = p
119
- largestDir = c .count
120
- c .reset ()
121
- else :
122
- c .reset ()
123
- if arrow != "" and not trackloop :
124
- time .sleep (.05 )
125
- # clear all counters
126
- for p ,c in Pydos_ui .trackball .items ():
127
- if c .count > 0 :
128
- c .reset ()
129
149
130
150
if arrow == 'A' or arrow == 'B' :
131
151
if len (Pydos_ui .commandHistory ) > 0 :
@@ -145,6 +165,7 @@ def input(disp_text=None):
145
165
else :
146
166
onFirst = False
147
167
elif arrow == 'D' :
168
+ Pydos_ui ._cmdhistlock = True
148
169
if len (keys ) > editCol :
149
170
print (keys [editCol :editCol + 1 ]+ "\x08 " ,end = "" )
150
171
elif editCol == len (keys ):
@@ -171,19 +192,23 @@ def input(disp_text=None):
171
192
if not onLast :
172
193
print (keys [editCol - 1 :],end = "" )
173
194
onLast = True
195
+ Pydos_ui ._cmdhistlock = False
174
196
175
197
if Pydos_ui .serial_bytes_available ():
176
198
if Pydos_ui .uart_bytes_available ():
177
199
keys = keys [:editCol ]+ stdin .read (1 )+ keys [editCol :]
178
- editCol += 1
179
- if keys [editCol - 1 ] == '\x1b ' :
180
- keys = keys [:editCol - 1 ]+ keys [editCol :]
181
- ctrlkeys = stdin .read (2 )
182
- # ctrlkeys = up:[A down:[B right:[C left:[D
183
- arrow = ctrlkeys [1 ]
184
200
else :
185
201
keys = keys [:editCol ]+ Pydos_ui .read_keyboard (1 )+ keys [editCol :]
186
- editCol += 1
202
+
203
+ editCol += 1
204
+ if keys [editCol - 1 ] == '\x1b ' :
205
+ keys = keys [:editCol - 1 ]+ keys [editCol :]
206
+ if Pydos_ui .uart_bytes_available ():
207
+ ctrlkeys = stdin .read (2 )
208
+ else :
209
+ ctrlkeys = Pydos_ui .read_keyboard (2 )
210
+ # ctrlkeys = up:[A down:[B right:[C left:[D
211
+ arrow = ctrlkeys [1 ]
187
212
188
213
# Convert two character sequences into missing keyboard keys
189
214
# '_-' -> '=' '(+' -> '[' '+)' -> ']'
@@ -197,6 +222,8 @@ def input(disp_text=None):
197
222
print ('\x08 ' + keys [editCol - 2 :]+ ' ' + ('\x08 ' * (len (keys [editCol :])+ (1 if onLast else 2 ))),end = "" )
198
223
editCol -= 1
199
224
bld_done = True
225
+ elif bld_chr1 .find (keys [editCol - 1 :editCol ]) != - 1 and arrow == "" :
226
+ bld_started = True
200
227
else :
201
228
bld_started = False
202
229
0 commit comments