Skip to content

Instantly share code, notes, and snippets.

@e-minguez
Last active April 7, 2016 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e-minguez/66bcddc971fb9305079d318c7d387fec to your computer and use it in GitHub Desktop.
Save e-minguez/66bcddc971fb9305079d318c7d387fec to your computer and use it in GitHub Desktop.
#!/bin/python
import os
import time
import RPi.GPIO as GPIO
# set GPIO pin 7 as output
GPIO.setmode(GPIO.BCM)
GPIO.setup(7, GPIO.OUT)
GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)
def Shutdown(channel):
os.system("sudo shutdown -h now")
GPIO.add_event_detect(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
while True:
found = False
time.sleep(5)
pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
for pid in pids:
try:
cmd = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read()
if "gimx" in cmd:
found = True
except IOError: # proc has already terminated
continue
if found == True:
GPIO.output(7, True)
else
GPIO.output(7, False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment