async def recording_playback(controller_state: ControllerState): #This method replays saved recordings if controller_state.get_controller() != Controller.PRO_CONTROLLER: raise ValueError('This script only works with the Pro Controller!') # waits until controller is fully connected await controller_state.connect() savedRecordings = shelve.open('savedRecs', writeback=True) LeftStick = controller_state.l_stick_state RightStick = controller_state.r_stick_state recList = list(savedRecordings.keys()) print('Saved Recordings:') print(recList) print('Enter the name of the recording you want to playback') print('Then press <enter> to start playback.') recordingName = await ainput(prompt='Recording name:') if recordingName in recList: recording = savedRecordings[recordingName] speed_factor = 1 last_time = None for event in recording: if speed_factor > 0 and last_time is not None: time.sleep((event.time - last_time) / speed_factor) last_time = event.time key = event.scan_code or event.name btnTrans = keyToConBtn(key) await directStateSet(btnTrans, controller_state) if event.event_type == keyboard.KEY_DOWN else await directStateUNSet(btnTrans, controller_state) keyboard.unhook_all() ControllerCLI._set_stick(RightStick, 'center', None) ControllerCLI._set_stick(LeftStick, 'center', None) await controller_state.send() else: print('Recording name not recognized')
async def _main(controller, reconnect_bt_addr=None, capture_file=None, spi_flash=None, device_id=None): factory = controller_protocol_factory(controller, spi_flash=spi_flash) ctl_psm, itr_psm = 17, 19 transport, protocol = await create_hid_server( factory, reconnect_bt_addr=reconnect_bt_addr, ctl_psm=ctl_psm, itr_psm=itr_psm, capture_file=capture_file, device_id=device_id) controller_state = protocol.get_controller_state() # Create command line interface and add some extra commands cli = ControllerCLI(controller_state) # Wrap the script so we can pass the controller state. The doc string will be printed when calling 'help' async def _run_test_controller_buttons(): """ test_buttons - Navigates to the "Test Controller Buttons" menu and presses all buttons. """ await test_controller_buttons(controller_state) # add the script from above cli.add_command('test_buttons', _run_test_controller_buttons) await cli.run() logger.info('Stopping communication...') await transport.close()
async def record_keyboard( controller_state: ControllerState ): #this method binds keyboard to conroller and records input for later playback if controller_state.get_controller() != Controller.PRO_CONTROLLER: raise ValueError('This script only works with the Pro Controller!') # waits until controller is fully connected await controller_state.connect() print('Using only letters and numbers, type a name for this recording') print('Then press <enter> to start recording keyboard control.') recordingName = await ainput(prompt='Recording name:') #pixels = neopixel.NeoPixel(board.D12, 6, auto_write=False) #button state handler callbacks savedRecordings = shelve.open('savedRecs', writeback=True) LeftStick = controller_state.l_stick_state RightStick = controller_state.r_stick_state bindKeyboard(controller_state) keyboard.start_recording() pixels.fill((0, 0, 0)) pixels.fill((10, 0, 0)) pixels.fill((10, 0, 0)) await ainput( prompt='Press <enter> to stop recording and exit keyboard control.') recording = keyboard.stop_recording() pixels.fill((0, 0, 0)) pixels.fill((0, 0, 0)) keyboard.unhook_all() savedRecordings[recordingName] = recording savedRecordings.close() ControllerCLI._set_stick(RightStick, 'center', None) ControllerCLI._set_stick(LeftStick, 'center', None) await controller_state.send()
async def _main(args): # parse the spi flash if args.spi_flash: with open(args.spi_flash, 'rb') as spi_flash_file: spi_flash = FlashMemory(spi_flash_file.read()) else: # Create memory containing default controller stick calibration spi_flash = FlashMemory() # Get controller name to emulate from arguments controller = Controller.from_arg(args.controller) with utils.get_output(path=args.log, default=None) as capture_file: # prepare the the emulated controller factory = controller_protocol_factory(controller, spi_flash=spi_flash) ctl_psm, itr_psm = 17, 19 transport, protocol = await create_hid_server( factory, reconnect_bt_addr=args.reconnect_bt_addr, ctl_psm=ctl_psm, itr_psm=itr_psm, capture_file=capture_file, device_id=args.device_id) controller_state = protocol.get_controller_state() joycon_server = JoyConRestfull() th = threading.Thread(target=joycon_server.run) th.start() # Create command line interface and add some extra commands cli = ControllerCLI(controller_state, queue) _register_commands_with_controller_state(controller_state, cli) cli.add_command( 'amiibo', ControllerCLI.deprecated( 'Command was removed - use "nfc" instead!')) # set default nfc content supplied by argument if args.nfc is not None: await cli.commands['nfc'](args.nfc) #asyncio.ensure_future(cli.run()) #asyncio.ensure_future(app.run(port='5002')) # run the cli try: await cli.run() finally: logger.info('Stopping communication...') await transport.close()
async def directStateUNSet(btnTrans, controller_state: ControllerState): #this method sets button/stick states during recording playback (button RELEASE/ stick CENTER) LeftStick = controller_state.l_stick_state RightStick = controller_state.r_stick_state btnsList = ['x', 'y', 'b', 'a', 'plus', 'minus', 'home', 'capture', 'zl', 'zr', 'l', 'r', 'up', 'down', 'left', 'right'] lStickList = ['lStickUp', 'lStickDown', 'lStickL', 'lStickR'] rStickList = ['rStickUp', 'rStickDown', 'rStickL', 'rStickR'] if btnTrans in btnsList: controller_state.button_state.set_button(btnTrans, pushed=False) await controller_state.send() elif btnTrans in lStickList: ControllerCLI._set_stick(LeftStick, 'center', None) await controller_state.send() elif btnTrans in rStickList: ControllerCLI._set_stick(RightStick, 'center', None) await controller_state.send()
async def keyboard_control(controller_state: ControllerState):# this method binds keyboard to controller for CLI keyboard control of switch if controller_state.get_controller() != Controller.PRO_CONTROLLER: raise ValueError('This script only works with the Pro Controller!') # waits until controller is fully connected await controller_state.connect() await ainput(prompt='Press <enter> to start keyboard control.') #button state handler callbacks LeftStick = controller_state.l_stick_state RightStick = controller_state.r_stick_state bindKeyboard(controller_state) await ainput(prompt='Press <enter> to exit keyboard control.') keyboard.unhook_all() ControllerCLI._set_stick(RightStick, 'center', None) ControllerCLI._set_stick(LeftStick, 'center', None) await controller_state.send()
async def _main(args): # parse the spi flash if args.spi_flash: with open(args.spi_flash, 'rb') as spi_flash_file: spi_flash = FlashMemory(spi_flash_file.read()) else: # Create memory containing default controller stick calibration spi_flash = FlashMemory() # Get controller name to emulate from arguments controller = Controller.from_arg(args.controller) with utils.get_output(path=args.log, default=None) as capture_file: factory = controller_protocol_factory(controller, spi_flash=spi_flash) ctl_psm, itr_psm = 17, 19 transport, protocol = await create_hid_server( factory, reconnect_bt_addr=args.reconnect_bt_addr, ctl_psm=ctl_psm, itr_psm=itr_psm, capture_file=capture_file, device_id=args.device_id) controller_state = protocol.get_controller_state() # Create command line interface and add some extra commands cli = ControllerCLI(controller_state) # Wrap the script so we can pass the controller state. The doc string will be printed when calling 'help' async def _run_Controller(): ''' - Controller ''' await xbox(controller_state) # add the script from above #cli.add_command('mash', call_mash_button) cli.add_command('Controller', _run_Controller) cli.add_command('controller', _run_Controller) try: await cli.run() finally: logger.info('Stopping communication...') await transport.close()
async def _main(server_address, capture_file=None): # We don't need to catch anything here # just raise and exit the program if fails to connect protocol, server_conn = await get_shared_controller(server_address, capture_file=capture_file) print("You are using a shared controller. " "You may exit the program at any time to yield the controller back to the sharing server.") controller_state = protocol.get_controller_state() cli = ControllerCLI(controller_state) await cli.run() logger.info('Yielding controller back to the sharing server...') server_conn.close()
async def _main(controller, capture_file=None, spi_flash=None): factory = controller_protocol_factory(controller, spi_flash=spi_flash) transport, protocol = await create_hid_server(factory, 17, 19, capture_file=capture_file) controller_state = protocol.get_controller_state() cli = ControllerCLI(controller_state) await cli.run() logger.info('Stopping communication...') await transport.close()
async def _main(controller, reconnect_bt_addr=None, capture_file=None, spi_flash=None, device_id=None): factory = controller_protocol_factory(controller, spi_flash=spi_flash) ctl_psm, itr_psm = 17, 19 transport, protocol = await create_hid_server( factory, reconnect_bt_addr=reconnect_bt_addr, ctl_psm=ctl_psm, itr_psm=itr_psm, capture_file=capture_file, device_id=device_id) controller_state = protocol.get_controller_state() cli = ControllerCLI(controller_state) await cli.run() logger.info('Stopping communication...') await transport.close()
async def _main(controller, capture_file=None, spi_flash=None, device_id=None, share_controller_address=None): factory = controller_protocol_factory(controller, spi_flash=spi_flash) global transport, protocol transport, protocol = await create_hid_server(factory, 17, 19, capture_file=capture_file, device_id=device_id) controller_state = protocol.get_controller_state() if share_controller_address is not None: asyncio.ensure_future( start_share_controller_server(protocol, share_controller_address)) cli = ControllerCLI(controller_state) await cli.run() logger.info('Stopping communication...') await transport.close()
async def _main(args): # parse the spi flash if args.spi_flash: with open(args.spi_flash, 'rb') as spi_flash_file: spi_flash = FlashMemory(spi_flash_file.read()) else: # Create memory containing default controller stick calibration spi_flash = FlashMemory() # Get controller name to emulate from arguments controller = Controller.from_arg(args.controller) async def nfc(*args): if controller_state.get_controller() == Controller.JOYCON_L: raise ValueError('NFC content cannot be set for JOYCON_L') elif not args: raise ValueError('"nfc" command requires file path to an nfc dump as argument!') elif args[0] == 'remove': controller_state.set_nfc(None) print('Removed nfc content.') else: _loop = asyncio.get_event_loop() with open(args[0], 'rb') as nfc_file: content = await _loop.run_in_executor(None, nfc_file.read) controller_state.set_nfc(content) with utils.get_output(path=args.log, default=None) as capture_file: # prepare the the emulated controller factory = controller_protocol_factory(controller, spi_flash=spi_flash) ctl_psm, itr_psm = 17, 19 draw.text((x, top + 16), str("Waiting for Switch to"), font=font, fill=255) draw.text((x + 40, top + 24), str("Connect,"), font=font, fill=255) draw.text((x + 18, top + 40), str("Please open the"), font=font, fill=255) draw.text((x + 6, top + 48), str("'Change Grip/Order'"), font=font, fill=255) draw.text((x + 46, top + 56), str("menu."), font=font, fill=255) disp.image(image) disp.display() transport, protocol = await create_hid_server(factory, reconnect_bt_addr=args.reconnect_bt_addr, ctl_psm=ctl_psm, itr_psm=itr_psm, capture_file=capture_file, device_id=args.device_id) controller_state = protocol.get_controller_state() # Create command line interface and add some extra commands cli = ControllerCLI(controller_state) # set default nfc content supplied by argument if args.nfc is not None: await cli.commands['nfc'](args.nfc) # run the cli try: await nfc(args.nfc) await run_at_start(controller_state) #await cli.run() finally: logger.info('Stopping communication...') await transport.close()
def DownRStickPress(self): ControllerCLI._set_stick(RightStick, 'down', None)
def UpRStickPress(self): ControllerCLI._set_stick(RightStick, 'up', None)
def __init__(self, controller_state): self.cli = ControllerCLI(controller_state) self.controller_state = controller_state self.__max_stick_power = MAX_STICK_POWER
def LeftRStickPress(self): ControllerCLI._set_stick(RightStick, 'left', None)
def RightRStickPress(self): ControllerCLI._set_stick(RightStick, 'right', None)
def UpLStickPress(self): ControllerCLI._set_stick(LeftStick, 'up', None)
def LStickUnpress(self): ControllerCLI._set_stick(LeftStick, 'center', None)
async def xbox( controller_state: ControllerState ): # this method binds keyboard to controller for CLI keyboard control of switch if controller_state.get_controller() != Controller.PRO_CONTROLLER: raise ValueError('This script only works with the Pro Controller!') # waits until controller is fully connected await controller_state.connect() lv = 0 lh = 0 rv = 0 rh = 0 #button state handler callbacks Working = True start_time = time.time() while Working: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: Working = False break if event.type == pygame.USEREVENT: pygame.time.set_timer(pygame.USEREVENT, 0) Working = False break LeftStick = controller_state.l_stick_state RightStick = controller_state.r_stick_state joysticks = [ pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count()) ] for i in range(pygame.joystick.get_count()): joysticks[i].init() for i in range(pygame.joystick.get_count()): #Left Stick if round(lh, -1) != round( 2048 + joysticks[i].get_axis(0) * 1792, -1) or round( lv, -1) != round( 2048 + joysticks[i].get_axis(1) * 1792, -1): lh = (2048 + joysticks[i].get_axis(0) * 1792) lv = (2048 - joysticks[i].get_axis(1) * 1792) if lh < 2150 and lh > 1950: lh = 2048 if lv < 2150 and lv > 1950: lv = 2048 ControllerCLI._set_stick(LeftStick, 'h', lh) ControllerCLI._set_stick(LeftStick, 'v', lv) #Right Stick if round(rh, -1) != round( 2048 + joysticks[i].get_axis(3) * 1792, -1) or round( rv, -1) != round( 2048 + joysticks[i].get_axis(4) * 1792, -1): rh = (2048 + joysticks[i].get_axis(3) * 1792) rv = (2048 - joysticks[i].get_axis(4) * 1792) if rh < 2150 and rh > 1950: rh = 2048 if rv < 2150 and rv > 1950: rv = 2048 ControllerCLI._set_stick(RightStick, 'h', rh) ControllerCLI._set_stick(RightStick, 'v', rv) #Triggers if joysticks[i].get_axis(2) >= 0.2: controller_state.button_state.set_button('zl') else: controller_state.button_state.set_button('zl', pushed=False) if joysticks[i].get_axis(5) >= -0.2: controller_state.button_state.set_button('zr') else: controller_state.button_state.set_button('zr', pushed=False) #Buttons if joysticks[i].get_button(0) == 1: #B controller_state.button_state.set_button('b') else: controller_state.button_state.set_button('b', pushed=False) if joysticks[i].get_button(1) == 1: #A controller_state.button_state.set_button('a') else: controller_state.button_state.set_button('a', pushed=False) if joysticks[i].get_button(2) == 1: #Y controller_state.button_state.set_button('y') else: controller_state.button_state.set_button('y', pushed=False) if joysticks[i].get_button(3) == 1: #X controller_state.button_state.set_button('x') else: controller_state.button_state.set_button('x', pushed=False) #Trigger Buttons if joysticks[i].get_button(4) == 1: #Left controller_state.button_state.set_button('l') else: controller_state.button_state.set_button('l', pushed=False) if joysticks[i].get_button(5) == 1: #Right controller_state.button_state.set_button('r') else: controller_state.button_state.set_button('r', pushed=False) #Other Buttons if joysticks[i].get_button(6) == 1: #Minius controller_state.button_state.set_button('minus') else: controller_state.button_state.set_button('minus', pushed=False) if joysticks[i].get_button(7) == 1: #plus controller_state.button_state.set_button('plus') else: controller_state.button_state.set_button('plus', pushed=False) if joysticks[i].get_button(8) == 1: #Home controller_state.button_state.set_button('home') else: controller_state.button_state.set_button('home', pushed=False) if joysticks[i].get_button(9) == 1: #Left Stick Click controller_state.button_state.set_button('l_stick') else: controller_state.button_state.set_button('l_stick', pushed=False) if joysticks[i].get_button(10) == 1: #Right Stick Click controller_state.button_state.set_button('r_stick') else: controller_state.button_state.set_button('r_stick', pushed=False) #Dpad hat = joysticks[i].get_hat(0) if hat[0] == 1: #Right controller_state.button_state.set_button('right') else: controller_state.button_state.set_button('right', pushed=False) if hat[0] == -1: #Left controller_state.button_state.set_button('left') else: controller_state.button_state.set_button('left', pushed=False) if hat[1] == 1: #Up controller_state.button_state.set_button('up') else: controller_state.button_state.set_button('up', pushed=False) if hat[1] == -1: #Down controller_state.button_state.set_button('down') else: controller_state.button_state.set_button('down', pushed=False) await controller_state.send()
async def _main(args): # parse the spi flash if args.spi_flash: with open(args.spi_flash, 'rb') as spi_flash_file: spi_flash = FlashMemory(spi_flash_file.read()) else: # Create memory containing default controller stick calibration spi_flash = FlashMemory() # Get controller name to emulate from arguments controller = Controller.from_arg(args.controller) with utils.get_output(path=args.log, default=None) as capture_file: factory = controller_protocol_factory(controller, spi_flash=spi_flash) ctl_psm, itr_psm = 17, 19 transport, protocol = await create_hid_server( factory, reconnect_bt_addr=args.reconnect_bt_addr, ctl_psm=ctl_psm, itr_psm=itr_psm, capture_file=capture_file, device_id=args.device_id) controller_state = protocol.get_controller_state() # Create command line interface and add some extra commands cli = ControllerCLI(controller_state) # Wrap the script so we can pass the controller state. The doc string will be printed when calling 'help' async def _run_test_controller_buttons(): """ test_buttons - Navigates to the "Test Controller Buttons" menu and presses all buttons. """ await test_controller_buttons(controller_state) # add the script from above cli.add_command('test_buttons', _run_test_controller_buttons) # Mash a button command async def call_mash_button(*args): """ mash - Mash a specified button at a set interval Usage: mash <button> <interval> """ if not len(args) == 2: raise ValueError( '"mash_button" command requires a button and interval as arguments!' ) button, interval = args await mash_button(controller_state, button, interval) # add the script from above cli.add_command('mash', call_mash_button) # Create nfc command async def nfc(*args): """ nfc - Sets nfc content Usage: nfc <file_name> Set controller state NFC content to file nfc remove Remove NFC content from controller state """ if controller_state.get_controller() == Controller.JOYCON_L: raise ValueError('NFC content cannot be set for JOYCON_L') elif not args: raise ValueError( '"nfc" command requires file path to an nfc dump as argument!' ) elif args[0] == 'remove': controller_state.set_nfc(None) print('Removed nfc content.') else: await set_nfc(controller_state, args[0]) # add the script from above cli.add_command('nfc', nfc) cli.add_command( 'amiibo', ControllerCLI.deprecated( 'Command is deprecated - use "nfc" instead!')) if args.nfc is not None: await nfc(args.nfc) eventToButton = { 304: 'b', 305: 'a', 307: 'y', 308: 'x', 704: 'left', 705: 'right', 706: 'up', 707: 'down', 311: 'r', 310: 'l', 312: 'zl', 313: 'zr', 314: 'minus', 315: 'plus', 317: 'l_stick', 318: 'r_stick', } device = evdev.InputDevice( "/dev/input/by-id/usb-045e_0291-event-joystick") caps = device.capabilities() try: t1 = time.perf_counter() cnt = 0 async for event in device.async_read_loop(): if event.type == ecodes.EV_SYN: lasttask = asyncio.ensure_future( sync_controller(controller_state)) if event.type == ecodes.EV_ABS: if event.code == 0: controller_state.l_stick_state.set_h(event.value // 22 + 2048) elif event.code == 1: controller_state.l_stick_state.set_v( -(event.value - 15) // 22 + 2047) elif event.code == 3: controller_state.r_stick_state.set_h(event.value // 22 + 2048) elif event.code == 4: controller_state.r_stick_state.set_v( -(event.value - 15) // 22 + 2047) elif event.type == ecodes.EV_KEY: if event.code in eventToButton: buttonCode = eventToButton[event.code] button_set_state(controller_state, buttonCode, event) if event.code == 305: if event.value == 1: if controller_state.button_state.get_button( 'zr'): button_set_state(controller_state, 'home', event) else: button_set_state(controller_state, 'home', event) lasttask = asyncio.ensure_future( sync_controller(controller_state)) cnt = cnt + 1 if cnt > 50: cnt = 0 t2 = time.perf_counter() deltaT = t2 - t1 freq = 50.00 / deltaT str = " 50 event takes " + format( deltaT, '.2f') + " secs freq = " + format(freq, '.2f') logger.info(str) t1 = t2 except: logger.info('unexpected') logger.info(sys.exc_info()[0]) finally: logger.info('Stopping communication...') await transport.close()
async def _main(args): # parse the spi flash if args.spi_flash: with open(args.spi_flash, 'rb') as spi_flash_file: spi_flash = FlashMemory(spi_flash_file.read()) else: # Create memory containing default controller stick calibration spi_flash = FlashMemory() # Get controller name to emulate from arguments controller = Controller.from_arg(args.controller) with utils.get_output(path=args.log, default=None) as capture_file: factory = controller_protocol_factory(controller, spi_flash=spi_flash) ctl_psm, itr_psm = 17, 19 transport, protocol = await create_hid_server( factory, reconnect_bt_addr=args.reconnect_bt_addr, ctl_psm=ctl_psm, itr_psm=itr_psm, capture_file=capture_file, device_id=args.device_id) controller_state = protocol.get_controller_state() # Create command line interface and add some extra commands cli = ControllerCLI(controller_state) # Wrap the script so we can pass the controller state. The doc string will be printed when calling 'help' async def _run_test_control(): """ test_control - test method that will be removed later """ await test_control(controller_state) async def _run_keyboard_control(): """ keyboard - binds controls to keyboard. Keybinding: q=LEFT w=LstickUP e=UP r=ZL t=L y=R u=ZR i=RstickUP a=LstickLEFT s=LstickDOWN d=LstickRIGHT f=RIGHT g=capture h=home j=RstickLEFT k=RStickDOWN l=RstickRIGHT c=DOWN up=X down=B left=Y right=A plus= + minus= - """ await keyboard_control(controller_state) async def _run_recording_control(): """ recording - binds controls to keyboard, and records input until recording stopped. saved recordings can be replayed using cmd >> recording_playback Keybinding: q=LEFT w=LstickUP e=UP r=ZL t=L y=R u=ZR i=RstickUP a=LstickLEFT s=LstickDOWN d=LstickRIGHT f=RIGHT g=capture h=home j=RstickLEFT k=RStickDOWN l=RstickRIGHT c=DOWN up=X down=B left=Y right=A plus= + minus= - """ await record_keyboard(controller_state) async def _run_recording_playback(): """ playback - select a saved recording and replay it """ await recording_playback(controller_state) async def _run_delete_recording(): """ delete_rec - select a saved recording and delete it """ await delete_recording(controller_state) async def _run_test_controller_buttons(): """ test_buttons - Navigates to the "Test Controller Buttons" menu and presses all buttons. """ await test_controller_buttons(controller_state) # Mash a button command async def call_mash_button(*args): """ mash - Mash a specified button at a set interval Usage: mash <button> <interval> """ if not len(args) == 2: raise ValueError( '"mash_button" command requires a button and interval as arguments!' ) button, interval = args await mash_button(controller_state, button, interval) # Create nfc command async def nfc(*args): """ nfc - Sets nfc content Usage: nfc <file_name> Set controller state NFC content to file nfc remove Remove NFC content from controller state """ if controller_state.get_controller() == Controller.JOYCON_L: raise ValueError('NFC content cannot be set for JOYCON_L') elif not args: raise ValueError( '"nfc" command requires file path to an nfc dump as argument!' ) elif args[0] == 'remove': controller_state.set_nfc(None) print('Removed nfc content.') else: await set_nfc(controller_state, args[0]) cli.add_command('test_buttons', _run_test_controller_buttons) cli.add_command('keyboard', _run_keyboard_control) cli.add_command('recording', _run_recording_control) cli.add_command('playback', _run_recording_playback) cli.add_command('delete_rec', _run_delete_recording) cli.add_command('mash', call_mash_button) # add the script from above cli.add_command('nfc', nfc) if args.nfc is not None: await nfc(args.nfc) try: await cli.run() finally: logger.info('Stopping communication...') await transport.close()
def DownLStickPress(self): ControllerCLI._set_stick(LeftStick, 'down', None)
async def directStateSet( btnTrans, controller_state: ControllerState ): #this method sets button/stick states during recording playback (button PRESS/ stick UDLR) LeftStick = controller_state.l_stick_state RightStick = controller_state.r_stick_state btnsList = [ 'x', 'y', 'b', 'a', 'plus', 'minus', 'home', 'capture', 'zl', 'zr', 'l', 'r', 'up', 'down', 'left', 'right' ] lStickList = ['lStickUp', 'lStickDown', 'lStickL', 'lStickR'] rStickList = ['rStickUp', 'rStickDown', 'rStickL', 'rStickR'] if btnTrans in btnsList: #print(btnTrans) controller_state.button_state.set_button(btnTrans) await controller_state.send() elif btnTrans in lStickList: #print(btnTrans) if btnTrans == 'lStickDown': ControllerCLI._set_stick(LeftStick, 'down', None) await controller_state.send() elif btnTrans == 'lStickUp': ControllerCLI._set_stick(LeftStick, 'up', None) await controller_state.send() elif btnTrans == 'lStickL': ControllerCLI._set_stick(LeftStick, 'left', None) await controller_state.send() elif btnTrans == 'lStickR': ControllerCLI._set_stick(LeftStick, 'right', None) await controller_state.send() elif btnTrans in rStickList: if btnTrans == 'rStickDown': ControllerCLI._set_stick(RightStick, 'down', None) await controller_state.send() elif btnTrans == 'rStickUp': ControllerCLI._set_stick(RightStick, 'up', None) await controller_state.send() elif btnTrans == 'rStickL': ControllerCLI._set_stick(RightStick, 'left', None) await controller_state.send() elif btnTrans == 'rStickR': ControllerCLI._set_stick(RightStick, 'right', None) await controller_state.send()
def RStickUnpress(self): ControllerCLI._set_stick(RightStick, 'center', None)
async def _main(args): # parse the spi flash if args.spi_flash: with open(args.spi_flash, 'rb') as spi_flash_file: spi_flash = FlashMemory(spi_flash_file.read()) else: # Create memory containing default controller stick calibration spi_flash = FlashMemory() # Get controller name to emulate from arguments controller = Controller.from_arg(args.controller) with utils.get_output(path=args.log, default=None) as capture_file: factory = controller_protocol_factory(controller, spi_flash=spi_flash) ctl_psm, itr_psm = 17, 19 transport, protocol = await create_hid_server( factory, reconnect_bt_addr=args.reconnect_bt_addr, ctl_psm=ctl_psm, itr_psm=itr_psm, capture_file=capture_file, device_id=args.device_id) controller_state = protocol.get_controller_state() # Create command line interface and add some extra commands cli = ControllerCLI(controller_state) # Wrap the script so we can pass the controller state. The doc string will be printed when calling 'help' async def _run_test_controller_buttons(): """ test_buttons - Navigates to the "Test Controller Buttons" menu and presses all buttons. """ await test_controller_buttons(controller_state) # add the script from above cli.add_command('test_buttons', _run_test_controller_buttons) # Create amiibo command async def amiibo(*args): """ amiibo - Sets amiibo content Usage: amiibo <file_name> Set controller state NFC content to file amiibo remove Remove NFC content from controller state """ if controller_state.get_controller() == Controller.JOYCON_L: raise ValueError('NFC content cannot be set for JOYCON_L') elif not args: raise ValueError( '"amiibo" command requires amiibo dump file path as argument!' ) elif args[0] == 'remove': controller_state.set_nfc(None) print('Removed nfc content.') else: await set_amiibo(controller_state, args[0]) # add the script from above cli.add_command('amiibo', amiibo) try: await cli.run() finally: logger.info('Stopping communication...') await transport.close()
def LeftLStickPress(self): ControllerCLI._set_stick(LeftStick, 'left', None)