X-Git-Url: https://scm.cri.mines-paristech.fr/git/minwii.git/blobdiff_plain/a06a69f9abfb7ecc88ef153768e894415ae089fd..4986d1d41239a54cd13b490ad72c3dc99793c8e8:/src/pywiiuse/pygame_wiimote.py diff --git a/src/pywiiuse/pygame_wiimote.py b/src/pywiiuse/pygame_wiimote.py index 09ba3aa..26d9f9d 100755 --- a/src/pywiiuse/pygame_wiimote.py +++ b/src/pywiiuse/pygame_wiimote.py @@ -22,6 +22,7 @@ import time # events to use. Is there a way to get ones known to be unused? base = pygame.USEREVENT +print 'pygame_wiimote base :', pygame.USEREVENT WIIMOTE_BUTTON_PRESS = base + 1 WIIMOTE_BUTTON_RELEASE = base + 2 WIIMOTE_ACCEL = base + 3 @@ -32,6 +33,10 @@ NUNCHUK_ACCEL = base + 7 NUNCHUK_JOY = base + 8 WIIMOTE_STATUS = base + 9 WIIMOTE_DISCONNECT = base + 10 +pygame.USEREVENT = WIIMOTE_DISCONNECT +if pygame.USEREVENT > pygame.NUMEVENTS : + pygame.NUMEVENTS = pygame.USEREVENT + wiiuse = None # import within the thread, why do I have to do this? @@ -51,8 +56,7 @@ class wiimote_thread(Thread): '''This runs in a separate thread''' global wiiuse import PyWiiUse as wiiuse # import here to avoid thread problems on windows - self.wiimotes = wiiuse.init(self.nmotes, range(self.nmotes), self.event_cb, - self.control_cb, self.disconnect_cb) + self.wiimotes = wiiuse.init(self.nmotes) found = wiiuse.find(self.wiimotes, self.nmotes, self.timeout) self.actual_nmotes = wiiuse.connect(self.wiimotes, self.nmotes) @@ -64,10 +68,19 @@ class wiimote_thread(Thread): self.startup.put(self.go) while self.go: - try: - wiiuse.poll(self.wiimotes, self.nmotes) - except: + try : + if wiiuse.poll(self.wiimotes, self.nmotes) : + for i in range(self.nmotes): + m = self.wiimotes[i] + if m[0].event == wiiuse.EVENT: + self.event_cb(m) + except : pass + + #try: + # wiiuse.poll(self.wiimotes, self.nmotes) + #except: + # pass # allow executing functions in this thread while True: @@ -75,6 +88,7 @@ class wiimote_thread(Thread): func, args = self.queue.get_nowait() except Empty: break + print 'do:', func.__name__, args func(*args) def do(self, func, *args): @@ -98,14 +112,14 @@ class wiimote_thread(Thread): time=time.time(), id=wm.unid)) - if wiiuse.using_acc(wm): + if True: pygame.event.post(pygame.event.Event(WIIMOTE_ACCEL, orient=(wm.orient.roll, wm.orient.pitch, wm.orient.yaw), accel=(wm.gforce.x, wm.gforce.y, wm.gforce.z), time=time.time(), id=wm.unid)) - if wiiuse.using_ir(wm): + if True: dots = [ (wm.ir.dot[i].visible, wm.ir.dot[i].x, wm.ir.dot[i].y) for i in range(4) ] pygame.event.post(pygame.event.Event(WIIMOTE_IR, dots=dots,