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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this variable really needed? you only set it 3 times but never compare any value to it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @flok - this is intended to be used externally to indicated the controller is connected.

As an example, here is how I am using it in my project. https://github.com/dalethomas81/ArfBotOS/blob/main/Controller/DualSenseServer.py#L380

Is there another way to know if it is connected? I am open to alternative approaches.

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
Comment on lines +244 to +250
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my understanding you could also just break when a exception is thrown and the class variable connected is not needed


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