Skip to content

Commit db3ef55

Browse files
committedFeb 15, 2016
tools/flterm: remove serial.tools.miniterm dependency (console.getkey() was buggy on Linux: waiting for return)
1 parent 8b7672e commit db3ef55

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed
 

‎misoc/tools/flterm.py

+28-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,32 @@
77
import threading
88
import argparse
99

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+
1136

1237
sfl_prompt_req = "F7: boot from serial\n"
1338
sfl_prompt_ack = "\x06"
@@ -259,14 +284,14 @@ def writer(self):
259284
try:
260285
while self.writer_alive:
261286
try:
262-
b = console.getkey()
287+
b = getkey()
263288
except KeyboardInterrupt:
264289
b = serial.to_bytes([3])
265290
c = character(b)
266291
if c == chr(0x03):
267292
self.stop()
268293
elif c == '\n':
269-
self.serial.write(LF)
294+
self.serial.write(serial.to_bytes([10]))
270295
else:
271296
self.serial.write(b)
272297
except:

0 commit comments

Comments
 (0)
Please sign in to comment.