From cf156478917570a8c69524c18faefb4ef9785072 Mon Sep 17 00:00:00 2001 From: grace Date: Tue, 2 Jun 2020 00:19:02 -0700 Subject: [PATCH 1/2] add an --amiibo argument to command line --- run_controller_cli.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/run_controller_cli.py b/run_controller_cli.py index a6dc278..fa3bce7 100644 --- a/run_controller_cli.py +++ b/run_controller_cli.py @@ -26,6 +26,7 @@ Usage: [--spi_flash ] [--reconnect_bt_addr | -r ] [--log | -l ] + [--amiibo ] run_controller_cli.py -h | --help Arguments: @@ -47,6 +48,8 @@ Options: Does not require the "Change Grip/Order" menu to be opened, -l --log Write hid communication (input reports and output reports) to a file. + + --amiibo Sets an amiibo dump file to the controller upon initial connection. """ @@ -238,6 +241,9 @@ async def _main(args): # add the script from above cli.add_command('amiibo', amiibo) + if args.amiibo is not None: + await amiibo(args.amiibo) + try: await cli.run() finally: @@ -261,6 +267,7 @@ if __name__ == '__main__': 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') + parser.add_argument('--amiibo', type=str, default=None) args = parser.parse_args() loop = asyncio.get_event_loop() From fee9e719c6bf20753c7fc59af49a4e66c391d261 Mon Sep 17 00:00:00 2001 From: Robert Martin Date: Thu, 11 Jun 2020 17:47:57 +0200 Subject: [PATCH 2/2] renamed nfc data command and argument (Now: nfc and --nfc) --- joycontrol/command_line_interface.py | 7 ++++++ run_controller_cli.py | 37 +++++++++++++++------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/joycontrol/command_line_interface.py b/joycontrol/command_line_interface.py index fb5a870..d3b5f90 100644 --- a/joycontrol/command_line_interface.py +++ b/joycontrol/command_line_interface.py @@ -89,6 +89,13 @@ class CLI: else: print('command', cmd, 'not found, call help for help.') + @staticmethod + def deprecated(message): + async def dep_printer(*args, **kwargs): + print(message) + + return dep_printer + class ControllerCLI(CLI): def __init__(self, controller_state: ControllerState): diff --git a/run_controller_cli.py b/run_controller_cli.py index fa3bce7..c90e506 100644 --- a/run_controller_cli.py +++ b/run_controller_cli.py @@ -26,7 +26,7 @@ Usage: [--spi_flash ] [--reconnect_bt_addr | -r ] [--log | -l ] - [--amiibo ] + [--nfc ] run_controller_cli.py -h | --help Arguments: @@ -49,7 +49,8 @@ Options: -l --log Write hid communication (input reports and output reports) to a file. - --amiibo Sets an amiibo dump file to the controller upon initial connection. + --nfc Sets the nfc data of the controller to a given nfc dump upon initial + connection. """ @@ -135,16 +136,16 @@ async def test_controller_buttons(controller_state: ControllerState): await button_push(controller_state, 'home') -async def set_amiibo(controller_state, file_path): +async def set_nfc(controller_state, file_path): """ Sets nfc content of the controller state to contents of the given file. :param controller_state: Emulated controller state - :param file_path: Path to amiibo dump file + :param file_path: Path to nfc dump file """ loop = asyncio.get_event_loop() - with open(file_path, 'rb') as amiibo_file: - content = await loop.run_in_executor(None, amiibo_file.read) + with open(file_path, 'rb') as nfc_file: + content = await loop.run_in_executor(None, nfc_file.read) controller_state.set_nfc(content) @@ -219,30 +220,32 @@ async def _main(args): # add the script from above cli.add_command('mash', call_mash_button) - # Create amiibo command - async def amiibo(*args): + # Create nfc command + async def nfc(*args): """ - amiibo - Sets nfc content + nfc - Sets nfc content Usage: - amiibo Set controller state NFC content to file - amiibo remove Remove NFC content from controller state + nfc 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('"amiibo" command requires file path to an nfc dump as argument!') + 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_amiibo(controller_state, args[0]) + await set_nfc(controller_state, args[0]) # add the script from above - cli.add_command('amiibo', amiibo) + cli.add_command('nfc', nfc) + cli.add_command('amiibo', ControllerCLI.deprecated('Command is deprecated - use "nfc" instead!')) - if args.amiibo is not None: - await amiibo(args.amiibo) + + if args.nfc is not None: + await nfc(args.nfc) try: await cli.run() @@ -267,7 +270,7 @@ if __name__ == '__main__': 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') - parser.add_argument('--amiibo', type=str, default=None) + parser.add_argument('--nfc', type=str, default=None) args = parser.parse_args() loop = asyncio.get_event_loop()