pydualsense icon indicating copy to clipboard operation
pydualsense copied to clipboard

Feature multi controllers

Open amerca9664 opened this issue 7 months ago • 0 comments

I added multi controller support, you need to select what controller you want to read, may could be better if a parallel thread are running to read the states of the controllers but seems to be a lot changes in the library.

    def sendReport(self) -> None:
        """background thread handling the reading of the device and updating its states"""
        while self.ds_thread:
            try:
                self.device =  self.devices[f'controller{self.setController.selectedController}']["deviceConection"] # Controller selector
                
                self.is_edge = self.devices[f'controller{self.setController.selectedController}']["isEdge"] # Check if is an edge and enable the reading of edge buttons
                
                # 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
            
            except KeyError:
                self.connected = False
                break

i also added a example, i dont know why but at the begining when you set changes in the controller 2 always apply to the first controller, i think is a problem in the sequence of read because if you put a slightly delay works fine.

dualsense.setController.choose(0) # choose controller 1
time.sleep(0.01) # sleep a little to see the result on the controller
dualsense.light.setColorI(0, 255, 0) # set color around touchpad to red
dualsense.light.setPlayerID(PlayerID.PLAYER_1) # set all player 1 indicator on
time.sleep(2) # sleep a little to see the result on the controller, this is not needed in normal usage

amerca9664 avatar Jun 08 '25 19:06 amerca9664