pydualsense suddenly stop reading input of PS5 controller

150 views Asked by At

reading input of PS5 controller using pydualsense get error and unable to read after running few secounds. error code has more than this, i just paste here top of them

from pydualsense import *


def input_check():
    dualsense = pydualsense()
    dualsense.init()
    keys = []
    while True:
        ...
        if dualsense.state.options:
            keys.append('option')
            return 'option'
        elif dualsense.state.ps:
            keys.append('ps')
            return 'ps'
        elif dualsense.state.triangle:
            keys.append('triangle')
            return 'triangle'
        elif dualsense.state.square:
            keys.append('square')
            return 'square'
        elif dualsense.state.cross:
            keys.append('cross')
            return 'cross'
        elif dualsense.state.circle:
            keys.append('circle')
            return 'circle'

    # close device
    dualsense.close()

while True:
    input = input_check()
    print(input)

this is error code

Exception in thread Thread-113:
Traceback (most recent call last):
  File "E:\anaconda3\envs\fifabot\lib\threading.py", line 980, in _bootstrap_inner
Exception in thread Thread-373:
Traceback (most recent call last):
  File "E:\anaconda3\envs\fifabot\lib\threading.py", line 980, in _bootstrap_inner
    self.run()
  File "E:\anaconda3\envs\fifabot\lib\threading.py", line 917, in run
    self.run()
  File "E:\anaconda3\envs\fifabot\lib\threading.py", line 917, in run

    
1

There are 1 answers

1
Tai On

I have self sloved it. code should be like this

from time import sleep

ds = pydualsense()  # open controller
ds.init()  # initialize controller

while True:
    keys = []
    triangle = ds.state.triangle
    if triangle == True:
        keys.append('triangle')
    square = ds.state.square
    if square == True:
        keys.append('square')
    cross = ds.state.cross
    if cross == True:
        keys.append('cross')
    circle = ds.state.circle
    if circle == True:
        keys.append('circle')

    print(keys,ds.state.LX,ds.state.LY)

ds.close() # closing the controller```