-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
73 lines (55 loc) · 1.36 KB
/
Main.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
67
68
69
70
71
72
73
from LED import led as led
from Website import web as site
import config
import os
import psutil
from Arduinocode import pythonCode as arduino
import threading
import time
count = 0
#Thread for running the led strip
def worker():
config.init()
arduino.init()
led.initLED()
print('did init')
while True:
try:
time.sleep(config.wait)
config.functdict[config.function]()
except:
time.sleep(1)
measure_pi()
return None
def arduinoWorker():
while True:
try:
time.sleep(config.wait)
if config.synced:
config.color_rgb_arduino = config.color_rgb
arduino.main()
except:
pass
return None
def measure_pi():
config.temperature = os.popen("vcgencmd measure_temp").readline().replace("temp=","")
config.cpu_load = psutil.cpu_percent(interval=0, percpu = False)
return None
CheckThread = threading.Thread(target=worker)
CheckThread.daemon = True
CheckThread.start()
ArduinoThread = threading.Thread(target=arduinoWorker)
ArduinoThread.daemon = True
ArduinoThread.start()
#Try to start the website when init() is done. Try it for 10 times then stop.
while count < 10:
try:
if config.run:
site.app.run(debug=False, host='0.0.0.0')
count = 10
except:
print('Waiting for INIT to complete')
time.sleep(1)
count +=1
print('Exiting code')
arduino.Exit()