forked from mirror/joycontrol
sub command enum cleanup
This commit is contained in:
+7
-4
@@ -49,20 +49,23 @@ class ControllerProtocol(BaseProtocol):
|
|||||||
# classify sub command
|
# classify sub command
|
||||||
sub_command = report.get_sub_command()
|
sub_command = report.get_sub_command()
|
||||||
logging.info(f'received output report - {sub_command}')
|
logging.info(f'received output report - {sub_command}')
|
||||||
if sub_command is None:
|
if sub_command == SubCommand.REQUEST_DEVICE_INFO:
|
||||||
logger.error(f'No sub command found')
|
|
||||||
elif sub_command == SubCommand.REQUEST_DEVICE_INFO:
|
|
||||||
await self._command_request_device_info(report)
|
await self._command_request_device_info(report)
|
||||||
|
|
||||||
elif sub_command == SubCommand.SET_SHIPMENT_STATE:
|
elif sub_command == SubCommand.SET_SHIPMENT_STATE:
|
||||||
await self._command_set_shipment_state(report)
|
await self._command_set_shipment_state(report)
|
||||||
|
|
||||||
elif sub_command == SubCommand.SPI_FLASH_READ:
|
elif sub_command == SubCommand.SPI_FLASH_READ:
|
||||||
await self._command_spi_flash_read(report)
|
await self._command_spi_flash_read(report)
|
||||||
|
|
||||||
elif sub_command == SubCommand.SET_INPUT_REPORT_MODE:
|
elif sub_command == SubCommand.SET_INPUT_REPORT_MODE:
|
||||||
await self._command_set_input_report_mode(report)
|
await self._command_set_input_report_mode(report)
|
||||||
|
|
||||||
elif sub_command == SubCommand.TRIGGER_BUTTONS_ELAPSED_TIME:
|
elif sub_command == SubCommand.TRIGGER_BUTTONS_ELAPSED_TIME:
|
||||||
await self._command_trigger_buttons_elapsed_time(report)
|
await self._command_trigger_buttons_elapsed_time(report)
|
||||||
|
|
||||||
elif sub_command == SubCommand.NOT_IMPLEMENTED:
|
elif sub_command == SubCommand.NOT_IMPLEMENTED:
|
||||||
logger.error(f'Sub command not implemented')
|
logger.error(f'Sub command 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')
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
from enum import Enum, auto
|
from enum import Enum
|
||||||
|
|
||||||
#[0xA1 0, 0x21 1, 0x05 2, 0x8E 3,
|
|
||||||
# 0x84, 0x00, 0x12, button
|
|
||||||
# 0x01, 0x18, 0x80, left analog
|
|
||||||
# 0x01, 0x18, 0x80, right analog
|
|
||||||
# 0x80, vibrator?
|
|
||||||
# 0x82, 0x02, 0x03, 0x48, 0x01, 0x02, 0xDC, 0xA6, 0x32, 0x71, 0x58, 0xBB, 0x01, 0x01]
|
|
||||||
from controller import Controller
|
from controller import Controller
|
||||||
|
|
||||||
|
|
||||||
@@ -113,12 +107,12 @@ class InputReport:
|
|||||||
|
|
||||||
|
|
||||||
class SubCommand(Enum):
|
class SubCommand(Enum):
|
||||||
REQUEST_DEVICE_INFO = auto()
|
REQUEST_DEVICE_INFO = 0x02
|
||||||
SET_SHIPMENT_STATE = auto()
|
SET_INPUT_REPORT_MODE = 0x03
|
||||||
SPI_FLASH_READ = auto()
|
TRIGGER_BUTTONS_ELAPSED_TIME = 0x04
|
||||||
SET_INPUT_REPORT_MODE = auto()
|
SET_SHIPMENT_STATE = 0x08
|
||||||
NOT_IMPLEMENTED = auto()
|
SPI_FLASH_READ = 0x10
|
||||||
TRIGGER_BUTTONS_ELAPSED_TIME = auto()
|
NOT_IMPLEMENTED = 0xFF
|
||||||
|
|
||||||
|
|
||||||
class OutputReport:
|
class OutputReport:
|
||||||
@@ -128,20 +122,10 @@ class OutputReport:
|
|||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
def get_sub_command(self):
|
def get_sub_command(self):
|
||||||
print('subcommand:', self.data[11])
|
try:
|
||||||
sub_command_byte = self.data[11]
|
return SubCommand(self.data[11])
|
||||||
if sub_command_byte == 0x02:
|
except ValueError:
|
||||||
return SubCommand.REQUEST_DEVICE_INFO
|
return SubCommand.NOT_IMPLEMENTED
|
||||||
elif sub_command_byte == 0x08:
|
|
||||||
return SubCommand.SET_SHIPMENT_STATE
|
|
||||||
elif sub_command_byte == 0x10:
|
|
||||||
return SubCommand.SPI_FLASH_READ
|
|
||||||
elif sub_command_byte == 0x03:
|
|
||||||
return SubCommand.SET_INPUT_REPORT_MODE
|
|
||||||
elif sub_command_byte == 0x04:
|
|
||||||
return SubCommand.TRIGGER_BUTTONS_ELAPSED_TIME
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def __bytes__(self):
|
def __bytes__(self):
|
||||||
return bytes(self.data)
|
return bytes(self.data)
|
||||||
|
|||||||
+1
-1
@@ -60,10 +60,10 @@ class L2CAP_Transport(asyncio.Transport):
|
|||||||
return super().get_write_buffer_size()
|
return super().get_write_buffer_size()
|
||||||
|
|
||||||
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):
|
elif isinstance(data, InputReport):
|
||||||
|
# set timer byte of input report
|
||||||
data.set_timer(self._input_report_timer)
|
data.set_timer(self._input_report_timer)
|
||||||
self._input_report_timer = (self._input_report_timer + 1) % 256
|
self._input_report_timer = (self._input_report_timer + 1) % 256
|
||||||
_bytes = bytes(data)
|
_bytes = bytes(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user