Esempio n. 1
0
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()

        # Create keyboard and mouse interface
        kmi = KMI(controller_state)
        # run the kmi
        try:
            await kmi.run()
        finally:
            logger.info('Stopping communication...')
            await transport.close()
Esempio n. 2
0
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()
Esempio n. 3
0
async def pre_init(app, 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()

    controller_state = protocol.get_controller_state()

    controller_state.l_stick_state.set_center()
    controller_state.r_stick_state.set_center()

    await controller_state.connect()
    
    app.stick = controller_state.l_stick_state
    calibration = app.stick.get_calibration()

    app.maxUp = calibration.v_center + calibration.v_max_above_center
    app.maxDown = calibration.v_center - calibration.v_max_below_center

    app.maxRight = calibration.h_center + calibration.h_max_above_center
    app.maxLeft = calibration.h_center - calibration.h_max_below_center

    app.vCenter = calibration.v_center
    app.hCenter = calibration.h_center
    app.globalController = controller_state
    
    app.stick.set_h(app.hCenter)
    app.stick.set_v(app.vCenter)
    async def get_controller(logger: Logger,
                             switch_mac_address=None,
                             spi_flash=None,
                             controller='PRO_CONTROLLER',
                             capture_file=None,
                             device_id=None):

        log.configure(logger.level, logger.level)
        if spi_flash:
            with open(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(controller)
        factory = controller_protocol_factory(controller, spi_flash=spi_flash)
        ctl_psm, itr_psm = 17, 19
        if switch_mac_address:
            logger.info("Pairing up with Switch MAC address: %s",
                        switch_mac_address)
        transport, protocol = await create_hid_server(
            factory,
            reconnect_bt_addr=switch_mac_address,
            ctl_psm=ctl_psm,
            itr_psm=itr_psm,
            capture_file=capture_file,
            device_id=device_id)

        controller_state: ControllerState = protocol.get_controller_state()

        return SwitchController(logger, controller_state)
Esempio n. 5
0
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()

        await controller_state.connect()

        ## RUN CONTROLLER CODE HERE
        await xbox(controller_state)

        await transport.close()
Esempio n. 6
0
async def _main():
    controller = Controller.from_arg("PRO_CONTROLLER")
    factory = controller_protocol_factory(controller, spi_flash=FlashMemory())
    print("waiting for 'Change Grip/Order' menu of the Switch.")
    transport, protocol = await create_hid_server(factory,
                                                  ctl_psm=17,
                                                  itr_psm=19)
    controller_state = protocol.get_controller_state()

    await controller_state.connect()
    print("controller connected.")

    await button_push(controller_state, "home", sec=0.1)
    await asyncio.sleep(1)
    await button_push(controller_state, "right", sec=0.1)
    await button_push(controller_state, "right", sec=0.1)
    await button_push(controller_state, "left", sec=0.1)

    await button_push(controller_state, "right", sec=0.1)
    await button_push(controller_state, "right", sec=0.1)
    await button_push(controller_state, "left", sec=0.1)

    await button_push(controller_state, "right", sec=0.1)
    await button_push(controller_state, "right", sec=0.1)
    await button_push(controller_state, "left", sec=0.1)

    controller_state.r_stick_state.set_right()
    await asyncio.sleep(60)
Esempio n. 7
0
    async def get_controller(reconnect_bt_addr=None,
                             spi_flash=None,
                             controller='PRO_CONTROLLER',
                             capture_file=None,
                             device_id=None):
        # parse the spi flash
        if spi_flash:
            with open(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(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=reconnect_bt_addr,
            ctl_psm=ctl_psm,
            itr_psm=itr_psm,
            capture_file=capture_file,
            device_id=device_id)

        controller_state: ControllerState = protocol.get_controller_state()

        return SwitchController(controller_state)
Esempio n. 8
0
async def _main(script,
                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)

    print("I'll wait for 10 seconds before executing the sequence.")
    await asyncio.sleep(10)

    Exec = ScriptExecutor()
    Exec.CtrlState = controller_state

    if "options" in script:
        Exec.Options = ScriptOptions.fromDict(script["options"])

    if "sequence" in script:
        await Exec.executeSequence(script["sequence"])

    logger.info('Stopping communication...')
    await transport.close()
Esempio n. 9
0
async def _main(bt_addr):
    # set up controller's flash memory data
    f = open('spi', 'rb')
    spi_flash = FlashMemory(f.read())
    f.close()

    # connect via bluetooth
    factory = controller_protocol_factory(Controller.PRO_CONTROLLER,
                                          spi_flash=spi_flash)
    transport, protocol = await create_hid_server(factory,
                                                  reconnect_bt_addr=bt_addr,
                                                  ctl_psm=17,
                                                  itr_psm=19)

    controller_state = protocol.get_controller_state()
    await controller_state.connect()
    print("Connected.")

    # start key listener thread
    keyboard_state = KeyboardState()
    listener = Listener(on_press=keyboard_state.key_down,
                        on_release=keyboard_state.key_up,
                        suppress=True)
    listener.start()

    # await button_push(controller_state, 'home', sec=5)
    pastTime = time.time()
    while listener.running:
        await main_loop(controller_state, keyboard_state)
Esempio n. 10
0
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()
    await controller_state.connect()
    con = NetController(controller_state)
    await con.run()
    logger.info('Stopping communication...')
    await transport.close()
Esempio n. 11
0
async def loader():
    if not os.geteuid() == 0:
        raise PermissionError('Script must be run as root!')
    transport, protocol = await create_hid_server(controller_protocol_factory(
        Controller.from_arg("PRO_CONTROLLER"), spi_flash=FlashMemory()),
                                                  ctl_psm=17,
                                                  itr_psm=19)
    controller_state = protocol.get_controller_state()
    return transport, controller_state
Esempio n. 12
0
async def get_shared_controller(server_address, capture_file=None):
    """Communicates with sharing server to setup a shared controller session.
    
    Given a sharing server address, returns a connected protocol object and a server socket.
    The protocol object is a connected session that contains 
    a ready-to-use controller state (running under 0x30 input mode).
    The server_conn is a socket object, which if written or make closed, 
    will close the connection to sharing server immediately. 
    Note that this function do only minimal error handling. 
    The caller is responsible for catching any exception and closing the server connection.

    Args:
        - server_address: a Unix socket path.
        - capture_file: opened file for capturing transport output (for this shared session).

    Returns:
        A pair of (protocol, server_conn).
    """

    loop = asyncio.get_event_loop()

    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    await loop.sock_connect(sock, server_address)

    data_len, = struct.unpack('i', await loop.sock_recv(sock, 4))

    msg, fds = recv_fds(sock, 2, 1)
    assert msg == b"fd"

    msg = b''
    while len(msg) < data_len:
        msg += await loop.sock_recv(sock, data_len - len(msg))

    msg = pickle.loads(msg)
    if msg.get("status") != "ok":
        raise ValueError("Failed to connect to controller server: {}".format(
            msg.get("msg", "unknown error")))

    client_itr = socket.fromfd(fds[0], socket.AF_BLUETOOTH,
                               socket.SOCK_SEQPACKET, socket.BTPROTO_L2CAP)
    controller, spi_flash = msg['controller'], msg['spi_flash']
    protocol = controller_protocol_factory(controller, spi_flash=spi_flash)()
    transport = L2CAP_Transport(asyncio.get_event_loop(),
                                protocol,
                                client_itr,
                                50,
                                capture_file=capture_file)
    protocol.connection_made(transport)

    # Start directly in input report 0x30 mode
    asyncio.ensure_future(protocol.input_report_mode_0x30())

    return protocol, sock
async def _main(controller, capture_file=None, spi_flash=None, device_id=None):
    factory = controller_protocol_factory(controller, spi_flash=spi_flash)
    transport, protocol = await create_hid_server(factory,
                                                  17,
                                                  19,
                                                  capture_file=capture_file,
                                                  device_id=device_id)

    await test_controller_buttons(protocol.get_controller_state())

    logger.info('Stopping communication...')
    await transport.close()
Esempio n. 14
0
async def setup(reconnect_bt_addr):
    global controller_state
    factory = controller_protocol_factory(Controller.PRO_CONTROLLER,
                                          spi_flash=FlashMemory())
    transport, protocol = await create_hid_server(
        factory,
        reconnect_bt_addr=reconnect_bt_addr,
        ctl_psm=17,
        itr_psm=19,
        capture_file=None,
        device_id=DEVICE)
    controller_state = protocol.get_controller_state()
    await controller_state.connect()
Esempio n. 15
0
async def loader(recon):
    if not os.geteuid() == 0:
        raise PermissionError('Script must be run as root!')
    transport, protocol, recon_addr = await create_hid_server(
        controller_protocol_factory(Controller.from_arg("PRO_CONTROLLER"),
                                    spi_flash=FlashMemory()),
        reconnect_bt_addr=recon,
        ctl_psm=17,
        itr_psm=19)
    controller_state = protocol.get_controller_state()
    with open("./.reconnect", "w+") as f:
        f.write(recon_addr)
    return transport, controller_state
Esempio n. 16
0
async def _main(controller, capture_file=None, spi_flash=None, device_id=None):
    factory = controller_protocol_factory(controller, spi_flash=spi_flash)
    transport, protocol = await create_hid_server(factory, 17, 19, capture_file=capture_file, device_id=device_id)

    try:
        await test_controller_buttons(protocol.get_controller_state())
    except KeyboardInterrupt:
        pass
    except NotConnectedError:
        logger.error('Connection was lost.')
    finally:
        logger.info('Stopping communication...')
        await transport.close()
Esempio n. 17
0
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()
Esempio n. 18
0
    async def create(self, configuration={}):
        """Initialize connection to the switch"""
        log.configure(logging.INFO)
        print("Connecting...")
        self.spi_flash = FlashMemory()
        self.controller = Controller.PRO_CONTROLLER

        self.factory = controller_protocol_factory(
            self.controller, spi_flash=self.spi_flash
        )
        self.transport, self.protocol = await create_hid_server(
            self.factory, reconnect_bt_addr=configuration.get("reconnect_bt_addr")
        )
        self.controller_state = self.protocol.get_controller_state()
        print("Connected!")
Esempio n. 19
0
 async def init(self,mac):   
     self.spi_flash = FlashMemory()
     self.controller = Controller.PRO_CONTROLLER
     factory = controller_protocol_factory(self.controller, spi_flash=self.spi_flash)
     ctl_psm, itr_psm = 17, 19
     self.transport, self.protocol, self.macAddress = await create_hid_server(factory, reconnect_bt_addr=mac,
                                                  ctl_psm=ctl_psm,
                                                  itr_psm=itr_psm,
                                                  )
     self.controller_state = self.protocol.get_controller_state()
     print("found switch initializing controller data")
     await self.controller_state.connect()
     print(self.macAddress)
     self.connected = True
     print("ready to use!")
Esempio n. 20
0
async def _main(date_list_):
    controller_ = Controller.PRO_CONTROLLER
    factory = controller_protocol_factory(controller_)
    transport, protocol = await create_hid_server(factory, 17, 19)

    dr = protocol.get_controller_state()
    while 1:
        if await dr.connect():
            print("蓝牙连接成功......")
            break

    mAutoJoy = auto_joy.AutoJoy(dr, date_list_[0], date_list_[1],
                                date_list_[2])
    await mAutoJoy.run()
    logger.info('Stopping communication...')
    await transport.close()
Esempio n. 21
0
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()
Esempio n. 22
0
    async def get_controller(logger: Logger,
                             switch_mac_address=None,
                             spi_flash=None,
                             controller='PRO_CONTROLLER',
                             capture_file=None,
                             device_id=None):
        logger.info("Simulating a %s controller.", controller)
        if spi_flash:
            with open(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(controller)
        factory = controller_protocol_factory(controller, spi_flash=spi_flash)
        ctl_psm, itr_psm = 17, 19
        if switch_mac_address:
            logger.info("Pairing with Switch MAC address: %s",
                        switch_mac_address)
        while True:
            try:
                transport, protocol = await create_hid_server(
                    factory,
                    reconnect_bt_addr=switch_mac_address,
                    ctl_psm=ctl_psm,
                    itr_psm=itr_psm,
                    capture_file=capture_file,
                    device_id=device_id)

                controller_state: ControllerState = protocol.get_controller_state(
                )
                break
            except:
                # TODO Try to wake the Switch up from sleep.
                wait_s = 3
                logger.exception(
                    "Error pairing. Make sure your Switch is on."
                    " Will try again in %ds.", wait_s)
                await asyncio.sleep(wait_s)

        logger.info("Simulated %s paired.", controller.name)
        return SwitchController(logger, controller_state)
Esempio n. 23
0
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

        if args.bt_addr_file is not None:
            bt_addr = open(args.bt_addr_file, "r").read()
            if bt_addr == "ANY":
                bt_addr = None
        else:
            bt_addr = args.reconnect_bt_addr

        transport, protocol = await create_hid_server(
            factory,
            reconnect_bt_addr=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 socket interface and add some extra commands
        socket_interface = ControllerSocketInterface(args.socket,
                                                     controller_state)
        _register_commands_with_controller_state(controller_state,
                                                 socket_interface)

        # run the socket_interface
        await socket_interface.start_server()
        return socket_interface, transport
Esempio n. 24
0
async def main(args, q):
    # parse the spi flash
    logger.name = "CLI进程"
    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()
        joycontrol_http.controller_state = controller_state
        method = controller_state.button_state.set_button
        q.put(method)
        logger.debug("controller开始监听")
        while True:
            await asyncio.sleep(0.1)
            if q.empty():
                continue
            msg = q.get()
            if isinstance(msg, Command):
                if msg.target == "controller":
                    if msg.cmd == "btn_push":
                        from joycontrol.controller_state import button_push
                        await button_push(controller_state, msg.obj)
Esempio n. 25
0
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()
Esempio n. 26
0
    async def run_joycontrol(self):
        factory = controller_protocol_factory(Controller.PRO_CONTROLLER)
        ctl_psm, itr_psm = 17, 19
        transport, protocol = await create_hid_server(factory,
                                                      ctl_psm=ctl_psm,
                                                      itr_psm=itr_psm)
        controller_state = protocol.get_controller_state()

        #controller_state.l_stick_state.set_center()
        #controller_state.r_stick_state.set_center()

        await controller_state.connect()
        print("connected")
        self.proctrl.connected = True
        self.draw()

        while True:
            func = await self.joycontrol_q.async_q.get()
            if func != None:
                func(controller_state)
                await controller_state.send()
            else:
                break
Esempio n. 27
0
    async def start(self, args):
        # Create memory containing default controller stick calibration
        spi_flash = FlashMemory()

        # Get controller name to emulate from arguments
        controller = Controller.from_arg('PRO_CONTROLLER')

        with utils.get_output(path=None, 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()
            self.transport = transport

            try:
                # waits until controller is fully connected
                await controller_state.connect()
                joycontrol_plugin = self.__load_plugin(args.plugin,
                                                       controller_state,
                                                       args.plugin_options)
                await joycontrol_plugin.run()
            except Exception as e:
                logger.error(e)
            finally:
                logger.info('Stopping communication...')
                await transport.close()
                self.transport = None
                self.joycontrol_cmd = None
Esempio n. 28
0
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()
Esempio n. 29
0
async def _main(args):

    # Create memory containing default controller stick calibration
    spi_flash = FlashMemory()

    # Get controller name to emulate from arguments
    controller = Controller.PRO_CONTROLLER

    with utils.get_output(path=args.log, default=None) as capture_file:
        factory = controller_protocol_factory(controller, spi_flash=spi_flash)
        transport, protocol = await create_hid_server(
            factory, ctl_psm=17, itr_psm=19, capture_file=capture_file)

        controller_state = protocol.get_controller_state()

        # Create command line interface and add some extra commands
        cli = command.CCLI(controller_state)

        try:
            await controller_state.connect()
            await cli.run()
        finally:
            logger.info('Stopping communication...')
            await transport.close()
Esempio n. 30
0
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()