-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (42 loc) · 1.27 KB
/
Copy pathmain.py
File metadata and controls
51 lines (42 loc) · 1.27 KB
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
from hvac import Sensor, Controller, Environment
from graph import Graph
from init import retrieve_args
from time import sleep
import curses
def get_target_temp(stdscr, prompt):
stdscr.clear()
curses.echo()
stdscr.addstr(0, 0, prompt)
stdscr.refresh()
temp = int(stdscr.getstr(0, len(prompt), 3))
curses.noecho()
return temp
def main(stdscr):
args = retrieve_args()
Environment.temperature = args.init
dt = args.time
sensor = Sensor()
controller = Controller()
graph = Graph(title=f'Temperature of the system with respect to time', winsize=(12, 6),
xlabel='time', ylabel='temperature')
while True:
stdscr.nodelay(0)
controller.change_target(get_target_temp(stdscr, "Enter target: "))
while True:
stdscr.nodelay(1)
key = stdscr.getch()
if key == ord('q'):
return
if key == 27:
break
controller.regulate(sensor.temperature())
graph.plot(sensor.history, controller.target, dt,
legend1='temperature', legend2='target')
sleep(dt)
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
main(stdscr)
curses.nocbreak()
curses.echo()
curses.endwin()