forked from mirror/joycontrol
DRY button validation
This commit is contained in:
+8
-12
@@ -150,11 +150,7 @@ async def set_nfc(controller_state, file_path):
|
|||||||
|
|
||||||
|
|
||||||
async def mash_button(controller_state, button, interval):
|
async def mash_button(controller_state, button, interval):
|
||||||
# waits until controller is fully connected
|
await ensure_valid_button(controller_state, button)
|
||||||
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()}')
|
|
||||||
|
|
||||||
user_input = asyncio.ensure_future(
|
user_input = asyncio.ensure_future(
|
||||||
ainput(prompt=f'Pressing the {button} button every {interval} seconds... Press <enter> to stop.')
|
ainput(prompt=f'Pressing the {button} button every {interval} seconds... Press <enter> to stop.')
|
||||||
@@ -169,24 +165,24 @@ async def mash_button(controller_state, button, interval):
|
|||||||
|
|
||||||
|
|
||||||
async def hold_button(controller_state, button):
|
async def hold_button(controller_state, button):
|
||||||
# waits until controller is fully connected
|
await ensure_valid_button(controller_state, button)
|
||||||
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)
|
await button_down(controller_state, button)
|
||||||
|
|
||||||
|
|
||||||
async def release_button(controller_state, button):
|
async def release_button(controller_state, button):
|
||||||
|
await ensure_valid_button(controller_state, button)
|
||||||
|
|
||||||
|
await button_up(controller_state, button)
|
||||||
|
|
||||||
|
|
||||||
|
async def ensure_valid_button(controller_state, button):
|
||||||
# waits until controller is fully connected
|
# waits until controller is fully connected
|
||||||
await controller_state.connect()
|
await controller_state.connect()
|
||||||
|
|
||||||
if button not in controller_state.button_state.get_available_buttons():
|
if button not in controller_state.button_state.get_available_buttons():
|
||||||
raise ValueError(f'Button {button} does not exist on {controller_state.get_controller()}')
|
raise ValueError(f'Button {button} does not exist on {controller_state.get_controller()}')
|
||||||
|
|
||||||
await button_up(controller_state, button)
|
|
||||||
|
|
||||||
|
|
||||||
async def _main(args):
|
async def _main(args):
|
||||||
# parse the spi flash
|
# parse the spi flash
|
||||||
|
|||||||
Reference in New Issue
Block a user