Skip to content

DualShock 4 userspace driver with a Cemuhook Motion Server - epigramx' fork for correct yaw axis multiplier, true MAC address and misc improvements

License

Notifications You must be signed in to change notification settings

ExpatUK/ds4drv-cemuhook

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ds4drv for Cemu hook - Expat's fork of epigramx's fork for a cut down version that provides battery health, battery LED control and motion over udp ONLY.

This is a DS4 driver that includes a cemuhook motion server. It allows to use motion data("gyro"), and other input of DualShock 4 with Cemu over network or locally on Linux. Rumble in Cemu is possible because of Wine XInput emulation.

How to install it:

Nobara OS 40 installation

Step 1: Install dependencies

sudo dnf install libbluetooth-devel bluez-deprecated

Step 2: Python workaround

pip install git+https://github.com/pybluez/pybluez.git#egg=pybluez

Step 3: Install this knobbled version

pip3 install -U https://github.com/ExpatUK/ds4drv-cemuhook/archive/master.zip

Old steps:

Step 1: Install pip and python3 dev files and BlueZ dev files on Debian/Ubuntu/etc. or do the equivalent on other distros:

sudo apt-get install python3-pip python3-dev libbluetooth-dev

Step 2: Install (or update to) the latest version of ds4drv-cemuhook from GitHub:

pip3 install -U https://github.com/epigramx/ds4drv-cemuhook/archive/master.zip

Step 3: Launch ds4drv-cemuhook as superuser after making sure uinput is loaded:

sudo modprobe uinput
sudo python3 -m ds4drv --hidraw --udp --trackpad-mouse

You should see something like this if controller has been connected successfully:

[info][controller 1] Connected to Bluetooth Controller (AA:BB:CC:DD:FF:EE hidraw4)
[info][controller 1] Battery: Fully charged

Requirements and notes and potential errors

  • The DS4 should be bluetooth-paired (e.g. via the GNOME UI) or connected to the USB.
  • "--trackpad-mouse" emulates mouse movement with the DS4 touchpad and can be omitted if needed.
  • If you see "/dev/uinput" does not exist you need to load the uinput module (e.g. every boot with /etc/modules-load.d/modules.conf or manually with modprobe). If you launch it as a normal user you may see a Permission denied error, in which case you can copy this file to /etc/udev/rules.d/ and then execute the command sudo udevadm control --reload. This udev rule allows to access the raw HID and uinput from user space without root privileges. After that reconnect your controller and try again.

For Rumble Support in Cemu with wine

The current official wine repository supports XInput emulation with rumble for the DS4. Select XInput as a controller in Cemu and use the Rumble slider to test it. You must use "Also use for buttons/axes" in Cemuhook's options in Cemu too since ds4drv overrides XInput's buttons mapping.

Testing Cemuhook motion with PadTest

Configuring Cemu itself

  • Have Cemuhook installed. To have Cemu use it, make sure winecfg prioritizes its dbghelp.dll.
  • Cemu connects to localhost:26760 by default, so you just need to choose the first controller (DSU1) in Options -GamePad motion source
  • Make sure to check the Also use for buttons/axes option in the same menu because ds4drv overrides Wine's XInput emulation buttons

image0

Additional options

ds4drv-cemuhook has 4 additional command line arguments (all are optional):

  • --udp -- starts UDP server. Without this flag ds4drv acts just like the official version;
  • --udp-host -- tells UDP server to what interface it should bind (default: 127.0.0.1);
  • --udp-port -- UDP port on which server will be listening (default: 26760);
  • --udp-remap-buttons -- an option for those, who doesn’t like Nintendo’s button layout. It just swaps A↔B and X↔Y buttons only for UDP clients.

Upstream ds4drv information

ds4drv is a Sony DualShock 4 userspace driver for Linux.

Features

  • Option to emulate the Xbox 360 controller for compatibility with Steam games
  • Setting the LED color
  • Reminding you about low battery by flashing the LED
  • Using the trackpad as a mouse
  • Custom mappings, map buttons and sticks to whatever mouse, key or joystick action you want
  • Settings profiles that can be cycled through with a button binding

Dependencies

  • Python 2.7 or 3.3+ (for Debian/Ubuntu you need to install the python2.7-dev or python3.3-dev package)
  • python-setuptools
  • hcitool (usually available in the bluez-utils or equivalent package)

These packages will normally be installed automatically by the setup script, but you may want to use your distro's packages if available:

If you want to try out latest development code check out the source from Github and install it with:

$ git clone https://github.com/chrippa/ds4drv.git
$ cd ds4drv
$ sudo python setup.py install

Using

ds4drv has two different modes to find DS4 devices, decide which one to use depending on your use case.

Raw bluetooth mode

Supported protocols: Bluetooth

Unless your system is using BlueZ 5.14 (which was released recently) or higher it is not possible to pair with the DS4. Therefore this workaround exists, which connects directly to the DS4 when it has been started in pairing mode (by holding Share + the PS button until the LED starts blinking rapidly).

This is the default mode when running without any options:

$ ds4drv

Hidraw mode

Supported protocols: Bluetooth and USB

This mode uses the Linux kernel feature hidraw to talk to already existing devices on the system.

$ ds4drv --hidraw

To use the DS4 via bluetooth in this mode you must pair it first. This requires BlueZ 5.14+ as there was a bug preventing pairing in earlier verions. How you actually pair the DS4 with your computer depends on how your system is setup, suggested googling: <distro name> bluetooth pairing

To use the DS4 via USB in this mode, simply connect your DS4 to your computer via a micro USB cable.

Permissions

If you want to use ds4drv as a normal user, you need to make sure ds4drv has permissions to use certain features on your system.

ds4drv uses the kernel module uinput to create input devices in user land and the module hidraw to communicate with DualShock 4 controllers (when using --hidraw), but this usually requires root permissions. You can change the permissions by copying the udev rules file to /etc/udev/rules.d/.

You may have to reload your udev rules after this with:

$ sudo udevadm control --reload-rules
$ sudo udevadm trigger

Configuring

Configuration file

The preferred way of configuring ds4drv is via a config file. Take a look at ds4drv.conf for example usage.

ds4drv will look for the config file in the following paths:

  • ~/.config/ds4drv.conf
  • /etc/ds4drv.conf

... or you can specify your own location with --config.

Command line options

You can also configure using command line options, this will set the LED to a bright red:

$ ds4drv --led ff0000

See ds4drv --help for a list of all the options.

Multiple controllers

ds4drv does in theory support multiple controllers (I only have one controller myself, so this is untested). You can give each controller different options like this:

$ ds4drv --led ff0000 --next-controller --led 00ff00

This will set the LED color to red on the first controller connected and green on the second.

Known issues/limitations

Troubleshooting

Check here for frequently encountered issues.

Failed to create input device: "/dev/uinput" cannot be opened for writing

This could be because the uinput kernel module is not running on your computer. Doing lsmod | grep uinput should show if the module is loaded. If it is blank, run sudo modprobe uinput to load it. (The uinput module needs to be installed first. Please check with your distro's package manager.)

To have the uinput module load on startup, you can add a file to /etc/modules-load.d. For example:

# in file /etc/modules-load.d/uinput.conf
# Load uinput module at boot
uinput

References

The DualShock 4 report format is not open and had to be reverse engineered. These resources have been very helpful when creating ds4drv:

About

DualShock 4 userspace driver with a Cemuhook Motion Server - epigramx' fork for correct yaw axis multiplier, true MAC address and misc improvements

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%