fraca7 / dsremap

Input remapping for the Dual Shock 4
MIT License
15 stars 2 forks source link

Wired RPi #5

Closed Davidobot closed 2 years ago

Davidobot commented 3 years ago

Hey! Great work - I'm here due to a twitter thread from Jibb.

I was wondering if it would be possible to allow the RPi to communicate with the PlayStation via USB and just have a BT connection between the dualshock and the Pi. I think that should minimise latency and can allow you to just have the Pi plugged into the USB port of the PS for both power and communication?

fraca7 commented 3 years ago

Unfortunately I don't think that's possible with the Pi. Gadgetfs (the Linux subsystem that allows the Pi to behave as a USB device) doesn't give me enough control about what happens at the lower levels to fully mimic a Dualshock; it was already difficult to mimic just enough for the PS4 to send the BT encryption key...

A possible solution would be using a microcontroller that is beefier than the Leonardo, with Bluetooth support, like a Teensy. I'll have to check that the Dualshock still answers the authentication reports when connected through BT though. I may try this in the future; the latency is indeed a problem over BT (since the Pi must handle both send and receive, and the Dualshock has a tendency to send as much reports as physically possible over the link).

Davidobot commented 3 years ago

I wonder if there is a more universal way of going about things like this...

I know there were a few Android apps that used Bluetooth HID profiles to emulate Nintendo Switch Pro Controllers/Joycons - 1, 2

Does it look like the pairing process of the DS4 might be a bit more complicated though?

I didn't find any similar apps for emulation the DS4, but the ones I did find seem to use the Remote Play for mimicking the controller. I'll try this out from my PC. I guess programs like DS4Windows can be configured to map gyro-to-joysticks for a virtual DS4 controller that would then be used in Remote Play. Speaking of that, I should add that feature to my BetterJoy...

The setup would be linking the controller through your PC, but then still using your PlayStation on your TV to minimise lag.

fraca7 commented 3 years ago

Yeah, the PS4 and Dualshock don't pair "normally", they use a special key exchange protocol through USB. From a user perspective this is very cool because you just have to plug your Dualshock once to the PS4 and bam it's paired; no holding a button, no entering a PIN or anything. And no chance of hijacking without physical access. But it also means that any device wanting to pass as a Dualshock through Bluetooth must support this and act, at least for the key exchange, as an USB device, so PCs are out, unless they use another channel like Remote Play. That's why I settled on a microcontroller or an RPi Zero; both can act as USB devices.

fraca7 commented 2 years ago

I took advantage of a long week-end to come back to this. By patching the kernel I can (not completely tested yet) make it support the USB interfaces I need to spoof the Dualshock so I'm going to give it a try; there are some difficulties along the way but it seems promising. Of course that means patching and rebuilding the kernel but whatever :) I'll try to do that properly when I have something actually working, so I can send the patch upstream.

fraca7 commented 2 years ago

Seems to work like a charm. Amazingly, as you suggested, the PS4 delivers enough juice to power the RPi. I'll spend a few days testing this extensively before releasing.

Davidobot commented 2 years ago

Super! Glad to see that the idea worked! Look forward to testing it.

fraca7 commented 2 years ago

Release done!

fraca7 commented 2 years ago

Reopening this because it doesn't actually work. Well, it works for me, because at some point last year I managed to impersonate the Dualshock using the RPi0 and now the PS4 remembers this particular Bluetooth MAC, so it behaves differently. Doesn't work with a MAC the PS4 never saw before though.

fraca7 commented 2 years ago

Okay NOW it works :)