def wiimote_loop(ev, cf): ev.subscribe(ABS_POS, ev_abs_pos); ev.subscribe(WM_BT, ev_wm_bt); while(True): btaddr = sys.stdin.readline().rstrip(); if (not btaddr): for addr in cf['KNOWN_WIIMOTES']: if ((not addr in connected_wiimotes) or (not connected_wiimotes[addr].running)): btaddr = addr; break; if (btaddr): print "Connecting to " + btaddr; cf['MY_WIIMOTE_ADDR'] = btaddr wm = WMManager( cf, ev ) # Handles the Wiimote; connects to it, manages wiimote state and mode, parses wiimote reports po = POManager( cf, ev, wm.id ) # Handles the pointer, receives WM_IR, sends out ABS_POS absolute position reports try: if wm.connect() and wm.setup(): thread.start_new_thread(wm.main_loop, ()) players[wm.id] = Player(next_start(), wm.id % 2 ); connected_wiimotes[btaddr] = wm; except Exception, reason: # continue the thread print "Exception: " + str(reason);
def __init__( self ): cf = CFG # This contains the configuration. At this time, many config variables are being ignored. ev = EVDispatcher( cf ) # In a way this is the core of the program. It dispatches events between each module # allowing for communications between each part of the program. It also loads # EventBridges, which route events like mouse position or clicks to the OS ui = UIManager( cf, ev ) # Loads one or more user interfaces cm = CommandMapper( cf, ev ) # Maps Wiimote keys and other events to commands like key presses or clicks while(True): btaddr = sys.stdin.readline() cf['MY_WIIMOTE_ADDR'] = btaddr.rstrip() if (cf['MY_WIIMOTE_ADDR']): wm = WMManager( cf, ev ) # Handles the Wiimote; connects to it, manages wiimote state and mode, parses wiimote reports #ms = MSManager( cf, ev, wm.id ) # Motion analysis po = POManager( cf, ev, wm.id ) # Handles the pointer, receives WM_IR, sends out ABS_POS absolute position reports if wm.connect() and wm.setup(): thread.start_new_thread(wm.main_loop, ()) wm.disconnect()
def __init__(self): """""" cf = CFG # This contains the configuration. At this time, many config variables are being ignored. ev = EVDispatcher(cf) # In a way this is the core of the program. It dispatches events between each module # allowing for communications between each part of the program. It also loads # EventBridges, which route events like mouse position or clicks to the OS UIManager(cf, ev) # Loads one or more user interfaces MSManager(cf, ev) # Motion analysis POManager(cf, ev) # Handles the pointer, receives WM_IR, sends out ABS_POS absolute position reports wm = WMManager(cf, ev) # Handles the Wiimote; connects to it, manages state and mode, parses reports CommandMapper(cf, ev) # Maps Wiimote keys and other events to commands like key presses or clicks if wm.connect() and wm.setup(): wm.main_loop() wm.disconnect()
elif buttons[0] == "L": os.popen2("xsendkeycode "+str(codeL)+" 0") elif buttons[0] == "R": os.popen2("xsendkeycode "+str(codeR)+" 0") def motion(accData): print accData['z'] #WiimoteSensitivityDelay += 1 if accData['z'] > 220: print "cambiando slide" os.popen2("xsendkeycode "+str(codeR)+" 1") os.popen2("xsendkeycode "+str(codeR)+" 0") #WiimoteSensitivityDelay = 0 cf = CFG ev = EVDispatcher(cf) ev.subscribe( WM_BT, wii_buttons) ev.subscribe( WM_ACC, motion) #Usar el mapper para mapear y no os.popen2 ms = MSManager( cf, ev ) wm = WMManager(cf, ev) wm.connect() wm.setup() wm.main_loop()
elif buttons[0] == "L": os.popen2("xsendkeycode " + str(codeL) + " 0") elif buttons[0] == "R": os.popen2("xsendkeycode " + str(codeR) + " 0") def motion(accData): print accData['z'] #WiimoteSensitivityDelay += 1 if accData['z'] > 220: print "cambiando slide" os.popen2("xsendkeycode " + str(codeR) + " 1") os.popen2("xsendkeycode " + str(codeR) + " 0") #WiimoteSensitivityDelay = 0 cf = CFG ev = EVDispatcher(cf) ev.subscribe(WM_BT, wii_buttons) ev.subscribe(WM_ACC, motion) #Usar el mapper para mapear y no os.popen2 ms = MSManager(cf, ev) wm = WMManager(cf, ev) wm.connect() wm.setup() wm.main_loop()