Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import RPi.GPIO as GPIO
- import os, time
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Reset switch
- GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Power switch
- GPIO.setup(25, GPIO.OUT) #ON control
- GPIO.output(25, GPIO.HIGH)
- def exitEmulator(channel):
- print('exitEmulator')
- pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
- for pid in pids:
- try:
- commandpath = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read()
- if commandpath[0:24] == '/opt/retropie/emulators/':
- os.system('kill -QUIT %s' % pid)
- print('kill -QUIT %s' % pid)
- except IOError:
- continue
- GPIO.add_event_detect(23, GPIO.FALLING, callback=exitEmulator, bouncetime=500)
- while True:
- if (GPIO.input(24)):
- time.sleep(0.25)
- else:
- print ("Shutting down...")
- os.system("sudo shutdown -h now")
- break
Add Comment
Please, Sign In to add comment