-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemp_sim.py
executable file
·65 lines (56 loc) · 1.78 KB
/
temp_sim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
import tty, termios
import sys
import serial
import argparse
try:
from msvcrt import getch # try to import Windows version
except ImportError:
def getch(): # define non-Windows version
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
class TempSim(object):
def __init__(self, cmd):
self.cmd = cmd
# Start at room temp.
self.temp = 20
def mod(self, delta):
self.temp += delta
ser.write(f'{self.cmd} {self.temp}\r\n'.encode('utf-8'))
print(f'\rMain: {temp_main.temp} Aft: {temp_aft.temp}' + ' ' * 10 + '\r', end='')
temp_main = TempSim('TM')
temp_aft = TempSim('TA')
def main():
while True:
char = getch()
if char == 'q' or char == '\x1b': # x1b is ESC
exit()
if char == 'e':
temp_main.mod(-100)
if char == 'r':
temp_main.mod(100)
if char == 'd':
temp_main.mod(-10)
if char == 'f':
temp_main.mod(10)
if char == 'u':
temp_aft.mod(-100)
if char == 'i':
temp_aft.mod(100)
if char == 'j':
temp_aft.mod(-10)
if char == 'k':
temp_aft.mod(10)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Incinerator temperature simulator')
parser.add_argument('port', help='serial port')
parser.add_argument('-b', '--baud', help='baud rate', type=int, default=115200)
args = parser.parse_args()
ser = serial.Serial(port=args.port, baudrate=args.baud, exclusive=True)
main()