Skip to content

Commit

Permalink
Merge pull request #55 from dalethomas81/bugfix/handle-hidapi-exceptions
Browse files Browse the repository at this point in the history
Bugfix/handle hidapi exceptions in sendReport
  • Loading branch information
flok authored Oct 5, 2024
2 parents 0f588a3 + 7f09a45 commit 6831748
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions pydualsense/pydualsense.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def init(self) -> None:
if self.conType is ConnectionType.ERROR:
raise Exception("Couldn't determine connection type")
self.ds_thread = True
self.connected = True
self.report_thread = threading.Thread(target=self.sendReport)
self.report_thread.start()
self.states = None
Expand Down Expand Up @@ -233,18 +234,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

def readInput(self, inReport : List[int]) -> None:
"""
Expand Down

0 comments on commit 6831748

Please sign in to comment.