From: pin Date: Mon, 12 Apr 2010 09:17:20 +0000 (+0000) Subject: Ok pour le fonctionnement avec plusieurs wiimotes. X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/commitdiff_plain/30e36fe2e442924342ce39d3217002ff0d222f35?ds=sidebyside Ok pour le fonctionnement avec plusieurs wiimotes. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@138 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/app/minwii.py b/src/app/minwii.py index 4f29319..d75dd5e 100755 --- a/src/app/minwii.py +++ b/src/app/minwii.py @@ -27,29 +27,28 @@ class MinWii(object): app = Desktop() synth = Synth() - modeResolution = (1024,768) + screenResolution = (1024,768) if wimoteSupport : from pywiiuse import pygame_wiimouse - from pywiiuse.PyWiiUse import IR_BELOW - pygame_wiimouse.init(4, 5) # look for 4, wait 5 seconds + pygame_wiimouse.init(4, 5, screenResolution) # look for 4, wait 5 seconds nwiimotes = pygame_wiimouse.get_count() print '%d wiimotes' % nwiimotes WT = pygame_wiimouse.WT WT.pause() - wm = pygame_wiimouse.Wiimote(0) # access the wiimote object - wm.enable_accels(0) # turn on acceleration reporting - wm.enable_ir(1, vres = modeResolution, position=IR_BELOW) else : nwiimotes = 0 class _WTFacade : + selectWimoteIndex = 0 def pause(self): pass def resume(self): pass + def selectWiimote(self, i): + pass WT = _WTFacade() - pygame.display.set_mode(modeResolution) + pygame.display.set_mode(screenResolution) pygame.display.set_caption('MinWii') while True : @@ -60,11 +59,14 @@ class MinWii(object): app.run(home) app.close(home) returnValue = home.returnValue + print 'home.selectedWiimoteIndex', home.selectedWiimoteIndex if not returnValue : break - # sélection de l'instrument + WT.selectWiimote(home.selectedWiimoteIndex) WT.resume() + + # sélection de l'instrument selector = InstrumentSelector() selector.run() selector.stop() diff --git a/src/app/widgets/home.py b/src/app/widgets/home.py index 86d6ab4..381ec68 100755 --- a/src/app/widgets/home.py +++ b/src/app/widgets/home.py @@ -89,6 +89,10 @@ class Home(Table) : self.tr() self.td(Spacer(500,500)) + @property + def selectedWiimoteIndex(self) : + return self.selectedWiimote.value + def _initLocalListeners(self) : self.browseButton.connect(CLICK, self.open_file_browser) self.quitButton.connect(CLICK, self._exitApp) diff --git a/src/pywiiuse/pygame_wiimouse.py b/src/pywiiuse/pygame_wiimouse.py index 5e764ce..8a4f6e0 100755 --- a/src/pywiiuse/pygame_wiimouse.py +++ b/src/pywiiuse/pygame_wiimouse.py @@ -22,6 +22,7 @@ class wiimote_thread(Thread): self.queue = Queue() self.startup = Queue() self.nmotes = nmotes + self.selectedWiimoteIndex = 0 self.timeout = timeout self.setDaemon(1) self._paused = False @@ -48,10 +49,9 @@ class wiimote_thread(Thread): if self._paused : continue 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) + m = self.wiimotes[self.selectedWiimoteIndex] + if m[0].event == wiiuse.EVENT: + self.event_cb(m) except : pass @@ -68,6 +68,9 @@ class wiimote_thread(Thread): def resume(self) : self._paused = False + + def selectWiimote(self, wiimoteIndex) : + self.selectedWiimoteIndex = wiimoteIndex def do(self, func, *args): '''Run the function in the thread handling the wiimote''' @@ -121,12 +124,19 @@ class wiimote_thread(Thread): WT = None -def init(nmotes, timeout): +def init(nmotes, timeout, screenResolution=(660, 370)): '''Initialize the module.''' global WT if WT: return WT = wiimote_thread(nmotes, timeout) + + nmotes = get_count() + for i in range(nmotes) : + wm = Wiimote(i) # access the wiimote object + wm.enable_accels(0) # turn off acceleration reporting + wm.enable_ir(1, vres = screenResolution, position=wiiuse.IR_BELOW) + def get_count(): '''How many Wiimotes were found?'''