forked from mirror/joycontrol
successful pairing
This commit is contained in:
+1
-1
@@ -17,4 +17,4 @@ class Controller(enum.Enum):
|
|||||||
elif self == Controller.PRO_CONTROLLER:
|
elif self == Controller.PRO_CONTROLLER:
|
||||||
return 'Pro Controller'
|
return 'Pro Controller'
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|||||||
+35
-2
@@ -55,6 +55,12 @@ class ControllerProtocol(BaseProtocol):
|
|||||||
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:
|
||||||
|
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)
|
||||||
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')
|
||||||
|
|
||||||
@@ -71,7 +77,7 @@ class ControllerProtocol(BaseProtocol):
|
|||||||
#input_report.set_left_analog_stick()
|
#input_report.set_left_analog_stick()
|
||||||
#input_report.set_right_analog_stick()
|
#input_report.set_right_analog_stick()
|
||||||
#input_report.set_vibrator_input()
|
#input_report.set_vibrator_input()
|
||||||
input_report.sub_0x2_device_info(bd_address)
|
input_report.sub_0x02_device_info(bd_address)
|
||||||
|
|
||||||
asyncio.ensure_future(self.transport.write(input_report))
|
asyncio.ensure_future(self.transport.write(input_report))
|
||||||
|
|
||||||
@@ -80,6 +86,33 @@ class ControllerProtocol(BaseProtocol):
|
|||||||
input_report.set_input_report_id(0x21)
|
input_report.set_input_report_id(0x21)
|
||||||
input_report.set_misc()
|
input_report.set_misc()
|
||||||
input_report.set_ack(0x80)
|
input_report.set_ack(0x80)
|
||||||
input_report.sub_0x8_shipment()
|
input_report.sub_0x08_shipment()
|
||||||
|
|
||||||
|
asyncio.ensure_future(self.transport.write(input_report))
|
||||||
|
|
||||||
|
async def _command_spi_flash_read(self, output_report):
|
||||||
|
input_report = InputReport()
|
||||||
|
input_report.set_input_report_id(0x21)
|
||||||
|
input_report.set_misc()
|
||||||
|
input_report.set_ack(0x90)
|
||||||
|
input_report.sub_0x10_spi_flash_read(output_report)
|
||||||
|
|
||||||
|
asyncio.ensure_future(self.transport.write(input_report))
|
||||||
|
|
||||||
|
async def _command_set_input_report_mode(self, output_report):
|
||||||
|
input_report = InputReport()
|
||||||
|
input_report.set_input_report_id(0x21)
|
||||||
|
input_report.set_misc()
|
||||||
|
input_report.set_ack(0x80)
|
||||||
|
input_report.sub_0x03_set_input_report_mode()
|
||||||
|
|
||||||
|
asyncio.ensure_future(self.transport.write(input_report))
|
||||||
|
|
||||||
|
async def _command_trigger_buttons_elapsed_time(self, output_report):
|
||||||
|
input_report = InputReport()
|
||||||
|
input_report.set_input_report_id(0x21)
|
||||||
|
input_report.set_misc()
|
||||||
|
input_report.set_ack(0x83)
|
||||||
|
input_report.sub_0x04_trigger_buttons_elapsed_time()
|
||||||
|
|
||||||
asyncio.ensure_future(self.transport.write(input_report))
|
asyncio.ensure_future(self.transport.write(input_report))
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class InputReport:
|
|||||||
"""
|
"""
|
||||||
self.data[13] = 0x80
|
self.data[13] = 0x80
|
||||||
|
|
||||||
def sub_0x2_device_info(self, mac, fm_version=(0x03, 0x48), controller=Controller.JOYCON_L):
|
def sub_0x02_device_info(self, mac, fm_version=(0x03, 0x48), controller=Controller.JOYCON_L):
|
||||||
"""
|
"""
|
||||||
Sub command 0x02 request device info response.
|
Sub command 0x02 request device info response.
|
||||||
|
|
||||||
@@ -87,18 +87,38 @@ class InputReport:
|
|||||||
self.data[offset + 10] = 0x01
|
self.data[offset + 10] = 0x01
|
||||||
self.data[offset + 11] = 0x01
|
self.data[offset + 11] = 0x01
|
||||||
|
|
||||||
def __bytes__(self):
|
def sub_0x08_shipment(self):
|
||||||
return bytes(self.data)
|
|
||||||
|
|
||||||
def sub_0x8_shipment(self):
|
|
||||||
# reply to sub command ID
|
# reply to sub command ID
|
||||||
self.data[15] = 0x08
|
self.data[15] = 0x08
|
||||||
|
|
||||||
|
def sub_0x10_spi_flash_read(self, output_report):
|
||||||
|
# reply to sub command ID
|
||||||
|
self.data[15] = 0x10
|
||||||
|
self.data[16:18] = output_report.data[12:14]
|
||||||
|
|
||||||
|
def sub_0x03_set_input_report_mode(self):
|
||||||
|
# reply to sub command ID
|
||||||
|
self.data[15] = 0x03
|
||||||
|
|
||||||
|
def sub_0x04_trigger_buttons_elapsed_time(self):
|
||||||
|
# reply to sub command ID
|
||||||
|
self.data[15] = 0x04
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
blub = [0x00, 0xCC, 0x00, 0xEE, 0x00, 0xFF]
|
||||||
|
self.data[16:22] = blub
|
||||||
|
|
||||||
|
def __bytes__(self):
|
||||||
|
return bytes(self.data)
|
||||||
|
|
||||||
|
|
||||||
class SubCommand(Enum):
|
class SubCommand(Enum):
|
||||||
REQUEST_DEVICE_INFO = auto()
|
REQUEST_DEVICE_INFO = auto()
|
||||||
SET_SHIPMENT_STATE = auto()
|
SET_SHIPMENT_STATE = auto()
|
||||||
|
SPI_FLASH_READ = auto()
|
||||||
|
SET_INPUT_REPORT_MODE = auto()
|
||||||
NOT_IMPLEMENTED = auto()
|
NOT_IMPLEMENTED = auto()
|
||||||
|
TRIGGER_BUTTONS_ELAPSED_TIME = auto()
|
||||||
|
|
||||||
|
|
||||||
class OutputReport:
|
class OutputReport:
|
||||||
@@ -114,6 +134,12 @@ class OutputReport:
|
|||||||
return SubCommand.REQUEST_DEVICE_INFO
|
return SubCommand.REQUEST_DEVICE_INFO
|
||||||
elif sub_command_byte == 0x08:
|
elif sub_command_byte == 0x08:
|
||||||
return SubCommand.SET_SHIPMENT_STATE
|
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:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user