forked from mirror/joycontrol
moved timer byte setting of input report to protocol class
This commit is contained in:
+11
-4
@@ -27,19 +27,22 @@ class ControllerProtocol(BaseProtocol):
|
|||||||
|
|
||||||
self.transport = None
|
self.transport = None
|
||||||
|
|
||||||
|
self._input_report_timer = 0x00
|
||||||
|
|
||||||
self._data_received = asyncio.Event()
|
self._data_received = asyncio.Event()
|
||||||
|
|
||||||
self._controller_state = ControllerState(self, controller, spi_flash=spi_flash)
|
self._controller_state = ControllerState(self, controller, spi_flash=spi_flash)
|
||||||
|
|
||||||
self._pending_write = None
|
|
||||||
self._pending_input_report = None
|
|
||||||
|
|
||||||
self._0x30_input_report_sender = None
|
self._0x30_input_report_sender = None
|
||||||
|
|
||||||
self.sig_set_player_lights = asyncio.Event()
|
self.sig_set_player_lights = asyncio.Event()
|
||||||
|
|
||||||
async def write(self, input_report: InputReport):
|
async def write(self, input_report: InputReport):
|
||||||
# set button and stick data
|
"""
|
||||||
|
Sets timer byte and current button state in the input report and sends it.
|
||||||
|
Fires sig_is_send event afterwards.
|
||||||
|
"""
|
||||||
|
# set button and stick data of input report
|
||||||
input_report.set_button_status(self._controller_state.button_state)
|
input_report.set_button_status(self._controller_state.button_state)
|
||||||
if self._controller_state.l_stick_state is None:
|
if self._controller_state.l_stick_state is None:
|
||||||
l_stick = [0x00, 0x00, 0x00]
|
l_stick = [0x00, 0x00, 0x00]
|
||||||
@@ -51,6 +54,10 @@ class ControllerProtocol(BaseProtocol):
|
|||||||
r_stick = self._controller_state.r_stick_state
|
r_stick = self._controller_state.r_stick_state
|
||||||
input_report.set_stick_status(l_stick, r_stick)
|
input_report.set_stick_status(l_stick, r_stick)
|
||||||
|
|
||||||
|
# set timer byte of input report
|
||||||
|
input_report.set_timer(self._input_report_timer)
|
||||||
|
self._input_report_timer = (self._input_report_timer + 1) % 0x100
|
||||||
|
|
||||||
await self.transport.write(input_report)
|
await self.transport.write(input_report)
|
||||||
self._controller_state.sig_is_send.set()
|
self._controller_state.sig_is_send.set()
|
||||||
|
|
||||||
|
|||||||
@@ -86,13 +86,8 @@ class L2CAP_Transport(asyncio.Transport):
|
|||||||
async def write(self, data: Any) -> None:
|
async def write(self, data: Any) -> None:
|
||||||
if isinstance(data, bytes):
|
if isinstance(data, bytes):
|
||||||
_bytes = data
|
_bytes = data
|
||||||
elif isinstance(data, InputReport):
|
|
||||||
# set timer byte of input report
|
|
||||||
data.set_timer(self._input_report_timer)
|
|
||||||
self._input_report_timer = (self._input_report_timer + 1) % 256
|
|
||||||
_bytes = bytes(data)
|
|
||||||
else:
|
else:
|
||||||
raise ValueError('data must be bytes or InputReport')
|
_bytes = bytes(data)
|
||||||
|
|
||||||
if self._capture_file is not None:
|
if self._capture_file is not None:
|
||||||
# write data to log file
|
# write data to log file
|
||||||
|
|||||||
Reference in New Issue
Block a user