@Substring try this:
import RPi.GPIO as GPIO
import time
import os
import thread
import datetime
import socket
import sys
from datetime import datetime
from configgen import recalboxFiles
# this last one retrieves emulators bin names
IPADDR = "127.0.0.1"
PORTNUM = 55355
# IP and port for retroarch network commands
QUIT = 3
GPIO.setwarnings(False) # no warnings
GPIO.setmode(GPIO.BCM) # set up BCM GPIO numbering
GPIO.setup(QUIT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# GPIO on pin 3 is the GPIO 2 in BCM mode
#to Reset+
# Define a threaded callback function to run in another thread when events are detected
def button_pressed(channel):
nwcommand="QUIT"
retroarch(nwcommand)
killthats**t(channel)
# on quit press, trying to kill all listed emus
def killthats**t(channel):
if channel == QUIT:
for bin in recalboxFiles.recalboxBins:
print bin
proc = os.path.basename(bin)
print proc
os.system("killall -9 "+proc)
# sending network command to retroarch (only exit and reset atm)
def retroarch(nwcommand):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except socket.error:
print 'Failed to create socket'
sys.exit()
s.sendto(nwcommand, (IPADDR, PORTNUM))
GPIO.add_event_detect(QUIT, GPIO.BOTH, callback=button_pressed, bouncetime=2)
while True:
time.sleep(0.2)