-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushbuttons.py
executable file
·58 lines (53 loc) · 1.77 KB
/
pushbuttons.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
#!/usr/bin/python
#
# pushbuttons.py LCD TFT push button controls
# version 0.0.1
# author Brian Walter @briantwalter
# description Simple loop control for the 4 buttons on the top of
# of the Adafuit touch panel LCD for the RPi
#
import time
import subprocess
import RPi.GPIO as GPIO
from daemon import runner
# button logic
def main():
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(27,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(22,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(23,GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
input_state18 = GPIO.input(18)
if input_state18 == False:
# shutdown the system
subprocess.call('/sbin/shutdown -h now', shell=True)
input_state27 = GPIO.input(27)
if input_state27 == False:
# reboot the system
subprocess.call('/sbin/reboot', shell=True)
input_state22 = GPIO.input(22)
if input_state22 == False:
# toggle display on and off
subprocess.call('/var/local/bin/backlight.sh toggle', shell=True)
input_state23 = GPIO.input(23)
if input_state23 == False:
# display random 320x240 picture
subprocess.call('/var/local/bin/splashimg.sh catfact', shell=True)
time.sleep(0.1)
GPIO.cleanup()
# daemon properties
class App():
def __init__(self):
self.stdin_path = '/dev/null'
self.stdout_path = '/var/local/log/pushbuttons.log'
self.stderr_path = '/var/local/log/pushbuttons.log'
self.pidfile_path = '/tmp/pushbuttons.pid'
self.pidfile_timeout = 5
def run(self):
main()
# execute the app according to argument
app = App()
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()