forked from mirror/joycontrol
added OutputReportID
This commit is contained in:
+35
-18
@@ -4,7 +4,7 @@ from asyncio import BaseTransport, BaseProtocol
|
|||||||
from typing import Optional, Union, Tuple, Text
|
from typing import Optional, Union, Tuple, Text
|
||||||
|
|
||||||
from joycontrol.controller import Controller
|
from joycontrol.controller import Controller
|
||||||
from joycontrol.report import OutputReport, SubCommand, InputReport
|
from joycontrol.report import OutputReport, SubCommand, InputReport, OutputReportID
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -54,28 +54,45 @@ class ControllerProtocol(BaseProtocol):
|
|||||||
logger.warning(f'Report parsing error "{v_err}" - IGNORE')
|
logger.warning(f'Report parsing error "{v_err}" - IGNORE')
|
||||||
return
|
return
|
||||||
|
|
||||||
# classify sub command
|
try:
|
||||||
sc_byte, sub_command = report.get_sub_command()
|
output_report_id = report.get_output_report_id()
|
||||||
logging.info(f'received output report - {sub_command}')
|
except NotImplementedError as err:
|
||||||
if sub_command is None:
|
logger.warning(err)
|
||||||
logger.warning(f'Received output report does not contain a sub command')
|
return
|
||||||
elif sub_command == SubCommand.REQUEST_DEVICE_INFO:
|
|
||||||
await self._command_request_device_info(report)
|
|
||||||
|
|
||||||
elif sub_command == SubCommand.SET_SHIPMENT_STATE:
|
if output_report_id == OutputReportID.SUB_COMMAND:
|
||||||
await self._command_set_shipment_state(report)
|
# 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:
|
if sub_command is None:
|
||||||
await self._command_spi_flash_read(report)
|
raise ValueError('Received output report does not contain a sub command')
|
||||||
|
|
||||||
elif sub_command == SubCommand.SET_INPUT_REPORT_MODE:
|
logging.info(f'received output report - Sub command {sub_command}')
|
||||||
await self._command_set_input_report_mode(report)
|
# 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:
|
elif sub_command == SubCommand.SET_SHIPMENT_STATE:
|
||||||
await self._command_trigger_buttons_elapsed_time(report)
|
await self._command_set_shipment_state(report)
|
||||||
|
|
||||||
elif sub_command == SubCommand.NOT_IMPLEMENTED:
|
elif sub_command == SubCommand.SPI_FLASH_READ:
|
||||||
logger.warning(f'Sub command 0x{sc_byte:02x} not implemented - ignoring')
|
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):
|
async def _command_request_device_info(self, output_report):
|
||||||
address = self.transport.get_extra_info('sockname')
|
address = self.transport.get_extra_info('sockname')
|
||||||
|
|||||||
+20
-4
@@ -137,7 +137,11 @@ class SubCommand(Enum):
|
|||||||
SET_SHIPMENT_STATE = 0x08
|
SET_SHIPMENT_STATE = 0x08
|
||||||
SPI_FLASH_READ = 0x10
|
SPI_FLASH_READ = 0x10
|
||||||
ENABLE_6AXIS_SENSOR = 0x40
|
ENABLE_6AXIS_SENSOR = 0x40
|
||||||
NOT_IMPLEMENTED = 0xFF
|
|
||||||
|
|
||||||
|
class OutputReportID(Enum):
|
||||||
|
SUB_COMMAND = 0x01
|
||||||
|
RUMBLE_ONLY = 0x10
|
||||||
|
|
||||||
|
|
||||||
class OutputReport:
|
class OutputReport:
|
||||||
@@ -146,13 +150,25 @@ class OutputReport:
|
|||||||
raise ValueError('Output reports must start with 0xA2')
|
raise ValueError('Output reports must start with 0xA2')
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
|
def get_output_report_id(self):
|
||||||
|
try:
|
||||||
|
return OutputReportID(self.data[1])
|
||||||
|
except ValueError:
|
||||||
|
raise NotImplementedError(f'Output report id {self.data[1]}')
|
||||||
|
|
||||||
|
def get_timer(self):
|
||||||
|
return OutputReportID(self.data[2])
|
||||||
|
|
||||||
|
def get_rumble_data(self):
|
||||||
|
return self.data[3:11]
|
||||||
|
|
||||||
def get_sub_command(self):
|
def get_sub_command(self):
|
||||||
if len(self.data) < 12:
|
if len(self.data) < 12:
|
||||||
return None, None
|
return None
|
||||||
try:
|
try:
|
||||||
return self.data[11], SubCommand(self.data[11])
|
return SubCommand(self.data[11])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return self.data[11], SubCommand.NOT_IMPLEMENTED
|
raise NotImplementedError(f'Sub command id {self.data[11]}')
|
||||||
|
|
||||||
def __bytes__(self):
|
def __bytes__(self):
|
||||||
return bytes(self.data)
|
return bytes(self.data)
|
||||||
|
|||||||
Reference in New Issue
Block a user