forked from mirror/joycontrol
removed unused imports, cleanup
This commit is contained in:
+17
-20
@@ -21,22 +21,8 @@ async def _send_empty_input_reports(transport):
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
async def _run_protocol_on_connection(protocol, client_itr, capture_file=None):
|
||||
transport = L2CAP_Transport(asyncio.get_event_loop(), protocol, client_itr, 50, capture_file=capture_file)
|
||||
protocol.connection_made(transport)
|
||||
|
||||
# send some empty input reports until the Switch decides to reply
|
||||
future = asyncio.ensure_future(_send_empty_input_reports(transport))
|
||||
await protocol.wait_for_output_report()
|
||||
future.cancel()
|
||||
try:
|
||||
await future
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
|
||||
|
||||
async def create_hid_server(protocol_factory,
|
||||
ctl_psm=17, itr_psm=19, device_id=None, reconnect_bt_addr=None, capture_file=None):
|
||||
async def create_hid_server(protocol_factory, ctl_psm=17, itr_psm=19, device_id=None, reconnect_bt_addr=None,
|
||||
capture_file=None):
|
||||
"""
|
||||
:param protocol_factory: Factory function returning a ControllerProtocol instance
|
||||
:param ctl_psm: hid control channel port
|
||||
@@ -46,10 +32,10 @@ async def create_hid_server(protocol_factory,
|
||||
Bluetooth mac address in string notation of the adapter (e.g. "FF:FF:FF:FF:FF:FF").
|
||||
If None, choose any device.
|
||||
Note: Selection of adapters may currently not work if the bluez "input" plugin is enabled.
|
||||
:param reconnect_bt_addr: the Bluetooth address of the console that was previously connected. Defaults to None.
|
||||
:param reconnect_bt_addr: The Bluetooth address of the console that was previously connected. Defaults to None.
|
||||
If None, a new hid server will be started for the initial paring.
|
||||
Otherwise, the function assumes an initial pairing with the console was already done and reconnects
|
||||
to the provided Bluetooth address.
|
||||
Otherwise, the function assumes an initial pairing with the console was already done
|
||||
and reconnects to the provided Bluetooth address.
|
||||
:param capture_file: opened file to log incoming and outgoing messages
|
||||
:returns transport for input reports and protocol which handles incoming output reports
|
||||
"""
|
||||
@@ -124,6 +110,17 @@ async def create_hid_server(protocol_factory,
|
||||
client_ctl.setblocking(False)
|
||||
client_itr.setblocking(False)
|
||||
|
||||
await _run_protocol_on_connection(protocol, client_itr, capture_file=capture_file)
|
||||
# create transport for the established connection and activate the HID protocol
|
||||
transport = L2CAP_Transport(asyncio.get_event_loop(), protocol, client_itr, 50, capture_file=capture_file)
|
||||
protocol.connection_made(transport)
|
||||
|
||||
# send some empty input reports until the Switch decides to reply
|
||||
future = asyncio.ensure_future(_send_empty_input_reports(transport))
|
||||
await protocol.wait_for_output_report()
|
||||
future.cancel()
|
||||
try:
|
||||
await future
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
|
||||
return protocol.transport, protocol
|
||||
|
||||
+8
-11
@@ -2,7 +2,6 @@ import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import socket
|
||||
from contextlib import contextmanager
|
||||
|
||||
from joycontrol import logging_default as log
|
||||
@@ -11,7 +10,6 @@ from joycontrol.controller import Controller
|
||||
from joycontrol.memory import FlashMemory
|
||||
from joycontrol.protocol import controller_protocol_factory
|
||||
from joycontrol.server import create_hid_server
|
||||
from joycontrol.report import InputReport
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -19,9 +17,8 @@ logger = logging.getLogger(__name__)
|
||||
async def _main(controller, reconnect_bt_addr=None, capture_file=None, spi_flash=None, device_id=None):
|
||||
factory = controller_protocol_factory(controller, spi_flash=spi_flash)
|
||||
ctl_psm, itr_psm = 17, 19
|
||||
transport, protocol = await create_hid_server(factory,
|
||||
reconnect_bt_addr=reconnect_bt_addr,
|
||||
ctl_psm=ctl_psm, itr_psm=itr_psm, capture_file=capture_file, device_id=device_id)
|
||||
transport, protocol = await create_hid_server(factory, reconnect_bt_addr=reconnect_bt_addr, ctl_psm=ctl_psm,
|
||||
itr_psm=itr_psm, capture_file=capture_file, device_id=device_id)
|
||||
|
||||
controller_state = protocol.get_controller_state()
|
||||
|
||||
@@ -47,7 +44,7 @@ if __name__ == '__main__':
|
||||
parser.add_argument('-d', '--device_id')
|
||||
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')
|
||||
help='The Switch console Bluetooth address, for reconnecting as an already paired controller')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.controller == 'JOYCON_R':
|
||||
@@ -81,9 +78,9 @@ if __name__ == '__main__':
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(
|
||||
_main(controller,
|
||||
reconnect_bt_addr=args.reconnect_bt_addr,
|
||||
capture_file=capture_file,
|
||||
spi_flash=spi_flash,
|
||||
device_id=args.device_id
|
||||
)
|
||||
reconnect_bt_addr=args.reconnect_bt_addr,
|
||||
capture_file=capture_file,
|
||||
spi_flash=spi_flash,
|
||||
device_id=args.device_id
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user