chrippa / ds4drv

A Sony DualShock 4 userspace driver for Linux
MIT License
1.05k stars 213 forks source link

Error read_report -> reports -> read_device #15

Closed Bux28 closed 10 years ago

Bux28 commented 10 years ago

pi@openbot ~ $ sudo ds4drv --led 0055ff [info][Controller 1] Created devices /dev/input/js0 (joystick) /dev/input/event0 (evdev) [info][Bluetooth] Scanning for devices [info][Bluetooth] Found device XX:XX:XX:XX:XX:XX [info][Controller 1] Connected to XX:XX:XX:XX:XX:XX [info][Bluetooth] Scanning for devices [warning] Got simplified HID report, ignoring Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 552, in bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 505, in run self.__target(_self.args, *_self.__kwargs) File "/usr/local/lib/python2.7/dist-packages/ds4drv.py", line 909, in read_device for report in device.reports: File "/usr/local/lib/python2.7/dist-packages/ds4drv.py", line 608, in reports report = self.read_report() File "/usr/local/lib/python2.7/dist-packages/ds4drv.py", line 576, in read_report S16LE.unpack(buf[16:18])[0], error: unpack requires a string argument of length 2

But the led is blue :)

chrippa commented 10 years ago

Hmm, this error really shouldn't be possible, strange. Please try modifying line 539 in ds4drv.py, from:

        if ret < 79:

to:

        if ret < 79 or len(self.buf) < 79:
Bux28 commented 10 years ago

hi, this line is modified , and now this is the error (the controller is probably ok , the led is blue)

[info][Bluetooth] Scanning for devices Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 552, in bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 505, in run self.__target(_self.args, *_self.__kwargs) File "/usr/local/lib/python2.7/dist-packages/ds4drv.py", line 909, in read_device for report in device.reports: File "/usr/local/lib/python2.7/dist-packages/ds4drv.py", line 608, in reports report = self.read_report() File "/usr/local/lib/python2.7/dist-packages/ds4drv.py", line 576, in read_report S16LE.unpack(buf[16:18])[0], error: unpack requires a string argument of length 2

Bux28 commented 10 years ago

i have print buf for show why buf[16:18] havn't length 2

this is the result "8¿{7ÿÿaþ¼üXá

full message with print line before Exeption

[info][Controller 1] Connected to XX:XX:XX:XX:XX:XX [info][Bluetooth] Scanning for devices "8¿{7ÿÿaþ¼üXá Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 552, in bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 505, in run self.__target(_self.args, *_self.__kwargs) File "/usr/local/lib/python2.7/dist-packages/ds4drv.py", line 911, in read_device for report in device.reports: File "/usr/local/lib/python2.7/dist-packages/ds4drv.py", line 610, in reports report = self.read_report() File "/usr/local/lib/python2.7/dist-packages/ds4drv.py", line 578, in read_report S16LE.unpack(buf[16:18])[0], error: unpack requires a string argument of length 2

chrippa commented 10 years ago

Hmm, this is very strange. Instead of the print you added, please add this, it will make the output more readable:

from binascii import hexlify
print(hexlify(self.buf))
Bux28 commented 10 years ago

print : a111c0007e7d7e7c080000000058d3fd0500feff020081fdcc07a2e1000000000002000004f60270070005000000320270070005003000b1026f07000500300055026f0700050040000000d6d7502a

chrippa commented 10 years ago

This is so strange... the buffer looks good yet your Python fails to unpack the data. What exact version of Python are you using?

Bux28 commented 10 years ago

2.7.3

chrippa commented 10 years ago

Hmm, I think it's possible your Python doesn't work with bytearray for some reason, even though it's suppose to be supported in 2.7, and works fine for me... Try changing this line:

        buf = self.buf

to:

        buf = bytes(self.buf)
Bux28 commented 10 years ago

... i don't understand too

[info][Bluetooth] Found device XX:XX:XX:XX:XX:XX [info][Controller 1] Connected to XX:XX:XX:XX:XX:XX [info][Bluetooth] Scanning for devices Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 552, in bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 505, in run self.__target(_self.args, *_self.__kwargs) File "/usr/local/lib/python2.7/dist-packages/ds4drv.py", line 911, in read_device for report in device.reports: File "/usr/local/lib/python2.7/dist-packages/ds4drv.py", line 610, in reports report = self.read_report() File "/usr/local/lib/python2.7/dist-packages/ds4drv.py", line 544, in read_report dpad = buf[8] % 16 TypeError: not all arguments converted during string formatting

chrippa commented 10 years ago

I managed to reproduce this now, seems like this was fixed in Python 2.7.4. 7c1e69c45e31c5e2bc196f0ff2679319c59d1ad6 has a workaround for this, so please try installing the git version.

Bux28 commented 10 years ago

[info][controller 1] Created devices /dev/input/js0 (joystick) /dev/input/event0 (evdev) [info][bluetooth] Scanning for devices [info][bluetooth] Found device XX:XX:XX:XX:XX:XX [info][controller 1] Connected to Bluetooth Controller (XX:XX:XX:XX:XX:XX) [info][bluetooth] Scanning for devices [info][controller 1] Battery: 25%

:) thanks good work guy