@Substring thank you.
@all This is my working Script:
import RPi.GPIO as GPIO
import time
import socket
# addressing information of target
IPADDR = "127.0.0.1"
PORTNUM = 55355
# enter the data content of the UDP packet
# initialize a socket, think of it as a cable
# SOCK_DGRAM specifies that this is UDP
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except socket.error:
print 'Failed to create socket'
sys.exit()
GPIO.setmode(GPIO.BCM)
GPIO.setup(2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(9, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def exitEmulator(channel):
s.sendto("QUIT", (IPADDR, PORTNUM))
def resetEmulator(channel):
s.sendto("RESET", (IPADDR, PORTNUM))
def loadState(channel):
s.sendto("LOAD_STATE", (IPADDR, PORTNUM))
def saveState(channel):
s.sendto("SAVE_STATE", (IPADDR, PORTNUM))
def stateSlotPlus(channel):
s.sendto("STATE_SLOT_PLUS", (IPADDR, PORTNUM))
def stateSlotMinus(channel):
s.sendto("STATE_SLOT_MINUS", (IPADDR, PORTNUM))
def pauseEmulator(channel):
s.sendto("PAUSE_TOGGLE", (IPADDR, PORTNUM))
def takeScreenshot(channel):
s.sendto("SCREENSHOT", (IPADDR, PORTNUM))
def muteEmulator(channel):
s.sendto("MUTE", (IPADDR, PORTNUM))
def fastForward(channel):
s.sendto("FAST_FORWARD", (IPADDR, PORTNUM))
def fastForwardHold(channel):
s.sendto("FAST_FORWARD_HOLD", (IPADDR, PORTNUM))
GPIO.add_event_detect(2, GPIO.FALLING, callback=exitEmulator, bouncetime=500)
GPIO.add_event_detect(3, GPIO.FALLING, callback=resetEmulator, bouncetime=500)
GPIO.add_event_detect(4, GPIO.FALLING, callback=loadState, bouncetime=500)
GPIO.add_event_detect(5, GPIO.FALLING, callback=saveState, bouncetime=500)
GPIO.add_event_detect(6, GPIO.FALLING, callback=stateSlotPlus, bouncetime=500)
GPIO.add_event_detect(7, GPIO.FALLING, callback=stateSlotMinus, bouncetime=500)
GPIO.add_event_detect(8, GPIO.FALLING, callback=takeScreenshot, bouncetime=500)
GPIO.add_event_detect(9, GPIO.FALLING, callback=muteEmulator, bouncetime=500)
GPIO.add_event_detect(10, GPIO.FALLING, callback=fastForward, bouncetime=500)
GPIO.add_event_detect(11, GPIO.FALLING, callback=fastForwardHold, bouncetime=500)
while True:
time.sleep(10)