class Control(object): size = 1 def __init__ ( self, name, base, memory, conf, core) : from pyjoy import Controller self.memory = memory self.port = conf[name]["port"] self.c = Controller(self.port) self.core = core self.active = True self.t = threading.Thread(target=self.mov) self.t.start() def writeByte(self, address, value): pass def mov(self): while self.active: t = self.c.buttons() ta = self.c.axes() #arriba, derecha, abajo, izquierda dir = [0, 0, 0, 0] if t[4] == 1 or (ta[1] >= -32767 and ta[1] < 0): dir[0] = 1 if t[6] == 1 or (ta[1] > 0 and ta[1] <= 32767): dir[2] = 1 if t[5] == 1 or (ta[0] > 0 and ta[0] <= 32767): dir[1] = 1 if t[7] == 1 or (ta[0] >= -32767 and ta[0] < 0): dir[3] = 1 if dir[0] and dir[1]: result = 1 elif dir[1] and dir[2]: result = 3 elif dir[2] and dir[3]: result = 5 elif dir[3] and dir[0]: result = 7 elif dir[0]: result = 0 elif dir[1]: result = 2 elif dir[2]: result = 4 elif dir[3]: result = 6 else: result = -1 self.memory.writeByte(0,result) time.sleep(0.05) def __del__(self): self.active = False
def __init__ ( self, name, base, memory, conf, core) : from pyjoy import Controller self.memory = memory self.port = conf[name]["port"] self.c = Controller(self.port) self.core = core self.active = True self.t = threading.Thread(target=self.mov) self.t.start()
from pyjoy import Controller c = Controller("/dev/input/js0") while True: print c.buttons() print c.axes()