SHOW:
|
|
- or go back to the newest paste.
1 | #!/usr/bin/python | |
2 | import RPi.GPIO as GPIO | |
3 | import os, time | |
4 | ||
5 | GPIO.setmode(GPIO.BCM) | |
6 | GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Reset switch | |
7 | GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Power switch | |
8 | GPIO.setup(25, GPIO.OUT) #ON control | |
9 | GPIO.output(25, GPIO.HIGH) | |
10 | ||
11 | def exitEmulator(channel): | |
12 | print('exitEmulator') | |
13 | pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] | |
14 | ||
15 | for pid in pids: | |
16 | try: | |
17 | commandpath = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read() | |
18 | if commandpath[0:24] == '/opt/retropie/emulators/': | |
19 | os.system('kill -QUIT %s' % pid) | |
20 | print('kill -QUIT %s' % pid) | |
21 | except IOError: | |
22 | continue | |
23 | GPIO.add_event_detect(23, GPIO.FALLING, callback=exitEmulator, bouncetime=500) | |
24 | ||
25 | while True: | |
26 | if (GPIO.input(24)): | |
27 | time.sleep(0.25) | |
28 | else: | |
29 | print ("Shutting down...") | |
30 | os.system("sudo shutdown -h now") | |
31 | break |