add hold and release commands to cli

This commit is contained in:
grace
2020-07-10 23:07:44 -07:00
parent 7a19841a2c
commit 2581296c15
+53 -1
View File
@@ -10,7 +10,7 @@ from aioconsole import ainput
from joycontrol import logging_default as log, utils
from joycontrol.command_line_interface import ControllerCLI
from joycontrol.controller import Controller
from joycontrol.controller_state import ControllerState, button_push
from joycontrol.controller_state import ControllerState, button_push, button_down, button_up
from joycontrol.memory import FlashMemory
from joycontrol.protocol import controller_protocol_factory
from joycontrol.server import create_hid_server
@@ -168,6 +168,26 @@ async def mash_button(controller_state, button, interval):
await user_input
async def hold_button(controller_state, button):
# waits until controller is fully connected
await controller_state.connect()
if button not in controller_state.button_state.get_available_buttons():
raise ValueError(f'Button {button} does not exist on {controller_state.get_controller()}')
await button_down(controller_state, button)
async def release_button(controller_state, button):
# waits until controller is fully connected
await controller_state.connect()
if button not in controller_state.button_state.get_available_buttons():
raise ValueError(f'Button {button} does not exist on {controller_state.get_controller()}')
await button_up(controller_state, button)
async def _main(args):
# parse the spi flash
if args.spi_flash:
@@ -220,6 +240,38 @@ async def _main(args):
# add the script from above
cli.add_command('mash', call_mash_button)
# Hold a button command
async def hold(*args):
"""
hold - Press and hold a specified button
Usage:
hold <button>
"""
if not args:
raise ValueError('"hold" command requires a button!')
await hold_button(controller_state, args[0])
# add the script from above
cli.add_command('hold', hold)
# Release a button command
async def release(*args):
"""
release - Release a held button
Usage:
release <button>
"""
if not args:
raise ValueError('"release" command requires a button!')
await release_button(controller_state, args[0])
# add the script from above
cli.add_command('release', release)
# Create nfc command
async def nfc(*args):
"""