Detect connection type and support bluetooth receiving

This commit is contained in:
Michael Wagner
2023-02-02 22:27:59 +01:00
parent 3b3ec445ad
commit e2c16cd29e

View File

@@ -98,14 +98,7 @@ class pydualsense:
self.triggerL = DSTrigger() # left trigger self.triggerL = DSTrigger() # left trigger
self.triggerR = DSTrigger() # right trigger self.triggerR = DSTrigger() # right trigger
self.state = DSState() # controller states self.state = DSState() # controller states
self.conType = self.determineConnectionType() # determine USB or BT connection
if platform.startswith('Windows'):
self.conType = self.determineConnectionType() # determine USB or BT connection
else:
# set for BT manually
self.input_report_length = 78
self.output_report_length = 78
self.ds_thread = True self.ds_thread = True
self.report_thread = threading.Thread(target=self.sendReport) self.report_thread = threading.Thread(target=self.sendReport)
self.report_thread.start() self.report_thread.start()
@@ -115,22 +108,24 @@ class pydualsense:
""" """
Determine the connection type of the controller. eg USB or BT. Determine the connection type of the controller. eg USB or BT.
Currently only USB is supported. We ask the controller for an input report with a length up to 100 bytes
and afterwords check the lenght of the received input report.
The connection type determines the length of the report.
This way of determining is not pretty but it works..
Returns: Returns:
ConnectionType: Detected connection type of the controller. ConnectionType: Detected connection type of the controller.
""" """
# hardcode to bluetooth for now dummy_report = self.device.read(100)
self.input_report_length = 78 input_report_length = len(dummy_report)
self.output_report_length = 78
return ConnectionType.BT
if self.device._device.input_report_length == 64: if input_report_length == 64:
self.input_report_length = 64 self.input_report_length = 64
self.output_report_length = 64 self.output_report_length = 64
return ConnectionType.USB return ConnectionType.USB
elif self.device._device.input_report_length == 78: elif input_report_length == 78:
self.input_report_length = 78 self.input_report_length = 78
self.output_report_length = 78 self.output_report_length = 78
return ConnectionType.BT return ConnectionType.BT
@@ -234,7 +229,14 @@ class pydualsense:
Args: Args:
inReport (bytearray): read bytearray containing the state of the whole controller inReport (bytearray): read bytearray containing the state of the whole controller
""" """
states = list(inReport)[1:] # convert bytes to list if self.conType == ConnectionType.BT:
# the reports for BT and USB are structured the same,
# but there is one more byte at the start of the bluetooth report.
# We drop that byte, so that the format matches up again.
states = list(inReport)[1:] # convert bytes to list
else: # USB
states = list(inReport) # convert bytes to list
self.states = states self.states = states
# states 0 is always 1 # states 0 is always 1
self.state.LX = states[1] - 127 self.state.LX = states[1] - 127