-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputs_deamon.py
More file actions
executable file
·105 lines (90 loc) · 3.48 KB
/
inputs_deamon.py
File metadata and controls
executable file
·105 lines (90 loc) · 3.48 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from cpu_temp import get_cpu_temperature
from os import system
import RPi.GPIO as gpio
from time import sleep
gpio.setmode(gpio.BCM)
temp_regulation = False
switchPin = 17
switchPin2 = 24
switchPin3 = 23
gpio.setup(switchPin, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setup(switchPin2, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setup(switchPin3, gpio.IN, pull_up_down=gpio.PUD_UP)
system('export DISPLAY=:0.0')
system('export LC_CTYPE="en_US.UTF-8"')
#system('sudo /home/paul/Documents/ethernet_leds l0 f1')
switchState = gpio.input(switchPin)
switchState2 = gpio.input(switchPin2)
switchState3 = gpio.input(switchPin3)
if switchState3:
temp_regulation = True
def switchCallback(channel):
sleep(0.5)
global switchState
if gpio.input(switchPin) != switchState:
switchState = not switchState
if switchState:
#system('sudo /home/paul/Documents/ethernet_leds l1 f1')
if 256 == system('pidof Xorg'):
system('startx&')
sleep(10)
system('pkill -f control_center.py')
system('pkill -f uxterm')
system('pkill -f start_control_center.sh')
system('pkill -f chromium-browser')
system('/home/paul/Documents/start_control_center.sh&')
else:
#system('sudo /home/paul/Documents/ethernet_leds l0 f1')
system('pkill -f control_center.py')
system('pkill -f uxterm')
system('pkill -f chromium-browser')
system('pkill -f start_control_center.sh')
system('pkill -f start_control_center_octoprint.sh')
def switchCallback2(channel):
sleep(0.5)
global switchState2
if gpio.input(switchPin2) != switchState2:
switchState2 = not switchState2
if switchState2:
#system('sudo /home/paul/Documents/ethernet_leds l1 f1')
if 256 == system('pidof Xorg'):
system('startx&')
sleep(10)
system('pkill -f control_center.py')
system('pkill -f uxterm')
system('pkill -f start_control_center.sh')
system('pkill -f chromium-browser')
system('/home/paul/Documents/start_control_center_octoprint.sh&')
else:
#system('sudo /home/paul/Documents/ethernet_leds l0 f1')
system('pkill -f control_center.py')
system('pkill -f uxterm')
system('pkill -f chromium-browser')
system('pkill -f start_control_center.sh')
system('pkill -f start_control_center_octoprint.sh')
def switchCallback3(channel):
global temp_regulation
sleep(0.5)
global switchState3
if gpio.input(switchPin3) != switchState3:
switchState3 = not switchState3
if switchState3:
temp_regulation = True
temp = get_cpu_temperature()
if temp > 65:
system('echo 41 > /dev/arduino')
else:
temp_regulation = False
system('echo 40 > /dev/arduino')
gpio.add_event_detect(switchPin, gpio.BOTH, callback=switchCallback, bouncetime=300)
gpio.add_event_detect(switchPin2, gpio.BOTH, callback=switchCallback2, bouncetime=300)
gpio.add_event_detect(switchPin3, gpio.BOTH, callback=switchCallback3, bouncetime=300)
while True:
sleep(20)
if temp_regulation:
temp = get_cpu_temperature()
if temp > 65:
system('echo 41 > /dev/arduino')
elif temp < 55:
system('echo 40 > /dev/arduino')
gpio.cleanup()