File tree 1 file changed +28
-3
lines changed
1 file changed +28
-3
lines changed Original file line number Diff line number Diff line change 7
7
import threading
8
8
import argparse
9
9
10
- from serial .tools .miniterm import console , character , LF
10
+
11
+ if sys .platform == "win32" :
12
+ def getkey ():
13
+ import msvcrt
14
+ return msvcrt .getch ()
15
+ else :
16
+ def getkey ():
17
+ import termios
18
+ fd = sys .stdin .fileno ()
19
+ old = termios .tcgetattr (fd )
20
+ new = termios .tcgetattr (fd )
21
+ new [3 ] = new [3 ] & ~ termios .ICANON & ~ termios .ECHO
22
+ new [6 ][termios .VMIN ] = 1
23
+ new [6 ][termios .VTIME ] = 0
24
+ termios .tcsetattr (fd , termios .TCSANOW , new )
25
+ c = None
26
+ try :
27
+ c = os .read (fd , 1 )
28
+ finally :
29
+ termios .tcsetattr (fd , termios .TCSAFLUSH , old )
30
+ return c
31
+
32
+
33
+ def character (b ):
34
+ return b .decode ('latin1' )
35
+
11
36
12
37
sfl_prompt_req = "F7: boot from serial\n "
13
38
sfl_prompt_ack = "\x06 "
@@ -259,14 +284,14 @@ def writer(self):
259
284
try :
260
285
while self .writer_alive :
261
286
try :
262
- b = console . getkey ()
287
+ b = getkey ()
263
288
except KeyboardInterrupt :
264
289
b = serial .to_bytes ([3 ])
265
290
c = character (b )
266
291
if c == chr (0x03 ):
267
292
self .stop ()
268
293
elif c == '\n ' :
269
- self .serial .write (LF )
294
+ self .serial .write (serial . to_bytes ([ 10 ]) )
270
295
else :
271
296
self .serial .write (b )
272
297
except :
You can’t perform that action at this time.
0 commit comments