-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset_button.py
More file actions
executable file
·34 lines (29 loc) · 932 Bytes
/
Copy pathreset_button.py
File metadata and controls
executable file
·34 lines (29 loc) · 932 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
#!/usr/bin/env python2.7
import RPi.GPIO as GPIO
import subprocess
import time
# GPIO chanel for Reset Button
# By default is GP23
chanel = 23
# Pressing time for system reboot
delaySystemReset = 2000
def waitForPress():
while True:
GPIO.wait_for_edge(chanel, GPIO.FALLING)
# Short press for stop running emulator and return to Emulationstation
subprocess.call("pkill retroarch && nohup emulationstation && pkill mupen64plus &", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
timePush = round(time.time() * 1000)
timePresses = 0
while GPIO.input(chanel) == GPIO.LOW:
timePressed = round(time.time() * 1000) - timePush
if timePressed >= delaySystemReset:
# When long press
# System reboot
subprocess.call("reboot")
GPIO.cleanup()
break
if __name__ == '__main__':
GPIO.setmode(GPIO.BCM)
GPIO.setup(chanel, GPIO.IN, pull_up_down=GPIO.PUD_UP)
waitForPress()