-
Notifications
You must be signed in to change notification settings - Fork 0
/
WRM.py
66 lines (55 loc) · 1.62 KB
/
WRM.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
66
import screen as S
import DS18B20 as D
import therm as T
import scheduler_xml as Scheduler
import sys
import time
def main(verbose=False):
t_sensor = None
screen = None
thermostat = None
scheduler = None
try:
t_sensor = D.TempSensor()
except Exception as ex:
print("Cannot reach the sensor, check wiring. Aborting..")
print(ex)
try:
scheduler = Scheduler.SchedManager()
except Exception as ex:
print("A problem occurs while initialising Scheduler obj.")
print(ex)
# Create and init Screen
if t_sensor is not None and scheduler is not None:
try:
thermostat = T.Thermostat(t_sensor, scheduler, verbose)
screen = S.Screen(t_sensor, scheduler, verbose)
except Exception as ex:
print(ex)
try:
if thermostat is not None:
thermostat.start()
if screen is not None:
#screen.setParam(t_sensor.get_temp(), 20, 1)
screen.start()
while True:
time.sleep(1)
except (Exception, KeyboardInterrupt) as ex:
print("Exiting, raised exception.")
print(ex)
screen.stop()
thermostat.stop()
screen.join()
thermostat.join()
print("Everything ok.")
if screen.is_alive():
screen.stop()
screen.join()
if thermostat.is_alive():
thermostat.stop()
thermostat.join()
if __name__ == "__main__":
if len(sys.argv) == 1:
main()
if len(sys.argv) == 2 and (sys.argv[1] == "v"):
main(True)