From: pin Date: Fri, 2 Apr 2010 15:03:51 +0000 (+0000) Subject: pygame_wiitest.py en état de marche (à l'arrache tout de même). X-Git-Url: https://scm.cri.mines-paristech.fr/git/minwii.git/commitdiff_plain/b0768fef498066bcea9fa7155185c7845721b7a2 pygame_wiitest.py en état de marche (à l'arrache tout de même). git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@124 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/pywiiuse/pygame_wiimote.py b/src/pywiiuse/pygame_wiimote.py index 09ba3aa..5540430 100755 --- a/src/pywiiuse/pygame_wiimote.py +++ b/src/pywiiuse/pygame_wiimote.py @@ -51,8 +51,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 +63,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 +83,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 +107,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, diff --git a/src/pywiiuse/pygame_wiitest.py b/src/pywiiuse/pygame_wiitest.py index b9d6827..cc2e5ed 100755 --- a/src/pywiiuse/pygame_wiitest.py +++ b/src/pywiiuse/pygame_wiitest.py @@ -22,6 +22,7 @@ if n == 0: sys.exit(1) wm = pygame_wiimote.Wiimote(0) # access the wiimote object +wm.enable_ir(1) wm.enable_accels(1) # turn on acceleration reporting w,h = size = (512,512)