Example #1
0
 def __init__(self):
     super(Grafico, self).__init__()
     self.l1=0
     self.l2=0
     self.l3=0
     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.5)
     wiiuse.rumble(self.wiimotes[0], 0)
     self.wm = self.wiimotes[0][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)
Example #3
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])
 def __init__(self,w):
       threading.Thread.__init__(self)
       self.rotX = 0
       self.rotY = 0
       self.rotZ = 0
       self.window = w
       self.sigue=True
       self.releasedButton ={"1":"2","2":"1","16":"-","128":"HOME","4096":"+","8":"A","1024":"ABAJO",
                             "512":"DERECHA","2048":"ARRIBA","256":"IZQUIERDA","4":"B","3":"1+2"}
       self.pressedButton  ={"2.86":"ARRIBA","1.43":"ABAJO","7.17":"DERECHA","3.58":"IZQUIERDA","1.12":"A",
                             "5.60":"B","2.24":"-","1.79":"HOME","5.73":"+","2.80":"1","1.40":"2","2.75":"1+2"}
       #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)
       self.wm = self.wiimotes[0][0]
 def __init__(self,w):
       threading.Thread.__init__(self)
       self.rotX = 0
       self.rotY = 0
       self.rotZ = 0
       self.window = w
       self.sigue=True
       #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)
       self.wm = self.wiimotes[0][0]
 def __init__(self, parent=None):
     self.parent = parent
     QtOpenGL.QGLWidget.__init__(self, parent)
     self.xRotDeg = 0.0
     self.yRotDeg = 0.0
     self.zRotDeg = 0.0
     #######iniciando Wiiii
     #####################
     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.5)
     wiiuse.rumble(self.wiimotes[0], 0)
     self.wm = self.wiimotes[0][0]
 def __init__(self):
     super(Grafico, self).__init__()
     self.maxG1 =1.0
     self.maxG2 =1.0
     self.maxG3 =1.0
     self.minG1 =-1.0
     self.minG2 =-1.0
     self.minG3 =-1.0
     self.b1 = True
     self.b2 = True
     self.b3 = True
     self.l1 = None
     self.l2 = None
     self.l3 = None
     self.arr = [0 for i in range(0,350)]
     self.arr1 = [0 for i in range(0,350)]
     self.arr2 = [0 for i in range(0,350)]
     #######iniciando Wiiii
     #####################
     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.5)
     wiiuse.rumble(self.wiimotes[0], 0)
     self.wm = self.wiimotes[0][0]
     #wiiuse.motion_sensing(self.wiimotes, 0)
     ###############################
     #######iniciando wii
     ###iniciando hilos
     self.hilo = Wiibotones(self)
     self.hilo.start()
     #################
     
     """super(Example, self).__init__()
Example #8
0
def intro_prompt():
    if os.name != 'nt':
        print "\n\n*************************************"
        time.sleep(STANDARD_SLEEP_TIME)
        print "*************************************"
        time.sleep(STANDARD_SLEEP_TIME)
        print "*************************************\n"
        time.sleep(STANDARD_SLEEP_TIME)
        print "Press 1 & 2 to connect"

        found_motes = wiiuse.find(wiimotes, num_motes, 1)  # Find one remote, and wait up to 1 second to find it.

        # If no remotes are found...
        if not found_motes:
            print "No remotes found!  Exiting."
            sys.exit(1)
        else:
            print "... Found remote."

        connected = wiiuse.connect(wiimotes, num_motes)

        if connected:
            print 'Connected to %i wiimotes!' % connected
        else:
            print "Failed to connect.  Exiting."
            sys.exit(1)

        wiiuse.set_leds(first_wm, wiiuse.LED[0])

        print "Enabling motion sense..."
        time.sleep(STANDARD_SLEEP_TIME)
        wiiuse.motion_sensing(first_wm, 1)  # Enable motion sensing.
        time.sleep(STANDARD_SLEEP_TIME)

        print "Enabling IR...\n"
        time.sleep(STANDARD_SLEEP_TIME)
        wiiuse.set_ir(first_wm, 1)  # Enable IR (No sensor bar yet.)
        time.sleep(STANDARD_SLEEP_TIME)

        print "*************************************"
        time.sleep(STANDARD_SLEEP_TIME)
        print "*************************************"
        time.sleep(STANDARD_SLEEP_TIME)
        print "*************************************\n"

        time.sleep(STANDARD_SLEEP_TIME)
        star_wave()
        print "\nLet's begin!\n"
        star_wave()
Example #9
0
	def start( self ):
		found = wii.find( self._pointer, self._nmotes, 5 )
		assert found
		print( 'found wiimotes', found )
		connected = wii.wiiuse_connect( self._pointer, self._nmotes )	# NOT wii.connect
		assert connected
		print( 'connected wiimotes', connected )

		for i in range( self._nmotes ):
			wm = self._pointer[i]
			wii.motion_sensing(wm, 1)
			wii.set_leds( wm, wii.WIIMOTE_LED_2)

		self._active = True
		return found
 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 getConnected():
    #global wiimotes
    #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)
Example #12
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")
Example #13
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.sigue = True
     #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.rumble(self.wiimotes[0], 10)
     time.sleep(0.1)
     wiiuse.rumble(self.wiimotes[0], 0)
     self.wm = self.wiimotes[0][0]
Example #14
0
def connect():
    if os.name != 'nt': print 'Press 1&2'

    wiimotes = wiiuse.init(nmotes)

    found = wiiuse.find(wiimotes, nmotes, 5)
    if not found:
        st='not found'
        print st
        return st
    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)
    
    return wiimotes,nmotes
Example #15
0
 def __init__(self, w):
     threading.Thread.__init__(self)
     self.rotX = 0
     self.rotY = 0
     self.rotZ = 0
     self.window = w
     self.sigue = True
     self.releasedButton = {
         "1": "2",
         "2": "1",
         "16": "-",
         "128": "HOME",
         "4096": "+",
         "8": "A",
         "1024": "ABAJO",
         "512": "DERECHA",
         "2048": "ARRIBA",
         "256": "IZQUIERDA",
         "4": "B",
         "3": "1+2"
     }
     self.pressedButton = {
         "2.86": "ARRIBA",
         "1.43": "ABAJO",
         "7.17": "DERECHA",
         "3.58": "IZQUIERDA",
         "1.12": "A",
         "5.60": "B",
         "2.24": "-",
         "1.79": "HOME",
         "5.73": "+",
         "2.80": "1",
         "1.40": "2",
         "2.75": "1+2"
     }
     #iniciar Wiimote
     self.nmotes = 2
     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[i])
         wiiuse.set_ir(self.wiimotes[i], 1)
         wiiuse.set_ir_vres(self.wiimotes[i], 1000, 1000)
     wiiuse.rumble(self.wiimotes[0], 10)
     wiiuse.rumble(self.wiimotes[1], 10)
     time.sleep(0.1)
     wiiuse.rumble(self.wiimotes[0], 0)
     wiiuse.rumble(self.wiimotes[1], 0)
     self.wm = self.wiimotes[0][0]
     self.wm2 = self.wiimotes[0][1]
Example #16
0
#!/usr/bin/python
# updated Nov 2011
import os, sys, time
import wiiuse as wii

MAX_WIIMOTES = 2
context = wii.init(MAX_WIIMOTES)
print(context)

found = wii.find(context, MAX_WIIMOTES, 5)
assert found
print('found wiimotes', found)

#connected = wii.connect( context, found )	# dont get confused by other connect function from bluez
connected = wii.wiiuse_connect(context, MAX_WIIMOTES)
assert connected

wii.set_leds(context[0], wii.WIIMOTE_LED_1)
Example #17
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])	


Example #18
0
#!/usr/bin/python
# updated Nov 2011
import os,sys, time
import wiiuse as wii

MAX_WIIMOTES = 2
context = wii.init( MAX_WIIMOTES )
print( context )

found = wii.find( context, MAX_WIIMOTES, 5 )
assert found
print( 'found wiimotes', found )

#connected = wii.connect( context, found )	# dont get confused by other connect function from bluez
connected = wii.wiiuse_connect( context, MAX_WIIMOTES )
assert connected

wii.set_leds( context[0], wii.WIIMOTE_LED_1 )



Example #19
0
            if wm.ir.dot[i].visible:
                currentX = wm.ir.x
                currentY = wm.ir.y
                #print currentX,currentY
        #print 'IR z distance: %f' % wm.ir.z
    return currentX, currentY


def handle_disconnect(wmp):
    print 'disconnect'


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)
Example #20
0
import time
import wiiuse
import sys
import ctypes
from ctypes import Structure, c_byte
#######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)
Example #21
0
bloque.Fg = bloque.masa * g
bloque.Fn = bloque.masa*g*math.sin(math.radians(angle))
def moveBloque():
	a = bloque.Fg* math.sin(math.radians(-angle))	
	bloque.Vx = a*dt
	bloque.x += bloque.Vx*dt/100
	if bloque.x > (tabla.length -bloque.length)/2: # Borde de la tabla
		bloque.x = (tabla.length -bloque.length)/2
	if bloque.x < -(tabla.length -bloque.length)/2:
		bloque.x = -(tabla.length -bloque.length)/2 
	print bloque.x

b = 0
wiimots = wiiuse.init(1)
encontrado = wiiuse.find(wiimots, 1, 5)
connected = wiiuse.connect(wiimots, 1)

wiiuse.set_leds(wiimots[0], wiiuse.LED[2])
wiiuse.rumble(wiimots[0],0)
sleep(1)


s = serial.Serial(8)		# COM8 virtual
s.baudrate = 4800

s.timeout = 0		# no espera a leer
alp = 0.0
while 1:
	#WiiMo(wiimotes[0])		
	#Wiis.an()