forked from mirror/joycontrol
implemented controller joy sticks
This commit is contained in:
@@ -2,6 +2,7 @@ import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
from contextlib import contextmanager
|
||||
|
||||
from joycontrol import logging_default as log
|
||||
from joycontrol.controller_state import ControllerState, button_push
|
||||
@@ -33,7 +34,7 @@ async def test_controller_buttons(controller_state: ControllerState):
|
||||
await asyncio.sleep(0.3)
|
||||
|
||||
# go all the way down
|
||||
await button_push(controller_state, 'down', sec=3)
|
||||
await button_push(controller_state, 'down', sec=4)
|
||||
await asyncio.sleep(0.3)
|
||||
|
||||
# goto "Controllers and Sensors" menu
|
||||
@@ -57,24 +58,22 @@ async def test_controller_buttons(controller_state: ControllerState):
|
||||
await button_push(controller_state, 'a')
|
||||
await asyncio.sleep(0.3)
|
||||
|
||||
# push all buttons
|
||||
button_list = ['y', 'x', 'b', 'a', 'r', 'zr',
|
||||
'minus', 'plus', 'r_stick', 'l_stick',
|
||||
'down', 'up', 'right', 'left', 'l', 'zl']
|
||||
# push all buttons except home and capture
|
||||
button_list = controller_state.button_state.get_available_buttons()
|
||||
if 'capture' in button_list:
|
||||
button_list.remove('capture')
|
||||
if 'home' in button_list:
|
||||
button_list.remove('home')
|
||||
|
||||
for i in range(10):
|
||||
for button in button_list:
|
||||
await button_push(controller_state, button)
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
|
||||
async def _main(args):
|
||||
spi_flash = None
|
||||
if args.spi_flash:
|
||||
with open(args.spi_flash, 'rb') as spi_flash_file:
|
||||
spi_flash = spi_flash_file.read()
|
||||
|
||||
factory = controller_protocol_factory(Controller.PRO_CONTROLLER, spi_flash=spi_flash)
|
||||
transport, protocol = await create_hid_server(factory, 17, 19)
|
||||
async def _main(controller, capture_file=None, spi_flash=None):
|
||||
factory = controller_protocol_factory(controller, spi_flash=spi_flash)
|
||||
transport, protocol = await create_hid_server(factory, 17, 19, capture_file=capture_file)
|
||||
|
||||
await test_controller_buttons(protocol.get_controller_state())
|
||||
|
||||
@@ -87,12 +86,45 @@ if __name__ == '__main__':
|
||||
if not os.geteuid() == 0:
|
||||
raise PermissionError('Script must be run as root!')
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--spi_flash')
|
||||
args = parser.parse_args()
|
||||
|
||||
# setup logging
|
||||
log.configure()
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(_main(args))
|
||||
parser = argparse.ArgumentParser()
|
||||
#parser.add_argument('controller', help='JOYCON_R, JOYCON_L or PRO_CONTROLLER')
|
||||
parser.add_argument('-l', '--log')
|
||||
parser.add_argument('--spi_flash')
|
||||
args = parser.parse_args()
|
||||
|
||||
"""
|
||||
if args.controller == 'JOYCON_R':
|
||||
controller = Controller.JOYCON_R
|
||||
elif args.controller == 'JOYCON_L':
|
||||
controller = Controller.JOYCON_L
|
||||
elif args.controller == 'PRO_CONTROLLER':
|
||||
controller = Controller.PRO_CONTROLLER
|
||||
else:
|
||||
raise ValueError(f'Unknown controller "{args.controller}".')
|
||||
"""
|
||||
controller = Controller.PRO_CONTROLLER
|
||||
|
||||
spi_flash = None
|
||||
if args.spi_flash:
|
||||
with open(args.spi_flash, 'rb') as spi_flash_file:
|
||||
spi_flash = spi_flash_file.read()
|
||||
|
||||
# creates file if arg is given
|
||||
@contextmanager
|
||||
def get_output(path=None):
|
||||
"""
|
||||
Opens file if path is given
|
||||
"""
|
||||
if path is not None:
|
||||
file = open(path, 'wb')
|
||||
yield file
|
||||
file.close()
|
||||
else:
|
||||
yield None
|
||||
|
||||
with get_output(args.log) as capture_file:
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(_main(controller, capture_file=capture_file, spi_flash=spi_flash))
|
||||
|
||||
Reference in New Issue
Block a user