-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrontpanel_function.py
More file actions
98 lines (66 loc) · 2.17 KB
/
frontpanel_function.py
File metadata and controls
98 lines (66 loc) · 2.17 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
import RPi.GPIO as GPIO
import os
import time
import psutil
from threading import Timer
pin_sw2 = 26
pin_d3 = 19
pin_d1 = 16
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin_d3, GPIO.OUT)
GPIO.setup(pin_d1, GPIO.OUT)
GPIO.setup(pin_sw2, GPIO.IN)
class RepeatTimer(Timer):
def run(self):
while not self.finished.wait(self.interval):
self.function(*self.args, **self.kwargs)
obj_Disk_old_size = 0
obj_Disk_new_size = 0
def buttonPress(channel):
global buttonStatus
global obj_Disk_new, obj_Disk_old, pin_d1, pin_d3, pin_d1
start_time = time.time()
while GPIO.input(channel) == 0: # Wait for the button up
pass
buttonTime = time.time() - start_time # How long was the button down?
if .1 <= buttonTime < 2:
print("reboot")
os.system('sudo reboot')
elif 2 <= buttonTime :
print("shutdown")
GPIO.output(pin_d1,False)
time.sleep(0.4)
GPIO.output(pin_d1,True)
time.sleep(0.4)
os.system('sudo shutdown now')
def checkForHDDChange():
global obj_Disk_old_size, obj_Disk_new_size, pin_d1, pin_d3, pin_d1
try:
obj_Disk_new = psutil.disk_usage('/media/USBdrive/ncdata')
obj_Disk_new_size = obj_Disk_new.used
except Exception:
for i in range(5):
GPIO.output(pin_d3,True)
time.sleep(0.1)
GPIO.output(pin_d3,False)
time.sleep(0.1)
print("ERROR: Nextcloud festplatte nicht gefunden")
if obj_Disk_new_size != obj_Disk_old_size :
print("HDD changed")
GPIO.output(pin_d3,True)
time.sleep(0.3)
GPIO.output(pin_d3,False)
time.sleep(0.3)
obj_Disk_old_size = obj_Disk_new_size
GPIO.add_event_detect(pin_sw2, GPIO.FALLING, callback=buttonPress, bouncetime=500)
def main():
global obj_Disk_new, obj_Disk_old, pin_d1, pin_d3, pin_d1
print("Frontpanel aktiv")
GPIO.output(pin_d1,True) #turn on main power light and pull up for switch
hddCheckTimer = RepeatTimer(2, checkForHDDChange)
hddCheckTimer.start()
while(True):
pass
if __name__ == "__main__":
main()