moved timer byte setting of input report to protocol class

This commit is contained in:
Robert Martin
2020-03-09 16:54:38 +09:00
parent 945043c136
commit c856459dfc
2 changed files with 12 additions and 10 deletions
+11 -4
View File
@@ -27,19 +27,22 @@ class ControllerProtocol(BaseProtocol):
self.transport = None
self._input_report_timer = 0x00
self._data_received = asyncio.Event()
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.sig_set_player_lights = asyncio.Event()
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)
if self._controller_state.l_stick_state is None:
l_stick = [0x00, 0x00, 0x00]
@@ -51,6 +54,10 @@ class ControllerProtocol(BaseProtocol):
r_stick = self._controller_state.r_stick_state
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)
self._controller_state.sig_is_send.set()
+1 -6
View File
@@ -86,13 +86,8 @@ class L2CAP_Transport(asyncio.Transport):
async def write(self, data: Any) -> None:
if isinstance(data, bytes):
_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:
raise ValueError('data must be bytes or InputReport')
_bytes = bytes(data)
if self._capture_file is not None:
# write data to log file