jath03 / openrgb-python

A python client for the OpenRGB SDK
GNU General Public License v3.0
112 stars 22 forks source link

Can't connect to server when Sony Dualshock 4 controller connected #18

Closed shawnc722 closed 3 years ago

shawnc722 commented 3 years ago

First of all, thanks for your implementation of the openRGB API! It's been really useful to me so far and seems to work flawlessly unless a PS4 controller is plugged in. OpenRGB itself recognises and can control the lights on the controller, but as soon as I initialise an OpenRGBClient object it causes a crash. I've got a couple other RGB devices that have been working perfectly. Here's the traceback:

  File "/home/shawn/Documents/RGB/default.py", line 13, in <module>
    client = OpenRGBClient()
  File "/home/shawn/.local/lib/python3.8/site-packages/openrgb/orgb.py", line 235, in __init__
    self.comms.requestDeviceNum()
  File "/home/shawn/.local/lib/python3.8/site-packages/openrgb/network.py", line 163, in requestDeviceNum
    self.read()
  File "/home/shawn/.local/lib/python3.8/site-packages/openrgb/network.py", line 113, in read
    self.callback(device_id, packet_type, buff[0])
  File "/home/shawn/.local/lib/python3.8/site-packages/openrgb/orgb.py", line 248, in _callback
    self.comms.requestDeviceData(x)
  File "/home/shawn/.local/lib/python3.8/site-packages/openrgb/network.py", line 156, in requestDeviceData
    self.read()
  File "/home/shawn/.local/lib/python3.8/site-packages/openrgb/network.py", line 131, in read
    self.callback(device_id, packet_type, utils.ControllerData.unpack(data, self._protocol_version))
  File "/home/shawn/.local/lib/python3.8/site-packages/openrgb/utils.py", line 448, in unpack
    start, metadata = MetaData.unpack(data, version, start)
  File "/home/shawn/.local/lib/python3.8/site-packages/openrgb/utils.py", line 395, in unpack
    start, val = parse_string(data, start)
  File "/home/shawn/.local/lib/python3.8/site-packages/openrgb/utils.py", line 90, in parse_string
    val = struct.unpack(f"{size}s", data[start:start + size])[0].decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte

I'm running this on linux using the latest stable build (0.2.5) in python 3.8. I'm not familiar with openRGB's api at all but looking at the traceback it seems to be related to the struct containing device info, so here's the info provided by openRGB itself:

Vendor: Sony
Type: Gamepad
Description: Sony Dualshock 4 Device
Version: 
Location: HID: /dev/hidraw11
Serial: �

The serial is the unicode U+FFFD (in case it doesn't show up right), which I assume is causing the issue when openRGB passes along the real value of whatever caused this error. Thanks again for your work on this project!

Edit: the serial number for the device returned by lsusb is just 0. I'm not sure if that helps.

inlart commented 3 years ago

The get serial call on the OpenRGB server side might fail. This is currently not checked properly so I made these changes: https://gitlab.com/inlart/OpenRGB/-/commit/a4a4e81beb51b35bbda1053a21815fac6668e3a0 Could you give this a try? You can try the builds here: https://gitlab.com/inlart/OpenRGB/-/pipelines/252074995 (select your OS -> Job artifcats -> Download) If you want to build from source you can find the branch here: https://gitlab.com/inlart/OpenRGB/-/tree/bugfix/DS4-serial If my guess was right the serial in the OpenRGB device info should now be empty and the python client should work without any changes.

shawnc722 commented 3 years ago

That fixed it, and your guess was exactly right. Thanks so much!