Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: flow control issues #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions joycontrol/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,16 @@ async def input_report_mode_full(self):
reply_send = await self._reply_to_sub_command(report)
elif output_report_id == OutputReportID.REQUEST_IR_NFC_MCU:
# TODO NFC
raise NotImplementedError('NFC communictation is not implemented.')
raise NotImplementedError('NFC communication is not implemented.')
else:
logger.warning(f'Report unknown output report "{output_report_id}" - IGNORE')
except ValueError as v_err:
logger.warning(f'Report parsing error "{v_err}" - IGNORE')
except NotImplementedError as err:
logger.warning(err)

if reply_send:
# Hack: Adding a delay here to avoid flooding during pairing
await asyncio.sleep(0.3)
else:
# only send controller state when player light is set
if not reply_send and self.sig_set_player_lights.is_set():
# write 0x30 input report.
# TODO: set some sensor data
input_report.set_6axis_data()
Expand Down
10 changes: 9 additions & 1 deletion joycontrol/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def create_hid_server(protocol_factory, ctl_psm=17, itr_psm=19, device_id=
itr_sock.setblocking(False)
ctl_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
itr_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

try:
hid = HidDevice(device_id=device_id)

Expand Down Expand Up @@ -113,6 +113,14 @@ async def create_hid_server(protocol_factory, ctl_psm=17, itr_psm=19, device_id=
client_ctl.setblocking(False)
client_itr.setblocking(False)

# The bluetooth adapter will send in the correct interval as the switch expects
# But the socket has a send buffer and blocks when the buffer is full.
# setting this low allows the write method to not block for a long time, as the buffer will
# be send fairly quick. Example:
# - default on my machine 212992: ~4 seconds
# - 4096: ~250ms
client_itr.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 4096)

# create transport for the established connection and activate the HID protocol
transport = L2CAP_Transport(asyncio.get_event_loop(), protocol, client_itr, client_ctl, 50, capture_file=capture_file)
protocol.connection_made(transport)
Expand Down