Skip to content

Commit

Permalink
Hotfix: Make controller emulation work on new Switch version
Browse files Browse the repository at this point in the history
  • Loading branch information
mart1nro committed Apr 15, 2020
1 parent ac28b4e commit e904993
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions joycontrol/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

async def _send_empty_input_reports(transport):
report = InputReport()
while True:
for i in range(10):
await transport.write(report)
await asyncio.sleep(1)

Expand Down Expand Up @@ -117,13 +117,15 @@ async def create_hid_server(protocol_factory, ctl_psm=17, itr_psm=19, device_id=
transport = L2CAP_Transport(asyncio.get_event_loop(), protocol, client_itr, client_ctl, 50, capture_file=capture_file)
protocol.connection_made(transport)

# send some empty input reports until the Switch decides to reply
# HACK: 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
6 changes: 4 additions & 2 deletions joycontrol/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ async def _reader(self):
self._read_thread = None
break

#logger.debug(f'received "{list(data)}"')
await self._protocol.report_received(data, self._itr_sock.getpeername())

def start_reader(self):
Expand Down Expand Up @@ -99,6 +98,8 @@ async def read(self):
await self._is_reading.wait()
data = await self._loop.sock_recv(self._itr_sock, self._read_buffer_size)

# logger.debug(f'received "{list(data)}"')

if not data:
# disconnect happened
logger.error('No data received.')
Expand Down Expand Up @@ -146,7 +147,8 @@ async def write(self, data: Any) -> None:
size = struct.pack('i', len(_bytes))
self._capture_file.write(_time + size + _bytes)

#logger.debug(f'sending "{_bytes}"')
# logger.debug(f'sending "{_bytes}"')

try:
await self._loop.sock_sendall(self._itr_sock, _bytes)
except OSError as err:
Expand Down

0 comments on commit e904993

Please sign in to comment.