added OutputReportID

This commit is contained in:
Robert Martin
2020-02-02 20:35:32 +09:00
parent 38ff49ee04
commit 6f11ee0b22
2 changed files with 55 additions and 22 deletions
+35 -18
View File
@@ -4,7 +4,7 @@ from asyncio import BaseTransport, BaseProtocol
from typing import Optional, Union, Tuple, Text
from joycontrol.controller import Controller
from joycontrol.report import OutputReport, SubCommand, InputReport
from joycontrol.report import OutputReport, SubCommand, InputReport, OutputReportID
logger = logging.getLogger(__name__)
@@ -54,28 +54,45 @@ class ControllerProtocol(BaseProtocol):
logger.warning(f'Report parsing error "{v_err}" - IGNORE')
return
# classify sub command
sc_byte, sub_command = report.get_sub_command()
logging.info(f'received output report - {sub_command}')
if sub_command is None:
logger.warning(f'Received output report does not contain a sub command')
elif sub_command == SubCommand.REQUEST_DEVICE_INFO:
await self._command_request_device_info(report)
try:
output_report_id = report.get_output_report_id()
except NotImplementedError as err:
logger.warning(err)
return
elif sub_command == SubCommand.SET_SHIPMENT_STATE:
await self._command_set_shipment_state(report)
if output_report_id == OutputReportID.SUB_COMMAND:
# classify sub command
try:
sub_command = report.get_sub_command()
except NotImplementedError as err:
logger.warning(err)
return
elif sub_command == SubCommand.SPI_FLASH_READ:
await self._command_spi_flash_read(report)
if sub_command is None:
raise ValueError('Received output report does not contain a sub command')
elif sub_command == SubCommand.SET_INPUT_REPORT_MODE:
await self._command_set_input_report_mode(report)
logging.info(f'received output report - Sub command {sub_command}')
# answer to sub command
if sub_command == SubCommand.REQUEST_DEVICE_INFO:
await self._command_request_device_info(report)
elif sub_command == SubCommand.TRIGGER_BUTTONS_ELAPSED_TIME:
await self._command_trigger_buttons_elapsed_time(report)
elif sub_command == SubCommand.SET_SHIPMENT_STATE:
await self._command_set_shipment_state(report)
elif sub_command == SubCommand.NOT_IMPLEMENTED:
logger.warning(f'Sub command 0x{sc_byte:02x} not implemented - ignoring')
elif sub_command == SubCommand.SPI_FLASH_READ:
await self._command_spi_flash_read(report)
elif sub_command == SubCommand.SET_INPUT_REPORT_MODE:
await self._command_set_input_report_mode(report)
elif sub_command == SubCommand.TRIGGER_BUTTONS_ELAPSED_TIME:
await self._command_trigger_buttons_elapsed_time(report)
else:
logger.warning(f'Sub command 0x{sub_command.value:02x} not implemented - ignoring')
#elif output_report_id == OutputReportID.RUMBLE_ONLY:
# pass
else:
logger.warning(f'Output report {output_report_id} not implemented - ignoring')
async def _command_request_device_info(self, output_report):
address = self.transport.get_extra_info('sockname')