forked from mirror/joycontrol
renamed nfc data command and argument (Now: nfc and --nfc)
This commit is contained in:
@@ -89,6 +89,13 @@ class CLI:
|
|||||||
else:
|
else:
|
||||||
print('command', cmd, 'not found, call help for help.')
|
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):
|
class ControllerCLI(CLI):
|
||||||
def __init__(self, controller_state: ControllerState):
|
def __init__(self, controller_state: ControllerState):
|
||||||
|
|||||||
+20
-17
@@ -26,7 +26,7 @@ Usage:
|
|||||||
[--spi_flash <spi_flash_memory_file>]
|
[--spi_flash <spi_flash_memory_file>]
|
||||||
[--reconnect_bt_addr | -r <console_bluetooth_address>]
|
[--reconnect_bt_addr | -r <console_bluetooth_address>]
|
||||||
[--log | -l <communication_log_file>]
|
[--log | -l <communication_log_file>]
|
||||||
[--amiibo <amiibo_bin_file>]
|
[--nfc <nfc_data_file>]
|
||||||
run_controller_cli.py -h | --help
|
run_controller_cli.py -h | --help
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
@@ -49,7 +49,8 @@ Options:
|
|||||||
|
|
||||||
-l --log <communication_log_file> Write hid communication (input reports and output reports) to a file.
|
-l --log <communication_log_file> Write hid communication (input reports and output reports) to a file.
|
||||||
|
|
||||||
--amiibo <amiibo_bin_file> Sets an amiibo dump file to the controller upon initial connection.
|
--nfc <nfc_data_file> 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')
|
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.
|
Sets nfc content of the controller state to contents of the given file.
|
||||||
:param controller_state: Emulated controller state
|
: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()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
with open(file_path, 'rb') as amiibo_file:
|
with open(file_path, 'rb') as nfc_file:
|
||||||
content = await loop.run_in_executor(None, amiibo_file.read)
|
content = await loop.run_in_executor(None, nfc_file.read)
|
||||||
controller_state.set_nfc(content)
|
controller_state.set_nfc(content)
|
||||||
|
|
||||||
|
|
||||||
@@ -219,30 +220,32 @@ async def _main(args):
|
|||||||
# add the script from above
|
# add the script from above
|
||||||
cli.add_command('mash', call_mash_button)
|
cli.add_command('mash', call_mash_button)
|
||||||
|
|
||||||
# Create amiibo command
|
# Create nfc command
|
||||||
async def amiibo(*args):
|
async def nfc(*args):
|
||||||
"""
|
"""
|
||||||
amiibo - Sets nfc content
|
nfc - Sets nfc content
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
amiibo <file_name> Set controller state NFC content to file
|
nfc <file_name> Set controller state NFC content to file
|
||||||
amiibo remove Remove NFC content from controller state
|
nfc remove Remove NFC content from controller state
|
||||||
"""
|
"""
|
||||||
if controller_state.get_controller() == Controller.JOYCON_L:
|
if controller_state.get_controller() == Controller.JOYCON_L:
|
||||||
raise ValueError('NFC content cannot be set for JOYCON_L')
|
raise ValueError('NFC content cannot be set for JOYCON_L')
|
||||||
elif not args:
|
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':
|
elif args[0] == 'remove':
|
||||||
controller_state.set_nfc(None)
|
controller_state.set_nfc(None)
|
||||||
print('Removed nfc content.')
|
print('Removed nfc content.')
|
||||||
else:
|
else:
|
||||||
await set_amiibo(controller_state, args[0])
|
await set_nfc(controller_state, args[0])
|
||||||
|
|
||||||
# add the script from above
|
# 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:
|
try:
|
||||||
await cli.run()
|
await cli.run()
|
||||||
@@ -267,7 +270,7 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('--spi_flash')
|
parser.add_argument('--spi_flash')
|
||||||
parser.add_argument('-r', '--reconnect_bt_addr', type=str, default=None,
|
parser.add_argument('-r', '--reconnect_bt_addr', type=str, default=None,
|
||||||
help='The Switch console Bluetooth address, for reconnecting as an already paired controller')
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|||||||
Reference in New Issue
Block a user