예제 #1
0
 def drawLines(self, qp): ## este metodo hay que editarlo para que pinte yn punto
     wiiuse.motion_sensing(self.wiimotes, self.nmotes)
     wiiuse.poll(self.wiimotes, self.nmotes)
     pen = QtGui.QPen(QtCore.Qt.black, 10, QtCore.Qt.DotLine)
     qp.setPen(pen)
     try:
         T="(x,y)\t\tnum_dots\t\taspect\tpos\tstate\tax\tay\t\tdistance\tz\n"
         x=self.wm.ir.x
         y=self.wm.ir.y
         T+="("+str(x)+" , "+str(y)+")\t"+str(self.wm.ir.num_dots)+"\t\t"+str(self.wm.ir.pos)+"\t"+str(self.wm.ir.state)+"\t"+str(self.wm.ir.ax)+"\t"+str(self.wm.ir.ay)+"\t\t"+str(self.wm.ir.distance)+"\t"+str(self.wm.ir.z)
         #print str(x)+" "+str(y)
         qp.drawPoint(x,y)
         self.l1.setText("Accel X\t\tAccel Y\n"+str(self.wm.gforce.x)+"\t\t"+str(self.wm.gforce.y)+"")
         self.l2.setText(T)
         #print "##"
         T="(x,y)\t\torder\tVisible\trx\try\tsize\n"
         for a in self.wm.ir.dot:
             T+="( "+str(a.x)+" , "+str(a.y)+" )\t"+str(a.order)+"\t"+str(a.visible)+"\t"+str(a.rx)+"\t"+str(a.ry)+"\t"+str(a.size)+"\n"
             qp.drawPoint(a.rx,a.ry)
         T+="VRES\t"
         for a in self.wm.ir.vres:
             T+=str(a)+"\t"
         T+="\t###\tOfset\t"
         for a in self.wm.ir.offset:
             T+=str(a)+"\t"
         self.l3.setText(T)
         #print "##" 
         #self.l3.setText(str(self.wm.ir.dot))
     except:
         print "error pintando"
 def drawLines(self, qp): ## este metodo hay que editarlo para que pinte yn punto
     wiiuse.motion_sensing(self.wiimotes, self.nmotes)
     wiiuse.poll(self.wiimotes, self.nmotes)
     pen = QtGui.QPen(QtCore.Qt.black, 10, QtCore.Qt.DotLine)
     qp.setPen(pen)
     try:
         x=self.wm.ir.x
         y=768-self.wm.ir.y
         #print str(x)+" "+str(y)
         qp.drawPoint(x,y)
         puntosx=[]
         puntosy=[]
         for a in self.wm.ir.dot:
             if a.rx!=0:
                 qp.drawPoint(a.rx,y+(y/2))
                 qp.drawPoint(a.rx,y-(y/2))
                 qp.drawPoint(a.rx,y)
                 puntosx.append(a.rx)
                 puntosy.append(y-(y/2))
                 puntosy.append(y+(y/2))
         if self.wm.ir.aspect>1 :
             dx=puntosx[1]-puntosx[0]
             dy=puntosy[3]-puntosy[0]
             qp.drawEllipse( x,y,dx,dy)
         """win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,0,0)
         win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,0,0)"""
         self.l1.setText("x + "+str(self.wm.ir.x))
         self.l2.setText("y + "+str(self.wm.ir.y))
         self.l3=0
     except:
         print "error pintando"
예제 #3
0
    def muestraAccel(self):
        wiiuse.motion_sensing(self.wiimotes, self.nmotes)
        wiiuse.poll(self.wiimotes, self.nmotes)
        t = self.wm.gforce.x
        temp = 0
        try:
            temp = math.trunc(t)
        except:
            temp = 0
        if temp < (self.rotX - 3) or temp > (self.rotX + 3):
            self.rotX = temp
            self.window.emit(SIGNAL("AccelX"), self.rotX)

        t = self.wm.gforce.y
        temp = 0
        try:
            temp = math.trunc(t)
        except:
            temp = 0
        if temp < (self.rotY - 3) or temp > (self.rotY + 3):
            self.rotY = temp
            self.window.emit(SIGNAL("AccelY"), self.rotY)
        t = self.wm.gforce.z
        temp = 0
        try:
            temp = math.trunc(t)
        except:
            temp = 0
        if temp != self.rotZ:
            self.rotZ = temp
            self.window.emit(SIGNAL("AccelZ"), self.rotZ)
 def muestraAccel(self):
       wiiuse.motion_sensing(self.wiimotes,self.nmotes)
       wiiuse.poll(self.wiimotes, self.nmotes)
       t = self.wm.gforce.x
       temp=0
       try:
             temp = math.trunc(t)
       except:
             temp=0
       if temp< (self.rotX-3) or temp> (self.rotX+3):
             self.rotX= temp
             self.window.emit(SIGNAL("AccelX"), self.rotX)
       
       t = self.wm.gforce.y
       temp=0
       try:
             temp = math.trunc(t)
       except:
             temp=0
       if temp < (self.rotY-3) or temp > (self.rotY+3):
             self.rotY= temp
             self.window.emit(SIGNAL("AccelY"), self.rotY)
       t = self.wm.gforce.z
       temp=0
       try:
             temp = math.trunc(t)
       except:
             temp=0
       if temp != self.rotZ:
             self.rotZ= temp
             self.window.emit(SIGNAL("AccelZ"), self.rotZ)
예제 #5
0
 def drawLines(self,
               qp):  ## este metodo hay que editarlo para que pinte yn punto
     wiiuse.motion_sensing(self.wiimotes, self.nmotes)
     wiiuse.poll(self.wiimotes, self.nmotes)
     pen = QtGui.QPen(QtCore.Qt.black, 10, QtCore.Qt.DotLine)
     qp.setPen(pen)
     try:
         x = self.wm.ir.x
         y = 768 - self.wm.ir.y
         #print str(x)+" "+str(y)
         qp.drawPoint(x, y)
         puntosx = []
         puntosy = []
         for a in self.wm.ir.dot:
             if a.rx != 0:
                 qp.drawPoint(a.rx, y + (y / 2))
                 qp.drawPoint(a.rx, y - (y / 2))
                 qp.drawPoint(a.rx, y)
                 puntosx.append(a.rx)
                 puntosy.append(y - (y / 2))
                 puntosy.append(y + (y / 2))
         if self.wm.ir.aspect > 1:
             dx = puntosx[1] - puntosx[0]
             dy = puntosy[3] - puntosy[0]
             qp.drawEllipse(x, y, dx, dy)
         """win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,0,0)
         win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,0,0)"""
         self.l1.setText("x + " + str(self.wm.ir.x))
         self.l2.setText("y + " + str(self.wm.ir.y))
         self.l3 = 0
     except:
         print "error pintando"
예제 #6
0
 def run(self):
     while self.sigue:
         time.sleep(0.105)
         #wiiuse.motion_sensing(self.wiimotes,self.nmotes)
         wiiuse.poll(self.wiimotes, self.nmotes)
         try:
             """print self.wm.orient_threshold
                     print self.wm.accel_threshold
                     print self.wm.event
                     print "#####"
                     print self.wm.gforce.x
                     print self.wm.gforce.y
                     print self.wm.gforce.z"""
             if str(self.wm.orient_threshold)[:3] != "0.0":
                 #print "se presiono un boton -> "+str(self.wm.orient_threshold)
                 if str(self.wm.orient_threshold)[:4] == "2.86":
                     print "arriba"
                 if str(self.wm.orient_threshold)[:4] == "1.43":
                     print "abajo"
                 if str(self.wm.orient_threshold)[:4] == "7.17":
                     print "derecha"
                 if str(self.wm.orient_threshold)[:4] == "3.58":
                     print "izquierda"
                 if str(self.wm.orient_threshold)[:4] == "1.12":
                     print "A"
                 if str(self.wm.orient_threshold)[:4] == "5.60":
                     print "B"
                 if str(self.wm.orient_threshold)[:4] == "2.24":
                     print "-"
                 if str(self.wm.orient_threshold)[:4] == "1.79":
                     print "Home"
                 if str(self.wm.orient_threshold)[:4] == "5.73":
                     print "+"
                 if str(self.wm.orient_threshold)[:4] == "2.80":
                     print "1"
                 if str(self.wm.orient_threshold)[:4] == "1.40":
                     print "2"
                 if str(self.wm.orient_threshold)[:4] == "1.83" or str(
                         self.wm.orient_threshold)[:4] == "9.18":
                     print "1 y 2"
             """wiiuse.motion_sensing(self.wiimotes, 1)
                     #wiiuse.poll(self.wiimotes, self.nmotes)
                     print "gforce "+str(self.wm.gforce.x)
                     print "gforce "+str(self.wm.gforce.y)
                     print "gforce "+str(self.wm.gforce.z)
                     print "accel "+str(self.wm.accel.x)
                     print "orient "+str(self.wm.orient.roll)
                     print "orient "+str(self.wm.orient.pitch)
                     print "orient "+str(self.wm.orient.yaw)
                     print "accel_calib "+str(self.wm.accel_calib.cal_g.x)
                     print "state "+str(self.wm.state)
                     print "lstate"+str(self.wm.lstate.orient.roll)
                     print "lstate"+str(self.wm.lstate.orient.pitch)
                     print "lstate"+str(self.wm.lstate.orient.yaw)
                     wiiuse.motion_sensing(self.wiimotes, 0)"""
         except:
             print "error"
예제 #7
0
 def run(self):
       while self.sigue:
             time.sleep(0.105)
             #wiiuse.motion_sensing(self.wiimotes,self.nmotes)
             wiiuse.poll(self.wiimotes, self.nmotes)
             try:
                   """print self.wm.orient_threshold
                   print self.wm.accel_threshold
                   print self.wm.event
                   print "#####"
                   print self.wm.gforce.x
                   print self.wm.gforce.y
                   print self.wm.gforce.z"""
                   if str(self.wm.orient_threshold)[:3] !="0.0":
                         #print "se presiono un boton -> "+str(self.wm.orient_threshold)
                         if str(self.wm.orient_threshold)[:4] =="2.86":
                               print "arriba"
                         if str(self.wm.orient_threshold)[:4] =="1.43":
                               print "abajo"
                         if str(self.wm.orient_threshold)[:4] =="7.17":
                               print "derecha"
                         if str(self.wm.orient_threshold)[:4] =="3.58":
                               print "izquierda"
                         if str(self.wm.orient_threshold)[:4] =="1.12":
                               print "A"
                         if str(self.wm.orient_threshold)[:4] =="5.60":
                               print "B"
                         if str(self.wm.orient_threshold)[:4] =="2.24":
                               print "-"
                         if str(self.wm.orient_threshold)[:4] =="1.79":
                               print "Home"
                         if str(self.wm.orient_threshold)[:4] =="5.73":
                               print "+"
                         if str(self.wm.orient_threshold)[:4] =="2.80":
                               print "1"
                         if str(self.wm.orient_threshold)[:4] =="1.40":
                               print "2"
                         if str(self.wm.orient_threshold)[:4] =="1.83" or str(self.wm.orient_threshold)[:4] =="9.18":
                               print "1 y 2"
                   """wiiuse.motion_sensing(self.wiimotes, 1)
                   #wiiuse.poll(self.wiimotes, self.nmotes)
                   print "gforce "+str(self.wm.gforce.x)
                   print "gforce "+str(self.wm.gforce.y)
                   print "gforce "+str(self.wm.gforce.z)
                   print "accel "+str(self.wm.accel.x)
                   print "orient "+str(self.wm.orient.roll)
                   print "orient "+str(self.wm.orient.pitch)
                   print "orient "+str(self.wm.orient.yaw)
                   print "accel_calib "+str(self.wm.accel_calib.cal_g.x)
                   print "state "+str(self.wm.state)
                   print "lstate"+str(self.wm.lstate.orient.roll)
                   print "lstate"+str(self.wm.lstate.orient.pitch)
                   print "lstate"+str(self.wm.lstate.orient.yaw)
                   wiiuse.motion_sensing(self.wiimotes, 0)"""
             except :
               print "error"
    def ingresaPuntoDeWiiMote(self):
        wiiuse.motion_sensing(self.wiimotes, self.nmotes)
        wiiuse.poll(self.wiimotes, self.nmotes)
        #print self.wm.flags
        #print wiiuse.api.read_data
        """if self.wm.btns:
            if wiiuse.is_pressed(self.wm, 0x0004):
                print "B"
            """
        """if wiiuse.is_just_pressed(self.wm, 0x1000):
            print "+"
        """
        #print self.wm.accel.x
        try :
            if wiiuse.using_acc(self.wm):
                print 'roll  = %i' % self.wm.orient.roll
                print 'pitch = %i' % self.wm.orient.pitch
                print 'yaw   = %i' % self.wm.orient.yaw
            if self.b1:
                for i in range(1,len(self.arr)):
                    self.arr[i-1]=self.arr[i]
                self.arr[len(self.arr)-1]=self.wm.gforce.x
                
            if self.b2:
                for i in range(1,len(self.arr1)):
                    self.arr1[i-1]=self.arr1[i]
                self.arr1[len(self.arr1)-1]=self.wm.gforce.y

            if self.b3 and str(self.wm.gforce.z)!='inf':
                for i in range(1,len(self.arr2)):
                    self.arr2[i-1]=self.arr2[i]
                self.arr2[len(self.arr2)-1]=self.wm.gforce.z
            self.l1.setText(str(self.arr[len(self.arr)-1]))
            self.l2.setText(str(self.arr1[len(self.arr1)-1]))
            self.l3.setText(str(self.arr2[len(self.arr2)-1]))
            ####escalando
            if self.arr[len(self.arr)-1] > self.maxG1:
                self.maxG1=self.arr[len(self.arr)-1]*1.0
            if self.arr[len(self.arr)-1] < self.minG1:
                self.minG1=self.arr[len(self.arr)-1]*1.0

            if self.arr1[len(self.arr1)-1] > self.maxG2:
                self.maxG2=self.arr1[len(self.arr1)-1]*1.0
            if self.arr1[len(self.arr1)-1] < self.minG2:
                self.minG2=self.arr1[len(self.arr1)-1]*1.0

            if self.arr2[len(self.arr2)-1] > self.maxG3:
                self.maxG3=self.arr2[len(self.arr2)-1]*1.0
            if self.arr2[len(self.arr2)-1] < self.minG3:
                self.minG3=self.arr2[len(self.arr2)-1]*1.0
        except:
            print "error"
        self.repaint()
예제 #9
0
    def ingresaPuntoDeWiiMote(self):
        wiiuse.motion_sensing(self.wiimotes, self.nmotes)
        wiiuse.poll(self.wiimotes, self.nmotes)
        #print self.wm.flags
        #print wiiuse.api.read_data
        """if self.wm.btns:
            if wiiuse.is_pressed(self.wm, 0x0004):
                print "B"
            """
        """if wiiuse.is_just_pressed(self.wm, 0x1000):
            print "+"
        """
        #print self.wm.accel.x
        try:
            if wiiuse.using_acc(self.wm):
                print 'roll  = %i' % self.wm.orient.roll
                print 'pitch = %i' % self.wm.orient.pitch
                print 'yaw   = %i' % self.wm.orient.yaw
            if self.b1:
                for i in range(1, len(self.arr)):
                    self.arr[i - 1] = self.arr[i]
                self.arr[len(self.arr) - 1] = self.wm.gforce.x

            if self.b2:
                for i in range(1, len(self.arr1)):
                    self.arr1[i - 1] = self.arr1[i]
                self.arr1[len(self.arr1) - 1] = self.wm.gforce.y

            if self.b3 and str(self.wm.gforce.z) != 'inf':
                for i in range(1, len(self.arr2)):
                    self.arr2[i - 1] = self.arr2[i]
                self.arr2[len(self.arr2) - 1] = self.wm.gforce.z
            self.l1.setText(str(self.arr[len(self.arr) - 1]))
            self.l2.setText(str(self.arr1[len(self.arr1) - 1]))
            self.l3.setText(str(self.arr2[len(self.arr2) - 1]))
            ####escalando
            if self.arr[len(self.arr) - 1] > self.maxG1:
                self.maxG1 = self.arr[len(self.arr) - 1] * 1.0
            if self.arr[len(self.arr) - 1] < self.minG1:
                self.minG1 = self.arr[len(self.arr) - 1] * 1.0

            if self.arr1[len(self.arr1) - 1] > self.maxG2:
                self.maxG2 = self.arr1[len(self.arr1) - 1] * 1.0
            if self.arr1[len(self.arr1) - 1] < self.minG2:
                self.minG2 = self.arr1[len(self.arr1) - 1] * 1.0

            if self.arr2[len(self.arr2) - 1] > self.maxG3:
                self.maxG3 = self.arr2[len(self.arr2) - 1] * 1.0
            if self.arr2[len(self.arr2) - 1] < self.minG3:
                self.minG3 = self.arr2[len(self.arr2) - 1] * 1.0
        except:
            print "error"
        self.repaint()
 def run(self):
       while self.sigue:
             self.muestraAccel()
             wiiuse.poll(self.wiimotes, self.nmotes)
             try:
                   rb = str(self.wm.accel_threshold)
                   if self.releasedButton.has_key(rb):
                         self.window.emit(SIGNAL("BotonSuelto"), self.releasedButton[rb])
                   pb=str(self.wm.orient_threshold)[:4]
                   if self.pressedButton.has_key(pb):
                         self.window.emit(SIGNAL("Boton"), self.pressedButton[pb])
             except :
               print "error"
예제 #11
0
 def update(self):
     wiiuse.motion_sensing(self.wiimotes, self.nmotes)
     wiiuse.poll(self.wiimotes, self.nmotes)
     #print "\t######"
     #print self.wm.gforce.x
     if str(self.wm.gforce.x)!='inf':
         self.zRotDeg = 360-self.wm.gforce.x
     if str(self.wm.gforce.y)!='inf':
         self.xRotDeg = 360-self.wm.gforce.y
     """if str(self.wm.gforce.z)!='inf':
         self.yRotDeg = self.wm.gforce.z"""
     self.parent.statusBar().showMessage('x %f - y %f - z %f' % (self.xRotDeg,self.yRotDeg,self.zRotDeg))
     self.updateGL()
예제 #12
0
 def update(self):
     wiiuse.motion_sensing(self.wiimotes, self.nmotes)
     wiiuse.poll(self.wiimotes, self.nmotes)
     #print "\t######"
     #print self.wm.gforce.x
     if str(self.wm.gforce.x) != 'inf':
         self.zRotDeg = 360 - self.wm.gforce.x
     if str(self.wm.gforce.y) != 'inf':
         self.xRotDeg = 360 - self.wm.gforce.y
     """if str(self.wm.gforce.z)!='inf':
         self.yRotDeg = self.wm.gforce.z"""
     self.parent.statusBar().showMessage(
         'x %f - y %f - z %f' % (self.xRotDeg, self.yRotDeg, self.zRotDeg))
     self.updateGL()
예제 #13
0
 def run(self):
     while self.sigue:
         self.muestraAccel()
         wiiuse.poll(self.wiimotes, self.nmotes)
         try:
             rb = str(self.wm.accel_threshold)
             if self.releasedButton.has_key(rb):
                 self.window.emit(SIGNAL("BotonSuelto"),
                                  self.releasedButton[rb])
             pb = str(self.wm.orient_threshold)[:4]
             if self.pressedButton.has_key(pb):
                 self.window.emit(SIGNAL("Boton"), self.pressedButton[pb])
         except:
             print "error"
 def drawLines(self, qp): 
     wiiuse.motion_sensing(self.wiimotes, self.nmotes)
     wiiuse.poll(self.wiimotes, self.nmotes)
     pen = QtGui.QPen(QtCore.Qt.black, 10, QtCore.Qt.DotLine)
     qp.setPen(pen)
     try:
         #x=self.wm2.ir.x
         #y=768-self.wm2.ir.y
         #print str(x)+" "+str(y)
         #qp.drawPoint(x,y)
         puntosx=[]
         puntosy=[]
         """for a in self.wm.ir.dot:
             if a.rx!=0:
                 qp.drawPoint(a.rx,5)"""
         for b in self.wm.ir.dot:
             #print str(b.x)+" "+str(b.y)+"\t"+"\t"+str(b.rx)+"\t"+str(b.ry)
             if b.rx!=0 and b.rx<1030 and b.rx>0:
                 #qp.drawPoint(b.rx,a.rx)
                 puntosx.append(b.rx)
         for a in self.wm2.ir.dot:
             #print str(b.x)+" "+str(b.y)+"\t"+"\t"+str(b.rx)+"\t"+str(b.ry)
             if a.rx!=0 and a.rx<800 and  a.rx>0:
                 #qp.drawPoint(b.rx,a.rx)
                 puntosy.append(a.rx)
         puntos=[]
         for i in range(0,2):
             qp.drawPoint(puntosx[i],puntosy[i])
             puntos.append(puntosx[i])
             puntos.append(puntosy[i])
         #print "arr "+str(puntos)
         qp.drawLine(puntos[0],puntos[1],puntos[2],puntos[3])
         ##REcta perpendicular
         M2=(puntos[0]-puntos[2])/(puntos[3]-puntos[1])
         y1=puntos[1] - M2*(puntos[0]- 0)
         y2=puntos[3] - M2*(puntos[2]- 0)
         #arr=[-10,y1,10,y2]
         qp.drawLine(0,y1,puntos[0],puntos[1])
         qp.drawLine(0,y2,puntos[2],puntos[3])
         ##REcta perpendicular
         qp.drawEllipse(((puntos[2]+puntos[0])/2)-50,((puntos[3]+puntos[1])/2)-50,100,100)
         """print "arriba"
         print puntosx
         print puntosy
         print puntos
         print "abajo" """
         #self.l3.setText()
     except:
         print "error pintando"
예제 #15
0
def getDataOnlyOnce():
    getConnected()
    while True:
        r=wiiuse.poll(wiimotes, nmotes)
        if r!=0:
            a=handle_event(wiimotes[0])
            print a           
예제 #16
0
    def perform_gesture(self):
        done = False

        if len(self.known_gestures) == 0:
            return
        i = 0
        frames = []
        while not done:
            r = wiiuse.poll(self.wiimotes, self.num_motes)
            if r != 0:

                if wiiuse.is_held(self.first_wm[0], wiiuse.button['B']):
                    roll = self.first_wm[0].orient.roll
                    pitch = self.first_wm[0].orient.pitch
                    acc_x = self.first_wm[0].gforce.x
                    acc_y = self.first_wm[0].gforce.y
                    acc_z = self.first_wm[0].gforce.z

                    frame = (roll, pitch, acc_x, acc_y, acc_z)

                    # Only add every nth frame to the list.
                    if i % self.frame_freq == 0:
                        frames.append(frame)

                if wiiuse.is_released(self.first_wm[0], wiiuse.button['B']):
                    done = True
                i += 1

        gesture = PerformedGesture(frames)
        return gesture
예제 #17
0
def withYield():
    getConnected()
    while True:
        r = wiiuse.poll(wiimotes, nmotes)
        if r != 0:
            wmp=wiimotes[0]
            wm=wmp[0]
          
            if wm.btns:
                for name, b in wiiuse.button.items():
                    if wiiuse.is_pressed(wm, b):
                        print name,'pressed'
                if wiiuse.is_just_pressed(wm, wiiuse.button['-']):
                    wiiuse.motion_sensing(wmp, 0)
                if wiiuse.is_just_pressed(wm, wiiuse.button['+']):
                        wiiuse.motion_sensing(wmp, 1)
                if wiiuse.is_just_pressed(wm, wiiuse.button['B']):
                    wiiuse.toggle_rumble(wmp) 
            if wiiuse.using_acc(wm):
                #global rollAngle
                global completeList
                #rollAngle=[wm.orient.roll]
                completeList=[wm.orient.roll, wm.orient.pitch, wm.orient.yaw, wm.gforce.x, wm.gforce.y, wm.gforce.z ]
                #yield rollAngle
                yield completeList
예제 #18
0
def init():
    if os.name != 'nt': print 'Press 1&2'

    wiimotes = wiiuse.init(nmotes)

    found = wiiuse.find(wiimotes, nmotes, 5)
    if not found:
        print 'not found'
        sys.exit(1)

    connected = wiiuse.connect(wiimotes, nmotes)
    if connected:
        print 'Connected to %i wiimotes (of %i found).' % (connected, found)
    else:
        print 'failed to connect to any wiimote.'
        sys.exit(1)

    for i in range(nmotes):
        wiiuse.set_leds(wiimotes[i], wiiuse.LED[i])
        wiiuse.status(wiimotes[0])
        wiiuse.set_ir(wiimotes[0], 1)
        wiiuse.set_ir_vres(wiimotes[i], 1000, 1000)

    try:
        rum = 1
        while True:
            r = wiiuse.poll(wiimotes, nmotes)
            if r != 0:
                handle_event(wiimotes[0])
    except KeyboardInterrupt:
        for i in range(nmotes):
            wiiuse.set_leds(wiimotes[i], 0)
            wiiuse.rumble(wiimotes[i], 0)
            wiiuse.disconnect(wiimotes[i])
예제 #19
0
    def run(self):
        '''This runs in a separate thread'''
        # import here to avoid thread problems on windows
        global wiiuse
        import wiiuse
        
        self.wiimotes = wiiuse.init(self.nmotes)
        found = wiiuse.find(self.wiimotes, self.nmotes, self.timeout)
        self.actual_nmotes = wiiuse.connect(self.wiimotes, self.nmotes)

        for i in range(self.nmotes):
            wiiuse.set_leds(self.wiimotes[i], wiiuse.LED[i])

        self.go = self.actual_nmotes != 0

        self.startup.put(self.go)

        while self.go:
            try:
                if wiiuse.poll(self.wiimotes, self.nmotes):
                    for i in range(self.nmotes):
                        wm = self.wiimotes[i][0]
                        if wm.event:
                            self.event_cb(wm)

            except:
                pass

            # allow executing functions in this thread
            while True:
                try:
                    func, args = self.queue.get_nowait()
                except Empty:
                    break
                func(*args)
예제 #20
0
 def run(self):
       while self.sigue:
             #self.muestraAccel()
             #print self.ir_points()
             wiiuse.poll(self.wiimotes, self.nmotes)
             try:
                   rb = str(self.wm.accel_threshold)
                   if self.releasedButton.has_key(rb):
                         self.window.emit(SIGNAL("BotonSuelto"), self.releasedButton[rb])
                   pb=str(self.wm.orient_threshold)[:4]
                   if self.pressedButton.has_key(pb):
                         self.window.emit(SIGNAL("Boton"), self.pressedButton[pb])
                   self.giraPlano()
                   self.window.glWidget.updateGL()
             except :
               print "error RUN"
예제 #21
0
def withYield():
    getConnected()
    while True:
        r = wiiuse.poll(wiimotes, nmotes)
        if r != 0:
            wmp = wiimotes[0]
            wm = wmp[0]

            if wm.btns:
                for name, b in wiiuse.button.items():
                    if wiiuse.is_pressed(wm, b):
                        print name, 'pressed'
                if wiiuse.is_just_pressed(wm, wiiuse.button['-']):
                    wiiuse.motion_sensing(wmp, 0)
                if wiiuse.is_just_pressed(wm, wiiuse.button['+']):
                    wiiuse.motion_sensing(wmp, 1)
                if wiiuse.is_just_pressed(wm, wiiuse.button['B']):
                    wiiuse.toggle_rumble(wmp)
            if wiiuse.using_acc(wm):
                #global rollAngle
                global completeList
                #rollAngle=[wm.orient.roll]
                completeList = [
                    wm.orient.roll, wm.orient.pitch, wm.orient.yaw,
                    wm.gforce.x, wm.gforce.y, wm.gforce.z
                ]
                #yield rollAngle
                yield completeList
예제 #22
0
def init():
    if os.name != 'nt': print 'Press 1&2'

    wiimotes = wiiuse.init(nmotes)

    found = wiiuse.find(wiimotes, nmotes, 5)
    if not found:
        print 'not found'
        sys.exit(1)

    connected = wiiuse.connect(wiimotes, nmotes)
    if connected:
        print 'Connected to %i wiimotes (of %i found).' % (connected, found)
    else:
        print 'failed to connect to any wiimote.'
        sys.exit(1)

    for i in range(nmotes):
        wiiuse.set_leds(wiimotes[i], wiiuse.LED[i])
        wiiuse.status(wiimotes[0])
        wiiuse.set_ir(wiimotes[0], 1)
        wiiuse.set_ir_vres(wiimotes[i], 1000, 1000)

    try:
        rum = 1
        while True:
            r = wiiuse.poll(wiimotes, nmotes)
            if r != 0:
                handle_event(wiimotes[0])
    except KeyboardInterrupt:
        for i in range(nmotes):
            wiiuse.set_leds(wiimotes[i], 0)
            wiiuse.rumble(wiimotes[i], 0)
            wiiuse.disconnect(wiimotes[i])
예제 #23
0
def getDataOnlyOnce():
    getConnected()
    while True:
        r = wiiuse.poll(wiimotes, nmotes)
        if r != 0:
            a = handle_event(wiimotes[0])
            print a
예제 #24
0
    def perform_gesture(self):
        done = False

        if len(self.known_gestures) == 0:
            return
        i = 0
        frames = []
        while not done:
            r = wiiuse.poll(self.wiimotes, self.num_motes)
            if r != 0:

                if wiiuse.is_held(self.first_wm[0], wiiuse.button['B']):
                    roll = self.first_wm[0].orient.roll
                    pitch = self.first_wm[0].orient.pitch
                    acc_x = self.first_wm[0].gforce.x
                    acc_y = self.first_wm[0].gforce.y
                    acc_z = self.first_wm[0].gforce.z

                    frame = (roll, pitch, acc_x, acc_y, acc_z)

                    # Only add every nth frame to the list.
                    if i % self.frame_freq == 0:
                        frames.append(frame)

                if wiiuse.is_released(self.first_wm[0], wiiuse.button['B']):
                    done = True
                i += 1

        gesture = PerformedGesture(frames)
        return gesture
예제 #25
0
 def run(self):
     while self.sigue:
         #self.muestraAccel()
         #print self.ir_points()
         wiiuse.poll(self.wiimotes, self.nmotes)
         try:
             rb = str(self.wm.accel_threshold)
             if self.releasedButton.has_key(rb):
                 self.window.emit(SIGNAL("BotonSuelto"),
                                  self.releasedButton[rb])
             pb = str(self.wm.orient_threshold)[:4]
             if self.pressedButton.has_key(pb):
                 self.window.emit(SIGNAL("Boton"), self.pressedButton[pb])
             self.giraPlano()
             self.window.glWidget.updateGL()
         except:
             print "error RUN"
예제 #26
0
 def run(self):
     #iniciar Wiimote
     self.nmotes = 1
     self.wiimotes = wiiuse.init(self.nmotes)
     found = wiiuse.find(self.wiimotes, self.nmotes, 5)
     if not found:
         print 'not found'
         sys.exit(1)
     connected = wiiuse.connect(self.wiimotes, self.nmotes)
     if connected:
         print 'Connected to %i wiimotes (of %i found).' % (connected,
                                                            found)
     else:
         print 'failed to connect to any wiimote.'
         sys.exit(1)
     for i in range(self.nmotes):
         wiiuse.set_leds(self.wiimotes[i], wiiuse.LED[i])
         wiiuse.status(self.wiimotes[0])
         wiiuse.set_ir(self.wiimotes[0], 1)
         wiiuse.set_ir_vres(self.wiimotes[i], 1000, 1000)
     """wiiuse.rumble(self.wiimotes[0], 10)
         time.sleep(0.1)
         wiiuse.rumble(self.wiimotes[0], 0)"""
     for i in range(4):
         wiiuse.set_leds(self.wiimotes[0], wiiuse.LED[3 - i])
         time.sleep(0.2)
     self.wm = self.wiimotes[0][0]
     #iniciar Wiimote
     while self.sigue:
         wiiuse.motion_sensing(self.wiimotes, self.nmotes)
         wiiuse.poll(self.wiimotes, self.nmotes)
         print wiiuse.using_acc(self.wm)
         print "gforce \t" + str(self.wm.gforce.x)
         print "gforce \t" + str(self.wm.gforce.y)
         print "gforce \t" + str(self.wm.gforce.z)
         print "accel \t" + str(self.wm.accel.x)
         print "orient \t" + str(self.wm.orient.roll)
         print "orient \t" + str(self.wm.orient.pitch)
         print "orient \t" + str(self.wm.orient.yaw)
         print "accel_calib \t" + str(self.wm.accel_calib.cal_g.x)
         print "state \t" + str(self.wm.state)
         print "lstate\t" + str(self.wm.lstate.orient.roll)
         print "lstate\t" + str(self.wm.lstate.orient.pitch)
         print "lstate\t" + str(self.wm.lstate.orient.yaw)
         print "#" * 30
         time.sleep(0.1)
 def run(self):
       #iniciar Wiimote
       self.nmotes = 1
       self.wiimotes = wiiuse.init(self.nmotes)
       found = wiiuse.find(self.wiimotes, self.nmotes, 5)
       if not found:
             print 'not found'
             sys.exit(1)
       connected = wiiuse.connect(self.wiimotes, self.nmotes)
       if connected:
             print 'Connected to %i wiimotes (of %i found).' % (connected, found)
       else:
             print 'failed to connect to any wiimote.'
             sys.exit(1)
       for i in range(self.nmotes):
             wiiuse.set_leds(self.wiimotes[i], wiiuse.LED[i])
             wiiuse.status(self.wiimotes[0])
             wiiuse.set_ir(self.wiimotes[0], 1)
             wiiuse.set_ir_vres(self.wiimotes[i], 1000, 1000)
       """wiiuse.rumble(self.wiimotes[0], 10)
       time.sleep(0.1)
       wiiuse.rumble(self.wiimotes[0], 0)"""
       for i in range(4):
             wiiuse.set_leds(self.wiimotes[0], wiiuse.LED[3-i])
             time.sleep(0.2)
       self.wm = self.wiimotes[0][0]
       #iniciar Wiimote
       while self.sigue:
             wiiuse.motion_sensing(self.wiimotes, self.nmotes)
             wiiuse.poll(self.wiimotes, self.nmotes)
             print wiiuse.using_acc(self.wm)
             print "gforce \t"+str(self.wm.gforce.x)
             print "gforce \t"+str(self.wm.gforce.y)
             print "gforce \t"+str(self.wm.gforce.z)
             print "accel \t"+str(self.wm.accel.x)
             print "orient \t"+str(self.wm.orient.roll)
             print "orient \t"+str(self.wm.orient.pitch)
             print "orient \t"+str(self.wm.orient.yaw)
             print "accel_calib \t"+str(self.wm.accel_calib.cal_g.x)
             print "state \t"+str(self.wm.state)
             print "lstate\t"+str(self.wm.lstate.orient.roll)
             print "lstate\t"+str(self.wm.lstate.orient.pitch)
             print "lstate\t"+str(self.wm.lstate.orient.yaw)
             print "#"*30
             time.sleep(0.1)
예제 #28
0
 def drawLines(self, qp): ## este metodo hay que editarlo para que pinte yn punto
     wiiuse.motion_sensing(self.wiimotes, self.nmotes)
     wiiuse.poll(self.wiimotes, self.nmotes)
     pen = QtGui.QPen(QtCore.Qt.black, 10, QtCore.Qt.DotLine)
     qp.setPen(pen)
     try:
         x=1024-self.wm.ir.x
         y=768-self.wm.ir.y
         #print str(x)+" "+str(y)
         qp.drawPoint(x,y)
         win32api.SetCursorPos((x,y))
         """win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,0,0)
         win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,0,0)"""
         self.l1.setText("x + "+str(self.wm.ir.x))
         self.l2.setText("y + "+str(self.wm.ir.y))
         self.l3=0
     except:
         print "error pintando"
예제 #29
0
 def run(self):
     while self.sigue:
         time.sleep(0.1)
         #wiiuse.motion_sensing(self.wiimotes,self.nmotes)
         wiiuse.poll(self.wiimotes, self.nmotes)
         try:
             """print self.wm.orient_threshold
                     print self.wm.accel_threshold
                     print self.wm.event
                     print "#####"
                     print self.wm.gforce.x
                     print self.wm.gforce.y
                     print self.wm.gforce.z"""
             if str(self.wm.orient_threshold)[:3] != "0.0":
                 #print "se presiono un boton -> "+str(self.wm.orient_threshold)
                 if str(self.wm.orient_threshold)[:4] == "2.86":
                     print "arriba"
                 if str(self.wm.orient_threshold)[:4] == "1.43":
                     print "abajo"
                 if str(self.wm.orient_threshold)[:4] == "7.17":
                     print "derecha"
                 if str(self.wm.orient_threshold)[:4] == "3.58":
                     print "izquierda"
                 if str(self.wm.orient_threshold)[:4] == "1.12":
                     print "A"
                 if str(self.wm.orient_threshold)[:4] == "5.60":
                     print "B"
                 if str(self.wm.orient_threshold)[:4] == "2.24":
                     print "-"
                 if str(self.wm.orient_threshold)[:4] == "1.79":
                     print "Home"
                 if str(self.wm.orient_threshold)[:4] == "5.73":
                     print "+"
                 if str(self.wm.orient_threshold)[:4] == "2.80":
                     print "1"
                 if str(self.wm.orient_threshold)[:4] == "1.40":
                     print "2"
                 if str(self.wm.orient_threshold)[:4] == "1.83" or str(
                         self.wm.orient_threshold)[:4] == "9.18":
                     print "1 y 2"
             if wiiuse.using_acc(self.wm):
                 print "acel"
         except:
             print "error"
예제 #30
0
 def run(self):
       while self.sigue:
             time.sleep(0.1)
             #wiiuse.motion_sensing(self.wiimotes,self.nmotes)
             wiiuse.poll(self.wiimotes, self.nmotes)
             try:
                   """print self.wm.orient_threshold
                   print self.wm.accel_threshold
                   print self.wm.event
                   print "#####"
                   print self.wm.gforce.x
                   print self.wm.gforce.y
                   print self.wm.gforce.z"""
                   if str(self.wm.orient_threshold)[:3] !="0.0":
                         #print "se presiono un boton -> "+str(self.wm.orient_threshold)
                         if str(self.wm.orient_threshold)[:4] =="2.86":
                               print "arriba"
                         if str(self.wm.orient_threshold)[:4] =="1.43":
                               print "abajo"
                         if str(self.wm.orient_threshold)[:4] =="7.17":
                               print "derecha"
                         if str(self.wm.orient_threshold)[:4] =="3.58":
                               print "izquierda"
                         if str(self.wm.orient_threshold)[:4] =="1.12":
                               print "A"
                         if str(self.wm.orient_threshold)[:4] =="5.60":
                               print "B"
                         if str(self.wm.orient_threshold)[:4] =="2.24":
                               print "-"
                         if str(self.wm.orient_threshold)[:4] =="1.79":
                               print "Home"
                         if str(self.wm.orient_threshold)[:4] =="5.73":
                               print "+"
                         if str(self.wm.orient_threshold)[:4] =="2.80":
                               print "1"
                         if str(self.wm.orient_threshold)[:4] =="1.40":
                               print "2"
                         if str(self.wm.orient_threshold)[:4] =="1.83" or str(self.wm.orient_threshold)[:4] =="9.18":
                               print "1 y 2"
                   if wiiuse.using_acc(self.wm):
                         print "acel"
             except :
               print "error"
예제 #31
0
def key_input(mapping_keys, wiimotes, nmotes):
    print "RECEIVING DATA\nPress the Home button when you're finished."
    print mapping_keys
    stop = 0
    while True:
        r = wiiuse.poll(wiimotes, nmotes)
        if r != 0:
            for i in range(nmotes):
                if handle_event(wiimotes[i], i, mapping_keys): stop = 1
        if stop == 1: break
예제 #32
0
 def ir_points(self):
     try:
         wiiuse.motion_sensing(self.wiimotes, self.nmotes)
         wiiuse.poll(self.wiimotes, self.nmotes)
         puntosx = []
         puntosy = []
         for b in self.wm.ir.dot:
             if b.rx != 0 and b.rx < 1030 and b.rx > 0:
                 puntosx.append(b.rx)
         for a in self.wm2.ir.dot:
             if a.rx != 0 and a.rx < 800 and a.rx > 0:
                 puntosy.append(a.rx)
         puntos = []
         for i in range(0, 2):
             #qp.drawPoint(puntosx[i],puntosy[i])
             puntos.append(puntosx[i])
             puntos.append(puntosy[i])
     except:
         print "error de ir"
     return puntos
예제 #33
0
 def ir_points(self):
       try:
           wiiuse.motion_sensing(self.wiimotes,self.nmotes)
           wiiuse.poll(self.wiimotes, self.nmotes)
           puntosx=[]
           puntosy=[]
           for b in self.wm.ir.dot:
               if b.rx!=0 and b.rx<1030 and b.rx>0:
                   puntosx.append(b.rx)
           for a in self.wm2.ir.dot:
               if a.rx!=0 and a.rx<800 and  a.rx>0:
                   puntosy.append(a.rx)
           puntos=[]
           for i in range(0,2):
               #qp.drawPoint(puntosx[i],puntosy[i])
               puntos.append(puntosx[i])
               puntos.append(puntosy[i])
       except:
           print "error de ir"
       return puntos
예제 #34
0
 def drawLines(self,
               qp):  ## este metodo hay que editarlo para que pinte yn punto
     wiiuse.motion_sensing(self.wiimotes, self.nmotes)
     wiiuse.poll(self.wiimotes, self.nmotes)
     pen = QtGui.QPen(QtCore.Qt.black, 10, QtCore.Qt.DotLine)
     qp.setPen(pen)
     try:
         T = "(x,y)\t\tnum_dots\t\taspect\tpos\tstate\tax\tay\t\tdistance\tz\n"
         x = self.wm.ir.x
         y = self.wm.ir.y
         T += "(" + str(x) + " , " + str(y) + ")\t" + str(
             self.wm.ir.num_dots
         ) + "\t\t" + str(self.wm.ir.pos) + "\t" + str(
             self.wm.ir.state) + "\t" + str(self.wm.ir.ax) + "\t" + str(
                 self.wm.ir.ay) + "\t\t" + str(
                     self.wm.ir.distance) + "\t" + str(self.wm.ir.z)
         #print str(x)+" "+str(y)
         qp.drawPoint(x, y)
         self.l1.setText("Accel X\t\tAccel Y\n" + str(self.wm.gforce.x) +
                         "\t\t" + str(self.wm.gforce.y) + "")
         self.l2.setText(T)
         #print "##"
         T = "(x,y)\t\torder\tVisible\trx\try\tsize\n"
         for a in self.wm.ir.dot:
             T += "( " + str(a.x) + " , " + str(a.y) + " )\t" + str(
                 a.order) + "\t" + str(a.visible) + "\t" + str(
                     a.rx) + "\t" + str(a.ry) + "\t" + str(a.size) + "\n"
             qp.drawPoint(a.rx, a.ry)
         T += "VRES\t"
         for a in self.wm.ir.vres:
             T += str(a) + "\t"
         T += "\t###\tOfset\t"
         for a in self.wm.ir.offset:
             T += str(a) + "\t"
         self.l3.setText(T)
         #print "##"
         #self.l3.setText(str(self.wm.ir.dot))
     except:
         print "error pintando"
예제 #35
0
    def tick():

        global prevOval
        r = wiiuse.poll(wiimotes, 1)
        while not r :
            r = wiiuse.poll(wiimotes, 1)
        
        #actual PID stuff
        positionx,positiony = handle_event(wiimotes[0])
        newcmdX = update(pidX,targetPositionX-positionx,positionx)

        if abs(newcmdX)<10.0:
            print "Equilibrium X"
        else:
            print "x:"+str(newcmdX)+":"+str(command.pitch)
            command.pitch = newcmdX + command.pitch
            if command.pitch>127:command.pitch =127
            if command.pitch <1:command.pitch =1
            
            signal(command)
        
        newcmdY = update(pidY,targetPositionY-positiony,positiony)
        if abs(newcmdY)<10.0:
            print "Equilibrium Y"
        else:
            print "y:"+str(newcmdY)+":"+str(command.throttle)
            command.throttle = command.throttle+newcmdY
            if command.throttle>127:command.throttle=127
            if command.throttle<1:command.throttle=1
            signal(command)

        time.sleep(.01)
        
        #drawing the interface thing (debug)
        canvas.delete(prevOval)
        AA = (positionx,500-positiony)
        #clock.config(text=str(positionx)+','+str(positiony))
        prevOval = canvas.create_oval(AA[0],AA[1],AA[0]+2,AA[1]+2)
        clock.after(10, tick)
예제 #36
0
    def tick():

        global prevOval
        r = wiiuse.poll(wiimotes, 1)
        while not r:
            r = wiiuse.poll(wiimotes, 1)

        #actual PID stuff
        positionx, positiony = handle_event(wiimotes[0])
        newcmdX = update(pidX, targetPositionX - positionx, positionx)

        if abs(newcmdX) < 10.0:
            print "Equilibrium X"
        else:
            print "x:" + str(newcmdX) + ":" + str(command.pitch)
            command.pitch = newcmdX + command.pitch
            if command.pitch > 127: command.pitch = 127
            if command.pitch < 1: command.pitch = 1

            signal(command)

        newcmdY = update(pidY, targetPositionY - positiony, positiony)
        if abs(newcmdY) < 10.0:
            print "Equilibrium Y"
        else:
            print "y:" + str(newcmdY) + ":" + str(command.throttle)
            command.throttle = command.throttle + newcmdY
            if command.throttle > 127: command.throttle = 127
            if command.throttle < 1: command.throttle = 1
            signal(command)

        time.sleep(.01)

        #drawing the interface thing (debug)
        canvas.delete(prevOval)
        AA = (positionx, 500 - positiony)
        #clock.config(text=str(positionx)+','+str(positiony))
        prevOval = canvas.create_oval(AA[0], AA[1], AA[0] + 2, AA[1] + 2)
        clock.after(10, tick)
예제 #37
0
def getData():
    getConnected()
    try:
        rum=1
        while True:
            r=wiiuse.poll(wiimotes, nmotes)
            print r
            if r!=0:
                a=handle_event(wiimotes[0])
                print a 

    except KeyboardInterrupt:
        for i in range(nmotes):
            wiiuse.disconnect(wiimotes[i])
예제 #38
0
def getData():
    getConnected()
    try:
        rum = 1
        while True:
            r = wiiuse.poll(wiimotes, nmotes)
            print r
            if r != 0:
                a = handle_event(wiimotes[0])
                print a

    except KeyboardInterrupt:
        for i in range(nmotes):
            wiiuse.disconnect(wiimotes[i])
예제 #39
0
def mapping(wiimotes, nmotes):
    mapping_keys = {}
    stop = 0
    text = "Press a wiimote button to associate it to a mouse position.\nPress the Home button when you're finished."
    print text
    while True:
        r = wiiuse.poll(wiimotes, nmotes)
        if r != 0:
            for i in range(nmotes):
                if not mapping_keys.has_key(i): mapping_keys[i] = {}
                exec("button%i=handle_event(wiimotes[%i])" % (i, i))
                pos = get_mouse_pos()
                exec(
                    "if button%i == 'Home': stop=1\nelif not button%i == None: \n\tmapping_keys[%i][button%i]=pos \n\tprint i,button%i,pos"
                    % (i, i, i, i, i))
                #print mapping_keys
        if stop == 1:
            break
    return mapping_keys
예제 #40
0
def main():
    if os.name != 'nt': print('Press 1 & 2 to continue')

    wiimotes = wiiuse.init(nmotes)

    found = wiiuse.find(wiimotes, nmotes, 5)
    if not found:
        print('No Wii remote found, exiting with error code 1...')
        sys.exit(1)

    connected = wiiuse.connect(wiimotes, nmotes)
    if connected:
        print('Connected to %i Wii remote(s) (of %i found).' %
              (connected, found))
    else:
        print('Failed to connect to any Wii remote.')
        sys.exit(1)

    for i in range(nmotes):
        wiiuse.set_leds(wiimotes[i], wiiuse.LED[i])
        wiiuse.status(wiimotes[0])
        #wiiuse.set_ir(wiimotes[0], 1)
        #wiiuse.set_ir_vres(wiimotes[i], 1000, 1000)

    wm = WiiMIDI()

    try:
        rum = 1
        while True:
            r = wiiuse.poll(wiimotes, nmotes)
            if r != 0:
                wm.handle_event(wiimotes[0])
    except KeyboardInterrupt:
        for i in range(nmotes):
            wiiuse.set_leds(wiimotes[i], 0)
            wiiuse.rumble(wiimotes[i], 0)
            wiiuse.disconnect(wiimotes[i])

    print("Ended connection")
예제 #41
0
 def poll_wiimote_device(self):
     r = wiiuse.poll(self.wiimotes, self.nmotes)
     #if r != 0:
     #    self.handle_event(self.wiimotes[0])
     return r
예제 #42
0
################################################################
#
# Begin BlueMote!
#
################################################################

done = False
i = 0

intro_prompt()
main_prompt()

# Main usage loop
while not done:
    # Poll the wiimotes for button/motion events
    r = wiiuse.poll(wiimotes, num_motes)

    if r != 0:
        # If there are any events, check for a pressed button
        button_pressed = button_handler.press_event()

        if button_pressed == wiiuse.button['B']:
            os.system('clear')
            print "\nRecognizing gesture...\n"

            # Collect data from the user's performed gesture.
            performed_gesture = gesture_creator.perform_gesture()

            if performed_gesture is None:
                # If the gesture has no length, prompt the user to try again
                time.sleep(STANDARD_SLEEP_TIME * 5)
예제 #43
0
 def run(self):
     while self.sigue:
         time.sleep(0.105)
         #wiiuse.motion_sensing(self.wiimotes,self.nmotes)
         wiiuse.poll(self.wiimotes, self.nmotes)
         try:
             """print self.wm.orient_threshold
                     print self.wm.accel_threshold
                     print self.wm.event
                     print "#####"
                     print self.wm.gforce.x
                     print self.wm.gforce.y
                     print self.wm.gforce.z"""
             s = str(self.wm.accel_threshold)
             #print "thresold "+s
             if s != "0":
                 if s == "1":
                     print "se solto el boton 2"
                     self.window.emit(SIGNAL("BotonSuelto"), "2")
                 if s == "2":
                     print "se solto el boton 1"
                     self.window.emit(SIGNAL("BotonSuelto"), "1")
                 if s == "16":
                     print "se solto el boton -"
                     self.window.emit(SIGNAL("BotonSuelto"), "-")
                 if s == "128":
                     print "se solto el boton HOME"
                     self.window.emit(SIGNAL("BotonSuelto"), "HOME")
                 if s == "4096":
                     print "se solto el boton +"
                     self.window.emit(SIGNAL("BotonSuelto"), "+")
                 if s == "8":
                     print "se solto el boton A"
                     self.window.emit(SIGNAL("BotonSuelto"), "A")
                 if s == "1024":
                     print "se solto el boton ABAJO"
                     self.window.emit(SIGNAL("BotonSuelto"), "ABAJO")
                 if s == "512":
                     print "se solto el boton DERECHA"
                     self.window.emit(SIGNAL("BotonSuelto"), "DERECHA")
                 if s == "2048":
                     print "se solto el boton ARRIBA"
                     self.window.emit(SIGNAL("BotonSuelto"), "ARRIBA")
                 if s == "256":
                     print "se solto el boton IZQUIERDA"
                     self.window.emit(SIGNAL("BotonSuelto"), "IZQUIERDA")
                 if s == "4":
                     print "se solto el boton B"
                     self.window.emit(SIGNAL("BotonSuelto"), "B")
                 if s == "3":
                     print "se solto el boton 1 y 2"
                     self.window.emit(SIGNAL("BotonSuelto"), "1 y 2")
             if str(self.wm.orient_threshold)[:3] != "0.0":
                 #print "se presiono un boton -> "+str(self.wm.orient_threshold)
                 if str(self.wm.orient_threshold)[:4] == "2.86":
                     print "arriba"
                     self.window.emit(SIGNAL("Boton"), "ARRIBA")
                     #self.window.repaint()
                 if str(self.wm.orient_threshold)[:4] == "1.43":
                     print "abajo"
                     self.window.emit(SIGNAL("Boton"), "ABAJO")
                 if str(self.wm.orient_threshold)[:4] == "7.17":
                     print "derecha"
                     self.window.emit(SIGNAL("Boton"), "DERECHA")
                 if str(self.wm.orient_threshold)[:4] == "3.58":
                     print "izquierda"
                     self.window.emit(SIGNAL("Boton"), "IZQUIERDA")
                 if str(self.wm.orient_threshold)[:4] == "1.12":
                     print "A"
                     self.window.emit(SIGNAL("Boton"), "A")
                 if str(self.wm.orient_threshold)[:4] == "5.60":
                     print "B"
                     self.window.emit(SIGNAL("Boton"), "B")
                 if str(self.wm.orient_threshold)[:4] == "2.24":
                     print "-"
                     self.window.emit(SIGNAL("Boton"), "-")
                 if str(self.wm.orient_threshold)[:4] == "1.79":
                     print "Home"
                     self.window.emit(SIGNAL("Boton"), "HOME")
                 if str(self.wm.orient_threshold)[:4] == "5.73":
                     print "+"
                     self.window.emit(SIGNAL("Boton"), "+")
                 if str(self.wm.orient_threshold)[:4] == "2.80":
                     print "1"
                     self.window.emit(SIGNAL("Boton"), "1")
                 if str(self.wm.orient_threshold)[:4] == "1.40":
                     print "2"
                     self.window.emit(SIGNAL("Boton"), "2")
                 if str(self.wm.orient_threshold)[:4] == "1.83" or str(
                         self.wm.orient_threshold)[:4] == "9.18":
                     print "1 y 2"
                     self.window.emit(SIGNAL("Boton"), "1 y 2")
             wiiuse.motion_sensing(self.wiimotes, 1)
             #wiiuse.poll(self.wiimotes, self.nmotes)
             print "gforce " + str(self.wm.gforce.x)
             print "gforce " + str(self.wm.gforce.y)
             print "gforce " + str(self.wm.gforce.z)
             print "accel " + str(self.wm.accel.x)
             print "orient " + str(self.wm.orient.roll)
             print "orient " + str(self.wm.orient.pitch)
             print "orient " + str(self.wm.orient.yaw)
             print "accel_calib " + str(self.wm.accel_calib.cal_g.x)
             print "state " + str(self.wm.state)
             print "lstate" + str(self.wm.lstate.orient.roll)
             print "lstate" + str(self.wm.lstate.orient.pitch)
             print "lstate" + str(self.wm.lstate.orient.yaw)
             #wiiuse.motion_sensing(self.wiimotes, 0)
         except:
             print "error"
예제 #44
0
import wiiuse


def handle_event(wmp):
    wm = wmp[0]
    if wm.btns:
        if wiiuse.is_just_pressed(wm, wiiuse.button['-']):
            wiiuse.motion_sensing(wmp, 0)
        if wiiuse.is_just_pressed(wm, wiiuse.button['A']):
            wiiuse.motion_sensing(wmp, 1)
        if wiiuse.is_just_pressed(wm, wiiuse.button['B']):
            wiiuse.toggle_rumble(wmp)		
    
    
	return wm.orient.pitch
    
wiimotes = wiiuse.init(1)
found = wiiuse.find(wiimotes, 1, 5)
if not found:
    print 'not found'
connected = wiiuse.connect(wiimotes, 1)
if connected:
	while True:
		r = wiiuse.poll(wiimotes, 1)	
		if r != 0:
			print handle_event(wiimotes[0])	


예제 #45
0
################################################################
#
# Begin BlueMote!
#
################################################################

done = False
i = 0

intro_prompt()
main_prompt()

# Main usage loop
while not done:
    # Poll the wiimotes for button/motion events
    r = wiiuse.poll(wiimotes, num_motes)

    if r != 0:
        # If there are any events, check for a pressed button
        button_pressed = button_handler.press_event()

        if button_pressed == wiiuse.button['B']:
            os.system('clear')
            print "\nRecognizing gesture...\n"

            # Collect data from the user's performed gesture.
            performed_gesture = gesture_creator.perform_gesture()

            if performed_gesture is None:
                # If the gesture has no length, prompt the user to try again
                time.sleep(STANDARD_SLEEP_TIME * 5)
예제 #46
0
#######iniciando Wiiii
####################
nmotes = 1
wiimotes = wiiuse.init(nmotes)
found = wiiuse.find(wiimotes, nmotes, 5)
if not found:
    print 'not found'
    sys.exit(1)
connected = wiiuse.connect(wiimotes, nmotes)
if connected:
    print 'Connected to %i wiimotes (of %i found).' % (connected, found)
else:
    print 'failed to connect to any wiimote.'
    sys.exit(1)
for i in range(nmotes):
    wiiuse.set_leds(wiimotes[i], wiiuse.LED[i])
    wiiuse.status(wiimotes[0])
    wiiuse.set_ir(wiimotes[0], 1)
    wiiuse.set_ir_vres(wiimotes[i], 1000, 1000)
wiiuse.rumble(wiimotes[0], 10)
time.sleep(0.1)
wiiuse.rumble(wiimotes[0], 0)
wm = wiimotes[0][0]
while True:
    wiiuse.motion_sensing(wiimotes,nmotes)
    wiiuse.poll(wiimotes, nmotes)
    print wm.ir.num_dots
    print wm.ir.x
    print wm.ir.y
    print "##"
예제 #47
0
    def learn_gesture(self, rep_limit):

        repetitions = 0         # How many times a gesture has been repeated.
        done = False
        confirmed = False

        while not confirmed:
            gest_name = raw_input("Please name your gesture: ")

            if not (self.get_gesture_names().__contains__(gest_name) or
                    len(gest_name) > 15):
                confirmed = True
            else:
                print "\nGesture name taken or too long.  Please choose another.\n"
        gest_action = raw_input("Please specify an command for your gesture: ")

        gest_arg_arr = shlex.split(gest_action)
        frame_arr = []

        print "\nPress and hold B, perform your gesture, and then release B."

        i = 0
        while not done:
            r = wiiuse.poll(self.wiimotes, self.num_motes)
            if r != 0:

                if wiiuse.is_just_pressed(self.first_wm[0], wiiuse.button['B']):
                    print "Learning gesture, round " + str(repetitions+1) + "."

                    frames = []

                if wiiuse.is_held(self.first_wm[0], wiiuse.button['B']):
                    roll = self.first_wm[0].orient.roll
                    pitch = self.first_wm[0].orient.pitch
                    acc_x = self.first_wm[0].gforce.x
                    acc_y = self.first_wm[0].gforce.y
                    acc_z = self.first_wm[0].gforce.z

                    frame = (roll, pitch, acc_x, acc_y, acc_z)

                    # Only add every nth frame to the list.
                    if i%self.frame_freq == 0:
                        frames.append(frame)

                if repetitions >= rep_limit:
                    done = True
                    print "Good! Press A to see your gesture added to the list of known gestures."
                    continue

                if wiiuse.is_released(self.first_wm[0], wiiuse.button['B']):
                    repetitions += 1
                    frame_arr.append(frames)
                    print str(rep_limit-repetitions) + " repetition(s) remaining."

                i += 1

        # Creating the average of the repetitions to create the learned gesture.
        gesture_average = self.average_gesture(frame_arr)

        # Writing Gesture to the gesture file.
        gesture = LearnedGesture(gest_name, gesture_average, gest_arg_arr, 0, 0, frame_arr)
        self.writer_reader.write_gesture(gesture)

        # Update the current known gestures.
        self.update_gestures()
 def run(self):
       while self.sigue:
             time.sleep(0.105)
             #wiiuse.motion_sensing(self.wiimotes,self.nmotes)
             wiiuse.poll(self.wiimotes, self.nmotes)
             try:
                   """print self.wm.orient_threshold
                   print self.wm.accel_threshold
                   print self.wm.event
                   print "#####"
                   print self.wm.gforce.x
                   print self.wm.gforce.y
                   print self.wm.gforce.z"""
                   s = str(self.wm.accel_threshold)
                   #print "thresold "+s
                   if s!="0":
                         if s=="1":
                               print "se solto el boton 2"
                               self.window.emit(SIGNAL("BotonSuelto"), "2")
                         if s=="2":
                               print "se solto el boton 1"
                               self.window.emit(SIGNAL("BotonSuelto"), "1")
                         if s=="16":
                               print "se solto el boton -"
                               self.window.emit(SIGNAL("BotonSuelto"), "-")
                         if s=="128":
                               print "se solto el boton HOME"
                               self.window.emit(SIGNAL("BotonSuelto"), "HOME")
                         if s=="4096":
                               print "se solto el boton +"
                               self.window.emit(SIGNAL("BotonSuelto"), "+")
                         if s=="8":
                               print "se solto el boton A"
                               self.window.emit(SIGNAL("BotonSuelto"), "A")
                         if s=="1024":
                               print "se solto el boton ABAJO"
                               self.window.emit(SIGNAL("BotonSuelto"), "ABAJO")
                         if s=="512":
                               print "se solto el boton DERECHA"
                               self.window.emit(SIGNAL("BotonSuelto"), "DERECHA")
                         if s=="2048":
                               print "se solto el boton ARRIBA"
                               self.window.emit(SIGNAL("BotonSuelto"), "ARRIBA")
                         if s=="256":
                               print "se solto el boton IZQUIERDA"
                               self.window.emit(SIGNAL("BotonSuelto"), "IZQUIERDA")
                         if s=="4":
                               print "se solto el boton B"
                               self.window.emit(SIGNAL("BotonSuelto"), "B")
                         if s=="3":
                               print "se solto el boton 1 y 2"
                               self.window.emit(SIGNAL("BotonSuelto"), "1 y 2")
                   if str(self.wm.orient_threshold)[:3] !="0.0":
                         #print "se presiono un boton -> "+str(self.wm.orient_threshold)
                         if str(self.wm.orient_threshold)[:4] =="2.86":
                               print "arriba"
                               self.window.emit(SIGNAL("Boton"), "ARRIBA")
                               #self.window.repaint()
                         if str(self.wm.orient_threshold)[:4] =="1.43":
                               print "abajo"
                               self.window.emit(SIGNAL("Boton"), "ABAJO")
                         if str(self.wm.orient_threshold)[:4] =="7.17":
                               print "derecha"
                               self.window.emit(SIGNAL("Boton"), "DERECHA")
                         if str(self.wm.orient_threshold)[:4] =="3.58":
                               print "izquierda"
                               self.window.emit(SIGNAL("Boton"), "IZQUIERDA")
                         if str(self.wm.orient_threshold)[:4] =="1.12":
                               print "A"
                               self.window.emit(SIGNAL("Boton"), "A")
                         if str(self.wm.orient_threshold)[:4] =="5.60":
                               print "B"
                               self.window.emit(SIGNAL("Boton"), "B")
                         if str(self.wm.orient_threshold)[:4] =="2.24":
                               print "-"
                               self.window.emit(SIGNAL("Boton"), "-")
                         if str(self.wm.orient_threshold)[:4] =="1.79":
                               print "Home"
                               self.window.emit(SIGNAL("Boton"), "HOME")
                         if str(self.wm.orient_threshold)[:4] =="5.73":
                               print "+"
                               self.window.emit(SIGNAL("Boton"), "+")
                         if str(self.wm.orient_threshold)[:4] =="2.80":
                               print "1"
                               self.window.emit(SIGNAL("Boton"), "1")
                         if str(self.wm.orient_threshold)[:4] =="1.40":
                               print "2"
                               self.window.emit(SIGNAL("Boton"), "2")
                         if str(self.wm.orient_threshold)[:4] =="1.83" or str(self.wm.orient_threshold)[:4] =="9.18":
                               print "1 y 2"
                               self.window.emit(SIGNAL("Boton"), "1 y 2")
                   wiiuse.motion_sensing(self.wiimotes, 1)
                   #wiiuse.poll(self.wiimotes, self.nmotes)
                   print "gforce "+str(self.wm.gforce.x)
                   print "gforce "+str(self.wm.gforce.y)
                   print "gforce "+str(self.wm.gforce.z)
                   print "accel "+str(self.wm.accel.x)
                   print "orient "+str(self.wm.orient.roll)
                   print "orient "+str(self.wm.orient.pitch)
                   print "orient "+str(self.wm.orient.yaw)
                   print "accel_calib "+str(self.wm.accel_calib.cal_g.x)
                   print "state "+str(self.wm.state)
                   print "lstate"+str(self.wm.lstate.orient.roll)
                   print "lstate"+str(self.wm.lstate.orient.pitch)
                   print "lstate"+str(self.wm.lstate.orient.yaw)
                   #wiiuse.motion_sensing(self.wiimotes, 0)
             except :
               print "error"
예제 #49
0
    def learn_gesture(self, rep_limit):

        repetitions = 0  # How many times a gesture has been repeated.
        done = False
        confirmed = False

        while not confirmed:
            gest_name = raw_input("Please name your gesture: ")

            if not (self.get_gesture_names().__contains__(gest_name)
                    or len(gest_name) > 15):
                confirmed = True
            else:
                print "\nGesture name taken or too long.  Please choose another.\n"
        gest_action = raw_input("Please specify an command for your gesture: ")

        gest_arg_arr = shlex.split(gest_action)
        frame_arr = []

        print "\nPress and hold B, perform your gesture, and then release B."

        i = 0
        while not done:
            r = wiiuse.poll(self.wiimotes, self.num_motes)
            if r != 0:

                if wiiuse.is_just_pressed(self.first_wm[0],
                                          wiiuse.button['B']):
                    print "Learning gesture, round " + str(repetitions +
                                                           1) + "."

                    frames = []

                if wiiuse.is_held(self.first_wm[0], wiiuse.button['B']):
                    roll = self.first_wm[0].orient.roll
                    pitch = self.first_wm[0].orient.pitch
                    acc_x = self.first_wm[0].gforce.x
                    acc_y = self.first_wm[0].gforce.y
                    acc_z = self.first_wm[0].gforce.z

                    frame = (roll, pitch, acc_x, acc_y, acc_z)

                    # Only add every nth frame to the list.
                    if i % self.frame_freq == 0:
                        frames.append(frame)

                if repetitions >= rep_limit:
                    done = True
                    print "Good! Press A to see your gesture added to the list of known gestures."
                    continue

                if wiiuse.is_released(self.first_wm[0], wiiuse.button['B']):
                    repetitions += 1
                    frame_arr.append(frames)
                    print str(rep_limit -
                              repetitions) + " repetition(s) remaining."

                i += 1

        # Creating the average of the repetitions to create the learned gesture.
        gesture_average = self.average_gesture(frame_arr)

        # Writing Gesture to the gesture file.
        gesture = LearnedGesture(gest_name, gesture_average, gest_arg_arr, 0,
                                 0, frame_arr)
        self.writer_reader.write_gesture(gesture)

        # Update the current known gestures.
        self.update_gestures()