-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuttons.py
More file actions
37 lines (30 loc) · 782 Bytes
/
Copy pathbuttons.py
File metadata and controls
37 lines (30 loc) · 782 Bytes
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
import RPi.GPIO as gpio
import os
from time import clock
REBOOT_PIN = 22
thresh = 0.3
gpio.setmode(gpio.BCM)
gpio.setup(REBOOT_PIN, gpio.IN, pull_up_down = gpio.PUD_UP)
def Shutdown(channel):
os.system("sudo shutdown -h now")
def Reboot(channel):
os.system("sudo reboot")
mutt = 0
lastClock = 0
def Butt(channel):
global mutt, lastClock, thresh
if gpio.input(REBOOT_PIN):
if mutt == 2:
print "ignore doubled stop"
return # was already stop, so something is fucked up
else:
if (clock() - lastClock) > thresh:
Reboot(channel)
else:
Shutdown(channel)
mutt = 2 #rising (stop)
else:
print "start"
mutt = 1 #falling (start)
lastClock = clock()
gpio.add_event_detect(REBOOT_PIN, gpio.BOTH, callback = Butt)