neilmunday / pes

The Pi Entertainment System (PES) is a graphical front end for a variety of games console emulators that has been written in Python which is intended for use on the Raspberry Pi. This repository contains the PES source code and operating system customisation scripts.
http://pes.mundayweb.com
GNU General Public License v3.0
24 stars 4 forks source link

Add shanwan PS3 Clone controllers support #28

Closed nwildner closed 6 years ago

nwildner commented 7 years ago

Hi.

I'm trying to pair a shanwan PS3 clone controller but it does not work. It pairs with bluetooth service(not sixad), and after its trusted it even shows at the bluetoothctl command line(after agent on, trust MAC:ADDRESS). I've sucessfully paired 2 controllers, but when i try to take them on by pressing the ps3 button this is what it happens:

[pi@pes ~]$ bluetoothctl
[NEW] Controller B8:27:EB:5F:02:64 pes [default]
[NEW] Device 05:24:68:65:63:25 PLAYSTATION(R)3 Controller
[NEW] Device 05:4D:A1:7F:63:25 PLAYSTATION(R)3Conteroller-PANHAI
Agent registered
[CHG] Device 05:24:68:65:63:25 Connected: yes

After some seconds of the controller blinking, its disconnected:

[CHG] Device 05:24:68:65:63:25 ServicesResolved: yes
[CHG] Device 05:24:68:65:63:25 ServicesResolved: no
[CHG] Device 05:24:68:65:63:25 Connected: no

==== if using sixad daemon ====

[pi@pes ~]$ sudo /opt/qtsixa/sbin/sixpair
Current Bluetooth master: b8:27:eb:5f:02:64
Setting master bd_addr to b8:27:eb:5f:02:64

It shows at dmesg:

[  141.049344] usb 1-1.2: New USB device found, idVendor=054c, idProduct=0268
[  141.049351] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  141.049355] usb 1-1.2: Product: PS3 GamePad
[  141.049359] usb 1-1.2: Manufacturer: SHANWAN
[  141.087280] input: SHANWAN PS3 GamePad as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/0003:054C:0268.0001/input/input0
[  141.087665] sony 0003:054C:0268.0001: input,hiddev0,hidraw0: USB HID v1.10 Joystick [SHANWAN PS3 GamePad] on usb-3f980000.usb-1.2/input0
[  192.580870] usb 1-1.2: USB disconnect, device number 4

This is the default behavior when you are using the incorrect sixad branch with those clones on other Linux Retro Gaming projects like RetroPie and Recalbox. There are specific branches at sixad repositories to those clones(shanwan and gasia). Is there a way to put separated binaries and daemons to those branches on PES, or automate the "ps3 controller type" change?

All the best :)

neilmunday commented 7 years ago

Hi,

For bluez support, can you try updating PES to the latest Arch Linux packages first? To do so, please run from the command line:

sudo pacman -Syu

After upgrading, then run:

sudo sed -r -i "s/^(RestrictAddressFamilies=)(.*?)/\1AF_UNIX AF_NETLINK AF_INET AF_INET6 AF_BLUETOOTH/" /usr/lib/systemd/system/systemd-udevd.service

Finally reboot your Rapsberry Pi and test whether using Bluez works with your control pads. I fear they might not still work but it would good to rule out this option. If this does not work, then we could try this Arch Linux package which apparently has patches for shanwan control pads: https://aur.archlinux.org/packages/bluez-ps3/

On the sixad front I'll see what I can do.

nwildner commented 7 years ago

OK. I had little time to tinker with the rpi yesterday. I'll try both: upgrade the system, and building the aur package. I'll report any findings as soon as i get home.

nwildner commented 7 years ago

Well, it seems that i'll not have enough space for base-devel(even when selecting gcc only) to build this package...

Maybe ill have to remake this Pes image with a larger root partition...

[pi@pes bluez-ps3]$ sudo pacman -S base-devel
:: There are 25 members in group base-devel:
:: Repository core
   1) autoconf  2) automake  3) binutils  4) bison  5) fakeroot  6) file
   7) findutils  8) flex  9) gawk  10) gcc  11) gettext  12) grep  13) groff
   14) gzip  15) libtool  16) m4  17) make  18) pacman  19) patch
   20) pkg-config  21) sed  22) sudo  23) texinfo  24) util-linux  25) which

Enter a selection (default=all): 10
resolving dependencies...
looking for conflicting packages...

Packages (1) gcc-7.1.1-4

Total Installed Size:  91.48 MiB

:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring                     [######################] 100
(1/1) checking package integrity                   [######################] 100
(1/1) loading package files                        [######################] 100
(1/1) checking for file conflicts                  [######################] 100
(1/1) checking available disk space                [######################] 100
error: Partition / too full: 30723 blocks needed, 18687 blocks free
error: not enough free disk space
error: failed to commit transaction (not enough free disk space)
Errors occurred, no packages were upgraded.
neilmunday commented 7 years ago

You can resize the root partition on the SD card if you connect it to your desktop PC and then use gparted. You can also free space by removing cached pacman packages like so:

sudo pacman -Scc

nwildner commented 7 years ago

I forgot to comment here yesterday: As you expected, only upgrading the system and editing the systemd-udevd.service did not solve the issue.

I'll free up some space today, and try to compile the aur package with makepkg -Acs.

nwildner commented 7 years ago

It worked. :)

After building with yaourt -SA bluez-ps3 (and installing fakeroot, a dependency that appeared after almost finishing the package creationg phase), it was just a matter of cleaning all bluetooth configuration with bluetoothctl and remove MAC1 remove MAC2 to eliminate trash configuration of my 2 controllers, and re-pairing again using sudo /usr/sbin/sixpair with the controllers plugged in an usb port.

Maybe i can uncomment the udev rule to automatically pair any new connected device(changing the path of sixpad of course):

[pi@pes ~]$ cat /etc/udev/rules.d/97-sixpair.rules
#SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ENV{idProduct}="0268", RUN+="/usr/sbin/sixpair"

img_20170824_204306

It would be awesome if this bluez-ps3 package could be added to the default image. But unfortunately it conflicts with all bluez packages...

neilmunday commented 7 years ago

Nice work! I'll try to incorporate it into PES 2.3.

I'm also going to try the sixad fork. I'll let you know how it goes as I will need you to test if that's ok?

nwildner commented 7 years ago

As a matter of curiosity: PES plans to support other controllers that uses Bluetooth connection like the Wiimote or the Xbox One controller? Cause this aur package will force remove bluez + bluez-plugins, and maybe, other bluez- related packages that could be in use by those controllers

My hope here is that solving this issue, i could focus on helping to implement a battery level indicator at PES Gui, for the PS3 controller. It will be the first retrogaming GUI to do it :)

neilmunday commented 7 years ago

On the additional control pad front, I only have access to PS3, PS4, Wiimote and Xbox 360 (wired) control pads. To add the Xbox One control pads I would ideally need access to one or a tester ;-)

The buez-ps3 AUR package "provides" 'bluez' and 'bluez-plugins' so I think other control pads should still work providing the maintainers of the bluez-ps3 package keep track of bluez updates.

neilmunday commented 7 years ago

On the battery monitor front for control pads, that would be an ace feature. I'll make a separate issue for this for tracking purposes. No promises if I can make it work, but I will certainly take a look. Thanks for the heads up.

Edit see #29.

neilmunday commented 7 years ago

Just to let you know that I have installed the bluez-ps3 package into my PES 2.3 (BETA) image and it seems to work fine, including with sixad.

I'll try that sixad fork over the weekend (all being well).

neilmunday commented 7 years ago

Note: added you to the acknowledgements section of the PES 2.3 readme. ;-) See: a6b0674db91dad69442bf515d62ab94155551b83

neilmunday commented 7 years ago

I've just updated in the qtsixad install script as well as adding a patch for Shanwan control pads based on the Shanwan fork mentioned above. sixad still works for me with my official PS3 control pad so I would be interested to know if it works for your Shanwan control pad.

To test, please proceed as follows:

sudo pacman -S patch git pkg-config make gcc
sudo systemctl stop sixad
cd ~
mkdir git
cd git
git clone https://www.github.com/neilmunday/pes
cd pes
git checkout pes2.3
./setup/arch-common/install-qtsixad.sh
neilmunday commented 7 years ago

You may also be interested in issue #30

neilmunday commented 7 years ago

Wiimote support issue #31 created.

nwildner commented 7 years ago

Just to give more info. I've made tests with Sixad this last weekend, and:

Based on issue #29, let see if it's better keep using sixad or bluez stack :)

neilmunday commented 7 years ago

Are you able to try my sixad version (see instructions above)?

neilmunday commented 7 years ago

I am leaning towards using Bluez in the long run as it means other control pads can be used. I just need to get Bluez auto pairing working first.

nwildner commented 7 years ago

I'll try your version when i get home. I've compiled the shanwan sixad git tree from RetroPie.

For pairing with bluez using usb cable, shouldn't the udev rule be enough? SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ENV{idProduct}="0268", RUN+="/usr/sbin/sixpair"

neilmunday commented 7 years ago

No that rule will associate the control pad with the Bluetooth adapter but you still need to use bluetoothctl to trust and then initiate the connection: https://pes.mundayweb.com/html/Using%20PS3%20Control%20Pads%20via%20Bluetooth.html#using-bluez-instead-of-qtsixa

neilmunday commented 7 years ago

I have some python dbus code to do this automatically, I just need to do some more testing.

neilmunday commented 7 years ago

Another reason for using Bluez is that not all Bluetooth adapters work with sixad.

nwildner commented 7 years ago

Could be possible to trust all bluetooth devices? ACTION=="add", KERNEL=="hci0", RUN+="/usr/bin/bluetoothctl trust all"'

It sure can be a security issue to trust all devices, but this should grant that after associating with a usb cable connection a device will be trusted

neilmunday commented 7 years ago

Unfortunately, it's not that simple. The MAC of the device has to be trusted and for some control pads, (e.g. Wiimote and PS4) the Bluetooth adapter has to be put into "discovery mode" and then the control pads paired.

neilmunday commented 7 years ago

Did you get a chance to try my qtsixad shanwan patched version?

nwildner commented 7 years ago

Oh man. Had no time to test it. I'm comming back from vacation. I'll test it as soon as i get contact to my rpi again :)

neilmunday commented 7 years ago

No problem - hope you had a good trip ;-)

nwildner commented 6 years ago

Well, sixad was built and installed successfully following this procedure(the only missing dependency was patch):

sudo pacman -S patch git pkg-config make gcc
sudo systemctl stop sixad
cd ~
mkdir git
cd git
git clone https://www.github.com/neilmunday/pes
cd pes
git checkout pes2.3
./setup/arch-common/install-qtsixad.sh

dmesg when controller plugged:

[ 2418.756972] usb 1-1.2: USB disconnect, device number 14
[ 2447.465728] usb 1-1.2: new full-speed USB device number 15 using dwc_otg
[ 2447.599311] usb 1-1.2: New USB device found, idVendor=054c, idProduct=0268
[ 2447.599328] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2447.599336] usb 1-1.2: Product: PS3 GamePad
[ 2447.599344] usb 1-1.2: Manufacturer: SHANWAN
[ 2447.612772] input: SHANWAN PS3 GamePad as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/0003:054C:0268.000A/input/input9
[ 2447.614083] sony 0003:054C:0268.000A: input,hiddev0,hidraw0: USB HID v1.10 Joystick [SHANWAN PS3 GamePad] on usb-3f980000.usb-1.2/input0
[ 2464.581093] usb 1-1.2: USB disconnect, device number 15

Didn't worked. What i've tried so far was to comment the second line at /etc/udev/rules.d/97-sixpair.rules since this product name isnt PLAYSTATION(R)3 Controller*. After disabling that rule: sudo udevadm control --reload-rules && udevadm trigger and tried to pair again. No success at all.

Then, double checked the bluetooth status:

[pi@pes pes]$ sudo hciconfig hci0 pscan
[pi@pes pes]$ hciconfig hci0
hci0:   Type: Primary  Bus: UART
        BD Address: B8:27:EB:5F:02:64  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING PSCAN
        RX bytes:7016 acl:72 sco:0 events:253 errors:0
        TX bytes:3700 acl:130 sco:0 commands:88 errors:0

and manually launched sixpair again:

[pi@pes pes]$ sudo /opt/qtsixa/sbin/sixpair
Current Bluetooth master: b8:27:eb:5f:02:64
Setting master bd_addr to b8:27:eb:5f:02:64

Unfortunately, no luck. Any additional tips?

neilmunday commented 6 years ago

Thanks for trying out the mod. I thought I had incorporated all the code changes from the sixad fork above. I think I'll revert the code to the PES 2.2 version for now and concentrate on making PES 3.0 use Bluez.

nwildner commented 6 years ago

Sounds great. If you have any alpha build of 3.0, let me know that i will test it(got another spare sdcard cause mine got fried on a china usb-to-sd dongle).

neilmunday commented 6 years ago

PES 3.0 development has been a bit slow due to a lack of free time but it is getting there. I will give you a shout when I have a version that can be released.

As it happens a friend very recently got himself as Raspberry Pi for PES use and has hit the same Shanwan issue as you. I am currently making a PES 2.3 image with the ps3-bluez package in place. Just to confirm, your control pad works fine with the RetroArch based emulators? (E.g NES, SNES etc.)

nwildner commented 6 years ago

Yup. And also tried the following retrogaming systems: RetroPIE, lakk, recalbox and batocera. There are minor differences on how they manage shanwan clones(retropie used specific drivers for example, with sixad), but as time passes, all of them seems to be using(or tending to implement) the bluez approach with patches.

neilmunday commented 6 years ago

Thanks for the info :-)

neilmunday commented 6 years ago

PES 2.3 released with bluez-ps3 package in place. Closing issue, thanks again for your help.