コード例 #1
0
    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)
コード例 #2
0
def main():
    # check if root
    if not os.geteuid() == 0:
        raise PermissionError('Script must be run as root!')

    parser = argparse.ArgumentParser()
    parser.add_argument('plugin', type=str, help='joycontrol plugin path')
    parser.add_argument('-p',
                        '--plugin-options',
                        nargs='*',
                        help='joycontrol plugin options')
    parser.add_argument('-d', '--device_id')
    parser.add_argument(
        '-r',
        '--reconnect_bt_addr',
        type=str,
        default=None,
        help=
        'The Switch console Bluetooth address, for reconnecting as an already paired controller'
    )
    parser.add_argument('-v', '--verbose', action='store_true')
    args = parser.parse_args()

    if args.verbose:
        log.configure()
    else:
        log.configure(console_level=logging.INFO)

    loop = asyncio.get_event_loop()
    loader = PluginLoader()

    try:
        loop.run_until_complete(loader.start(args))
    except KeyboardInterrupt:
        loop.run_until_complete(loader.stop())
コード例 #3
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!")
コード例 #4
0
        try:
            await cli.run()
        finally:
            logger.info('Stopping communication...')
            await transport.close()


if __name__ == '__main__':
    # check if root
    if not os.geteuid() == 0:
        raise PermissionError('Script must be run as root!')

    # setup logging
    #log.configure(console_level=logging.ERROR)
    log.configure()

    parser = argparse.ArgumentParser()
    parser.add_argument('controller',
                        help='JOYCON_R, JOYCON_L or PRO_CONTROLLER')
    parser.add_argument('-l', '--log')
    parser.add_argument('-d', '--device_id')
    parser.add_argument('--spi_flash')
    parser.add_argument(
        '-r',
        '--reconnect_bt_addr',
        type=str,
        default=None,
        help=
        'The Switch console Bluetooth address, for reconnecting as an already paired controller'
    )
コード例 #5
0
import argparse
import asyncio
import logging
import os
import socket
import struct
import time
import hid
from joycontrol import logging_default as log, utils
from joycontrol.device import HidDevice
from joycontrol.server import PROFILE_PATH
from joycontrol.utils import AsyncHID
logger = logging.getLogger(__name__)
VENDOR_ID = 1406
PRODUCT_ID_JL = 8198
PRODUCT_ID_JR = 8199
PRODUCT_ID_PC = 8201

class Relay:
    def __init__(self, capture_file=None):
        self._capture_file = capture_file
    async def relay_input(self, hid_device, client_itr):
        loop = asyncio.get_event_loop()
        while True:
            data = await hid_device.read(100)
            # add adding byte for input report
            data = b'\xa1' + data
            if self._capture_file is not None:
                # write data to log file
                current_time = struct.pack('d', time.time())
コード例 #6
0
    # add the script from above
    cli.add_command('test_buttons', _run_test_controller_buttons)

    await cli.run()

    logger.info('Stopping communication...')
    await transport.close()


if __name__ == '__main__':
    # check if root
    if not os.geteuid() == 0:
        raise PermissionError('Script must be run as root!')

    # setup logging
    log.configure(console_level=logging.ERROR)
    log.configure()

    parser = argparse.ArgumentParser()
    parser.add_argument('controller',
                        help='JOYCON_R, JOYCON_L or PRO_CONTROLLER')
    parser.add_argument('-l', '--log')
    parser.add_argument('-d', '--device_id')
    parser.add_argument('--spi_flash')
    parser.add_argument(
        '-r',
        '--reconnect_bt_addr',
        type=str,
        default=None,
        help=
        'The Switch console Bluetooth address, for reconnecting as an already paired controller'
コード例 #7
0
ファイル: controller.py プロジェクト: Woebenskie/AmiiboPI
        # 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()



if __name__ == '__main__':
    # check if root
    if not os.geteuid() == 0:
        raise PermissionError('Script must be run as root!')

    # setup logging
    log.configure(console_level=logging.INFO)

    parser = argparse.ArgumentParser()
    parser.add_argument('controller', help='JOYCON_R, JOYCON_L or PRO_CONTROLLER')
    parser.add_argument('--nfc', type=str, default=None)
    args = parser.parse_args()

    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        _main(args)
    )
コード例 #8
0
    cli = ControllerCLI(controller_state)
    await cli.run()

    logger.info('Stopping communication...')
    await transport.close()


if __name__ == '__main__':
    # check if root
    if not os.geteuid() == 0:
        raise PermissionError('Script must be run as root!')

    # setup logging
    #log.configure(console_level=logging.ERROR)
    log.configure(console_level=logging.DEBUG)

    parser = argparse.ArgumentParser()
    parser.add_argument('controller',
                        help='JOYCON_R, JOYCON_L or PRO_CONTROLLER')
    parser.add_argument('-l', '--log')
    parser.add_argument('-d', '--device_id')
    parser.add_argument('--spi_flash')
    parser.add_argument('-s',
                        '--share-controller',
                        action="store_true",
                        help="Optional. Set to true to share this controller")
    parser.add_argument(
        '--share-controller-address',
        default=None,
        type=str,
コード例 #9
0
ファイル: controller.py プロジェクト: qtuu/switch-remoteplay
 def configure_log(level):
     log.configure(level, level)