chrippa / ds4drv

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

fixing LED and rumble report in hidraw mode #154

Closed PatrickHussey closed 2 years ago

PatrickHussey commented 6 years ago

This is a fix to enable LED and rumble support in hidraw mode

NerosTie commented 6 years ago

I have an issue when I start ds4drv in hidraw mode with this PR:

Traceback (most recent call last):
  File "/usr/bin/ds4drv", line 11, in <module>
    load_entry_point('ds4drv==0.5.1', 'console_scripts', 'ds4drv')()
  File "/usr/lib/python3.7/site-packages/ds4drv/__main__.py", line 207, in main
    thread.controller.setup_device(device)
  File "/usr/lib/python3.7/site-packages/ds4drv/__main__.py", line 78, in setup_device
    self.device.set_led(*self.options.led)
  File "/usr/lib/python3.7/site-packages/ds4drv/device.py", line 98, in set_led
    self._control()
  File "/usr/lib/python3.7/site-packages/ds4drv/device.py", line 89, in _control
    flash_led2=self._led_flash[1], **kwargs)
  File "/usr/lib/python3.7/site-packages/ds4drv/device.py", line 148, in control
    self.write_report(report_id, pkt)
  File "/usr/lib/python3.7/site-packages/ds4drv/backends/hidraw.py", line 84, in write_report
    buf[len(buf)-4] = chr(crc & 0xFF)
TypeError: an integer is required
PatrickHussey commented 6 years ago

I only tested using python 2.7 since it was something I was doing for ROS integration

It’s just complaining about the chr, I’ll see if I can change it to make python 2 and 3 happy

Might be the zlib crc32 return a string in python 3 or something like that

NerosTie commented 6 years ago

I works without chr but I don't have any rumble feature.

PatrickHussey commented 6 years ago

Works for sure with this version that I modified to be a ROS driver

https://github.com/waypointrobotics/vector/blob/joy_dev/vector_common/vector_third_party/ds4drv/src/ds4drv/backends/hidraw.py

NerosTie commented 6 years ago

With the option emulate-xpad = true too?

idzikovsky commented 5 years ago

Works for me. Python 2.7. I've not tested with emulate-xpad = true.

Howarddj commented 4 weeks ago

Anyone that reads this with any skills in working with python, please have a go at trying to fix this again for use in python3. i have a lot of games installed though lutris that simply will not work without using ds4drv in xbox controller emulation mode and it would be amazing to have working LED and rumble support using hidraw.

Ryochan7 commented 4 weeks ago

Anyone that reads this with any skills in working with python, please have a go at trying to fix this again for use in python3. i have a lot of games installed though lutris that simply will not work without using ds4drv in xbox controller emulation mode and it would be amazing to have working LED and rumble support using hidraw.

I am not sure about rumble but getting the LED color option working again is fairly simple. The root problem is that the chr function returns a string and a bytearray must contain integer elements. The TypeError that comes up is raised from the bytearray type. Removing the use of chr allows the LED color to change when using the --led cmd option.

Edit: I modified the fork by saladtosser.