forked from mirror/joycontrol
added OutputReportID
This commit is contained in:
+25
-8
@@ -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,12 +54,26 @@ class ControllerProtocol(BaseProtocol):
|
||||
logger.warning(f'Report parsing error "{v_err}" - IGNORE')
|
||||
return
|
||||
|
||||
try:
|
||||
output_report_id = report.get_output_report_id()
|
||||
except NotImplementedError as err:
|
||||
logger.warning(err)
|
||||
return
|
||||
|
||||
if output_report_id == OutputReportID.SUB_COMMAND:
|
||||
# classify sub command
|
||||
sc_byte, sub_command = report.get_sub_command()
|
||||
logging.info(f'received output report - {sub_command}')
|
||||
try:
|
||||
sub_command = report.get_sub_command()
|
||||
except NotImplementedError as err:
|
||||
logger.warning(err)
|
||||
return
|
||||
|
||||
if sub_command is None:
|
||||
logger.warning(f'Received output report does not contain a sub command')
|
||||
elif sub_command == SubCommand.REQUEST_DEVICE_INFO:
|
||||
raise ValueError('Received output report does not contain a sub command')
|
||||
|
||||
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.SET_SHIPMENT_STATE:
|
||||
@@ -73,9 +87,12 @@ class ControllerProtocol(BaseProtocol):
|
||||
|
||||
elif sub_command == SubCommand.TRIGGER_BUTTONS_ELAPSED_TIME:
|
||||
await self._command_trigger_buttons_elapsed_time(report)
|
||||
|
||||
elif sub_command == SubCommand.NOT_IMPLEMENTED:
|
||||
logger.warning(f'Sub command 0x{sc_byte:02x} not implemented - ignoring')
|
||||
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')
|
||||
|
||||
+20
-4
@@ -137,7 +137,11 @@ class SubCommand(Enum):
|
||||
SET_SHIPMENT_STATE = 0x08
|
||||
SPI_FLASH_READ = 0x10
|
||||
ENABLE_6AXIS_SENSOR = 0x40
|
||||
NOT_IMPLEMENTED = 0xFF
|
||||
|
||||
|
||||
class OutputReportID(Enum):
|
||||
SUB_COMMAND = 0x01
|
||||
RUMBLE_ONLY = 0x10
|
||||
|
||||
|
||||
class OutputReport:
|
||||
@@ -146,13 +150,25 @@ class OutputReport:
|
||||
raise ValueError('Output reports must start with 0xA2')
|
||||
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):
|
||||
if len(self.data) < 12:
|
||||
return None, None
|
||||
return None
|
||||
try:
|
||||
return self.data[11], SubCommand(self.data[11])
|
||||
return SubCommand(self.data[11])
|
||||
except ValueError:
|
||||
return self.data[11], SubCommand.NOT_IMPLEMENTED
|
||||
raise NotImplementedError(f'Sub command id {self.data[11]}')
|
||||
|
||||
def __bytes__(self):
|
||||
return bytes(self.data)
|
||||
|
||||
Reference in New Issue
Block a user