Skip to content

Commit

Permalink
tools/flterm: remove serial.tools.miniterm dependency (console.getkey…
Browse files Browse the repository at this point in the history
…() was buggy on Linux: waiting for return)
enjoy-digital committed Feb 15, 2016
1 parent 8b7672e commit db3ef55
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions misoc/tools/flterm.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,32 @@
import threading
import argparse

from serial.tools.miniterm import console, character, LF

if sys.platform == "win32":
def getkey():
import msvcrt
return msvcrt.getch()
else:
def getkey():
import termios
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
new[6][termios.VMIN] = 1
new[6][termios.VTIME] = 0
termios.tcsetattr(fd, termios.TCSANOW, new)
c = None
try:
c = os.read(fd, 1)
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, old)
return c


def character(b):
return b.decode('latin1')


sfl_prompt_req = "F7: boot from serial\n"
sfl_prompt_ack = "\x06"
@@ -259,14 +284,14 @@ def writer(self):
try:
while self.writer_alive:
try:
b = console.getkey()
b = getkey()
except KeyboardInterrupt:
b = serial.to_bytes([3])
c = character(b)
if c == chr(0x03):
self.stop()
elif c == '\n':
self.serial.write(LF)
self.serial.write(serial.to_bytes([10]))
else:
self.serial.write(b)
except:

0 comments on commit db3ef55

Please sign in to comment.