Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/handle hidapi exceptions in sendReport #55

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions pydualsense/pydualsense.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def init(self) -> None:
self.battery = DSBattery()
self.conType = self.determineConnectionType() # determine USB or BT connection
self.ds_thread = True
self.connected = True
flok marked this conversation as resolved.
Show resolved Hide resolved
self.report_thread = threading.Thread(target=self.sendReport)
self.report_thread.start()
self.states = None
Expand Down Expand Up @@ -227,18 +228,26 @@ def setRightMotor(self, intensity: int) -> None:
def sendReport(self) -> None:
"""background thread handling the reading of the device and updating its states"""
while self.ds_thread:
# read data from the input report of the controller
inReport = self.device.read(self.input_report_length)
if self.verbose:
logger.debug(inReport)
# decrypt the packet and bind the inputs
self.readInput(inReport)

# prepare new report for device
outReport = self.prepareReport()

# write the report to the device
self.writeReport(outReport)
try:
# read data from the input report of the controller
inReport = self.device.read(self.input_report_length)
if self.verbose:
logger.debug(inReport)
# decrypt the packet and bind the inputs
self.readInput(inReport)

# prepare new report for device
outReport = self.prepareReport()

# write the report to the device
self.writeReport(outReport)
except IOError:
self.connected = False
break

except AttributeError:
self.connected = False
break
flok marked this conversation as resolved.
Show resolved Hide resolved

def readInput(self, inReport) -> None:
"""
Expand Down