2020-12-10 18:59:14 +01:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
""" @package docstring
|
|
|
|
ARDUINO PARALLEL TERMINAL EMULATOR
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
Connect the arduino to a Pat80 I/O port.
|
|
|
|
Flash /arduino/arduino_terminal firmware into the Arduino.
|
|
|
|
Connect the Arduino to a PC via USB and power on Pat80
|
|
|
|
Run this program providing the Arduino USB port
|
|
|
|
|
|
|
|
DISCLAIMER:
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import serial
|
2020-12-10 23:47:19 +01:00
|
|
|
import curses
|
2020-12-10 18:59:14 +01:00
|
|
|
import time
|
|
|
|
|
|
|
|
class TerminalEmulator:
|
2020-12-11 08:48:30 +01:00
|
|
|
def __init__(self, w, ser):
|
2020-12-10 23:47:19 +01:00
|
|
|
w.clear()
|
2020-12-11 08:48:30 +01:00
|
|
|
w.move(0,0)
|
2020-12-10 18:59:14 +01:00
|
|
|
while True:
|
2020-12-10 23:47:19 +01:00
|
|
|
'''try:
|
|
|
|
# read key and write to serial port
|
|
|
|
key = w.getkey()
|
|
|
|
ser.write(key)
|
|
|
|
except Exception as e:
|
|
|
|
# No input
|
2020-12-11 08:48:30 +01:00
|
|
|
pass'''
|
|
|
|
|
2020-12-10 23:47:19 +01:00
|
|
|
# read serial port and write to curses
|
|
|
|
if ser.inWaiting():
|
2020-12-11 08:48:30 +01:00
|
|
|
b = ser.read(1)
|
|
|
|
if ord(b) > 31:
|
|
|
|
w.addch(b)
|
|
|
|
|
|
|
|
stdscr.refresh()
|
2020-12-10 18:59:14 +01:00
|
|
|
|
2020-12-10 23:47:19 +01:00
|
|
|
|
2020-12-10 18:59:14 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('port', help="arduino parallel monitor USB port")
|
|
|
|
parser.add_argument('baudrate', help="arduino parallel monitor USB baudrate")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-12-10 23:47:19 +01:00
|
|
|
# Init curses
|
|
|
|
stdscr = curses.initscr()
|
|
|
|
curses.noecho()
|
|
|
|
curses.cbreak()
|
2020-12-11 08:48:30 +01:00
|
|
|
stdscr.idlok(True)
|
|
|
|
stdscr.scrollok(True)
|
2020-12-10 23:47:19 +01:00
|
|
|
|
|
|
|
try:
|
2020-12-11 08:48:30 +01:00
|
|
|
ser = serial.Serial(args.port, args.baudrate, timeout=0)
|
|
|
|
td = TerminalEmulator(stdscr, ser)
|
2020-12-10 23:47:19 +01:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
finally:
|
2020-12-11 08:48:30 +01:00
|
|
|
# Close serial
|
|
|
|
ser.close()
|
2020-12-10 23:47:19 +01:00
|
|
|
# Stop curses
|
|
|
|
curses.nocbreak()
|
|
|
|
curses.echo()
|
|
|
|
curses.endwin()
|
|
|
|
|