Пример #1
0
def handle_event(wmp):
    wm = wmp[0]
    #print '--- EVENT [wiimote id %i] ---' % wm.unid
    
    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.is_just_pressed(wm, wiiuse.button['Up']):
            wiiuse.set_ir(wmp, 1)
        if wiiuse.is_just_pressed(wm, wiiuse.button['Down']):
            wiiuse.set_ir(wmp, 0)
    
    if wiiuse.using_acc(wm):
        
        print 'roll  = %f' % wm.orient.roll
        print 'pitch = %f' % wm.orient.pitch
        print 'yaw   = %f' % wm.orient.yaw
        print 'x_acc = %f' % wm.gforce.x
        print 'y_acc = %f' % wm.gforce.y
        print 'z_acc = %f' % wm.gforce.z
Пример #2
0
def handle_event(wmp):
    wm = wmp[0]
    print '--- EVENT [wiimote id %i] ---' % wm.unid
    
    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.is_just_pressed(wm, wiiuse.button['Up']):
            wiiuse.set_ir(wmp, 1)
        if wiiuse.is_just_pressed(wm, wiiuse.button['Down']):
            wiiuse.set_ir(wmp, 0)
    
    if wiiuse.using_acc(wm):
        print 'roll  = %f' % wm.orient.roll
        print 'pitch = %f' % wm.orient.pitch
        print 'yaw   = %f' % wm.orient.yaw
		print 'x_force = %f' % wm.gforce.x
        print 'y_force = %f' % wm.gforce.y
        print 'z_force = %f' % wm.gforce.z
Пример #3
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
Пример #4
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
Пример #5
0
    def event_cb(self, wm):
        '''Called when the library has some data for the user.'''
        
        if wm.btns:
            for name,b in list(wiiuse.button.items()):
                if wiiuse.is_just_pressed(wm, b):
                    pygame.event.post(pygame.event.Event(WIIMOTE_BUTTON_PRESS, button=name,
                                                         time=time.time(),
                                                         id=wm.unid))

        if wm.btns_released:
            for name,b in list(wiiuse.button.items()):
                if wiiuse.is_released(wm, b):
                    pygame.event.post(pygame.event.Event(WIIMOTE_BUTTON_RELEASE, button=name,
                                                         time=time.time(),
                                                         id=wm.unid))

        if wiiuse.using_acc(wm):
            pygame.event.post(pygame.event.Event(WIIMOTE_ACCEL, 
                                                 orient=(wm.orient.roll, wm.orient.pitch,
                                                         wm.orient.yaw),
                                                 accel=(wm.gforce.x, wm.gforce.y, wm.gforce.z),
                                                 time=time.time(),
                                                 id=wm.unid))
        if wiiuse.using_ir(wm):
            dots = [ (wm.ir.dot[i].visible, wm.ir.dot[i].x, wm.ir.dot[i].y) for i in range(4) ]
            pygame.event.post(pygame.event.Event(WIIMOTE_IR,
                                                 dots=dots,
                                                 cursor=(wm.ir.x, wm.ir.y, wm.ir.z),
                                                 time=time.time(),
                                                 id=wm.unid))

        if wm.exp.type == wiiuse.EXP_NUNCHUK:
            nc = wm.exp.u.nunchuk
            
            for name,b in list(wiiuse.nunchuk_button.items()):
                if wiiuse.is_just_pressed(nc, b):
                    pygame.event.post(pygame.event.Event(NUNCHUK_BUTTON_PRESS, button=name,
                                                         time=time.time(),
                                                         id=wm.unid))
                elif wiiuse.is_released(nc, b):
                    pygame.event.post(pygame.event.Event(NUNCHUK_BUTTON_RELEASE, button=name,
                                                         time=time.time(),
                                                         id=wm.unid))

            pygame.event.post(pygame.event.Event(NUNCHUK_ACCEL,
                                                 orient=(nc.orient.roll, nc.orient.pitch,
                                                         nc.orient.yaw),
                                                 accel=(nc.gforce.x, nc.gforce.y, nc.gforce.z),
                                                 time=time.time(),
                                                 id=wm.unid))
            pygame.event.post(pygame.event.Event(NUNCHUK_JOY,
                                                 angle=nc.js.ang,
                                                 mag=nc.js.mag,
                                                 time=time.time(),
                                                 id=wm.unid))
Пример #6
0
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
Пример #7
0
def handle_event(wmp):
    wm = wmp[0]
    print('--- EVENT [wiimote id %i] ---' % wm.unid)

    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['-']):
            print("- pressed")
            wiiuse.motion_sensing(wmp, 0)
        if wiiuse.is_just_pressed(wm, wiiuse.button['+']):
            print("+ pressed")
            wiiuse.motion_sensing(wmp, 1)
        if wiiuse.is_just_pressed(wm, wiiuse.button['B']):
            print("B pressed")
            wiiuse.toggle_rumble(wmp)
        if wiiuse.is_just_pressed(wm, wiiuse.button['Up']):
            print("D-Pad Up pressed")
            wiiuse.set_ir(wmp, 1)
        if wiiuse.is_just_pressed(wm, wiiuse.button['Down']):
            print("D-Pad Down Pressed")
            wiiuse.set_ir(wmp, 0)

    if wiiuse.using_acc(wm):
        print('roll  = %f' % wm.orient.roll)
        print('pitch = %f' % wm.orient.pitch)
        print('yaw   = %f' % wm.orient.yaw)

    if wiiuse.using_ir(wm):
        for i in range(4):
            if wm.ir.dot[i].visible:
                print('IR source %i: (%u, %u)' %
                      (i, wm.ir.dot[i].x, wm.ir.dot[i].y))
        print('IR cursor: (%u, %u)' % (wm.ir.x, wm.ir.y))
        print('IR z distance: %f' % wm.ir.z)

    if wm.exp.type == wiiuse.EXP_NUNCHUK:
        nc = wm.exp.u.nunchuk

        for name, b in wiiuse.nunchuk_button.items():
            if wiiuse.is_pressed(nc, b):
                print('Nunchuk: %s is pressed' % name)

        print('nunchuk roll  = %f' % nc.orient.roll)
        print('nunchuk pitch = %f' % nc.orient.pitch)
        print('nunchuk yaw   = %f' % nc.orient.yaw)
        print('nunchuk joystick angle:     %f' % nc.js.ang)
        print('nunchuk joystick magnitude: %f' % nc.js.mag)
Пример #8
0
    def handle_event(self, wmp):
        wm = wmp[0]
        print('--- EVENT [Wiimote ID %i] ---' % wm.unid)

        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.is_just_pressed(wm, wiiuse.button['Up']):
                wiiuse.set_ir(wmp, 1)
            if wiiuse.is_just_pressed(wm, wiiuse.button['Down']):
                wiiuse.set_ir(wmp, 0)

        if wiiuse.using_acc(wm):
            print('roll  = %f' % wm.orient.roll)
            print('pitch = %f' % wm.orient.pitch)
            print('yaw   = %f' % wm.orient.yaw)

        #if wiiuse.using_ir(wm):
        #    for i in range(4):
        #        if wm.ir.dot[i].visible:
        #            print 'IR source %i: (%u, %u)' % (i, wm.ir.dot[i].x, wm.ir.dot[i].y)
        #    print 'IR cursor: (%u, %u)' % (wm.ir.x, wm.ir.y)
        #    print 'IR z distance: %f' % wm.ir.z

        if wm.exp.type == wiiuse.EXP_NUNCHUK:
            nc = wm.exp.u.nunchuk

            if abs(nc.js.mag) < self.deadthres:
                self.end(self.ids[1])

            for name, b in wiiuse.nunchuk_button.items():
                if wiiuse.is_pressed(nc, b):
                    print('Nunchuk: %s is pressed' % name)

            print('nunchuk roll  = %f' % nc.orient.roll)
            print('nunchuk pitch = %f' % nc.orient.pitch)
            print('nunchuk yaw   = %f' % nc.orient.yaw)
            print('nunchuk joystick angle:     %f' % nc.js.ang)
            print('nunchuk joystick magnitude: %f' % nc.js.mag)
Пример #9
0
def handle_event(wmp):
    wm = wmp[0]
    print '--- EVENT [wiimote id %i] ---' % wm.unid

    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.is_just_pressed(wm, wiiuse.button['Up']):
            wiiuse.set_ir(wmp, 1)
        if wiiuse.is_just_pressed(wm, wiiuse.button['Down']):
            wiiuse.set_ir(wmp, 0)

    if wiiuse.using_acc(wm):
        print 'roll  = %f' % wm.orient.roll
        print 'pitch = %f' % wm.orient.pitch
        print 'yaw   = %f' % wm.orient.yaw

    if wiiuse.using_ir(wm):
        for i in range(4):
            if wm.ir.dot[i].visible:
                print 'IR source %i: (%u, %u)' % (i, wm.ir.dot[i].x, wm.ir.dot[i].y)
        print 'IR cursor: (%u, %u)' % (wm.ir.x, wm.ir.y)
        print 'IR z distance: %f' % wm.ir.z

    if wm.exp.type == wiiuse.EXP_NUNCHUK:
        nc = wm.exp.u.nunchuk

        for name,b in wiiuse.nunchuk_button.items():
            if wiiuse.is_pressed(nc, b):
                print 'Nunchuk: %s is pressed' % name

        print 'nunchuk roll  = %f' % nc.orient.roll
        print 'nunchuk pitch = %f' % nc.orient.pitch
        print 'nunchuk yaw   = %f' % nc.orient.yaw
        print 'nunchuk joystick angle:     %f' % nc.js.ang
        print 'nunchuk joystick magnitude: %f' % nc.js.mag
Пример #10
0
 def press_event(self):
     remote = self.first_wm[0]
     for btn_name, btn in wiiuse.button.items():
         if wiiuse.is_just_pressed(remote, btn):
             return btn
Пример #11
0
        if str(wm.orient_threshold)[:4] != "0.0":
            print "#####"
            #print str(wm.orient_threshold)[:3]
            print str(wm.orient_threshold)[:4]
            print hex(wm.accel_threshold)
            print str(wm.accel_threshold)
            print str(wm.event)
            print str(wm.gforce.x)
        #b.a= wm.event_buf
        #print b.a
        """for estructura in wm.event_buf:
            print estructura
            print sys.getsizeof(estructura)
        """
        #print wm.event_buf
        if wm.btns:
            for name, b in wiiuse.button.items():
                if wiiuse.is_just_pressed(wm, b):
                    print "algo se apreto"
        if wiiuse.using_acc(wm):
            print "acel"
    except:
        print "error"
    #print wm.gforce.x
    """print wiiuse.using_acc(wm)
    print wm.btns"""

#wiiuse.motion_sensing(wiimotes, 0)
###############################
#######iniciando wii
Пример #12
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()
Пример #13
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()
Пример #14
0
            print "#####"
            #print str(wm.orient_threshold)[:3]
            print str(wm.orient_threshold)[:4]
            print hex(wm.accel_threshold)
            print str(wm.accel_threshold)
            print str(wm.event)
            print str(wm.gforce.x)
        #b.a= wm.event_buf
        #print b.a
        """for estructura in wm.event_buf:
            print estructura
            print sys.getsizeof(estructura)
        """
        #print wm.event_buf
        if wm.btns:
            for name,b in wiiuse.button.items():
                if wiiuse.is_just_pressed(wm, b):
                    print "algo se apreto"
        if wiiuse.using_acc(wm):
            print "acel"
    except :
        print "error"
    #print wm.gforce.x
    """print wiiuse.using_acc(wm)
    print wm.btns"""


#wiiuse.motion_sensing(wiimotes, 0)
###############################
#######iniciando wii
Пример #15
0
 def press_event(self):
     remote = self.first_wm[0]
     for btn_name, btn in wiiuse.button.items():
         if wiiuse.is_just_pressed(remote, btn):
             return btn