Tuesday, December 23, 2014

Controle de PS3 no Windows, Linux e Beaglebone

O SCP é um driver para controles do PS2, PS3, PS4 no Windows. 
É opensource e muito melhor que o Motionjoy.
Os controles podem ser conectados por USB ou Bluetooth.
Preparei um pacote com os fontes e os binários.





Para instalar é só executar o ScpDriver.exe,
Os controles irão aparece como controles nativos do Xbox. 


Instalador dos drivers e serviços SCP DS3

Referências:
http://emulation-general.wikia.com/wiki/SCP_Driver_Package
http://forums.pcsx2.net/Thread-XInput-Wrapper-for-DS3-and-Play-com-USB-Dual-DS2-Controller
http://www.motioninjoy.com/


Na beaglebone com Debian 7.7, o caminho é usar um dongle USB Bluetooth,
existem vários genéricos de menos de 2 dólares com chip da CSR (Cambridge Silicon Radio)

root@beaglebone:~/beaglebonequadcopter/quad-eclipse# lsusb
Bus 001 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
root@beaglebone:~/beaglebonequadcopter/quad-eclipse#

Então é só pegar o endereço MAC do Dongle USB com hciconfig para configurar o controle usando o sixpair.

root@beaglebone:~/beaglebonequadcopter/quad-eclipse# hciconfig
hci0:   Type: BR/EDR  Bus: USB
        BD Address: 00:15:83:07:D4:EF  ACL MTU: 310:10  SCO MTU: 64:8
        UP RUNNING PSCAN
        RX bytes:1269 acl:0 sco:0 events:45 errors:0
        TX bytes:446 acl:0 sco:0 commands:43 errors:0

root@beaglebone:~/beaglebonequadcopter/quad-eclipse#

Usando o sixpair com o  MAC do bluetooth

root@beaglebone:~/beaglebonequadcopter/quad-eclipse# ./sixpair 00:15:83:07:D4:EF
Current Bluetooth master: f8:2f:a8:42:53:39
Setting master bd_addr to 00:15:83:07:d4:ef
root@beaglebone:~/beaglebonequadcopter/quad-eclipse#

Verificando se o sixpair configurou o MAC corretamente

root@beaglebone:~/beaglebonequadcopter/quad-eclipse# ./sixpair
Current Bluetooth master: 00:15:83:07:d4:ef
Unable to retrieve local bd_addr from `hcitool dev`.
Please enable Bluetooth or specify an address manually.
root@beaglebone:~/beaglebonequadcopter/quad-eclipse#

apt-get install bluez-utils bluez-compat bluez-hcidump checkinstall libusb-dev libbluetooth-dev joystick

wget http://colocrossing.dl.sourceforge.net/project/qtsixa/QtSixA%201.5.1/QtSixA-1.5.1-src.tar.gz

root@beaglebone:~/QtSixA-1.5.1/sixad# make
mkdir -p bins
g++ -O2 -Wall -Wl,-Bsymbolic-functions sixad-bin.cpp bluetooth.cpp shared.cpp textfile.cpp -o bins/sixad-bin `pkg-config --cflags --libs bluez` -lpthread -fpermissive
sixad-bin.cpp: In function 'int main(int, char**)':
sixad-bin.cpp:84:20: warning: taking address of temporary [-fpermissive]
g++ -O2 -Wall -Wl,-Bsymbolic-functions sixad-sixaxis.cpp sixaxis.cpp shared.cpp uinput.cpp textfile.cpp -o bins/sixad-sixaxis -lpthread -lrt
g++ -O2 -Wall -Wl,-Bsymbolic-functions sixad-remote.cpp remote.cpp shared.cpp uinput.cpp textfile.cpp -o bins/sixad-remote -lrt
g++ -O2 -Wall -Wl,-Bsymbolic-functions sixad-raw.cpp sixaxis.cpp shared.cpp uinput.cpp textfile.cpp -o bins/sixad-raw
g++ -O2 -Wall -Wl,-Bsymbolic-functions sixad-3in1.cpp sixaxis.cpp shared.cpp uinput.cpp textfile.cpp -o bins/sixad-3in1


mkdir -pv /var/lib/sixad/profiles

root@beaglebone:~/QtSixA-1.5.1/sixad# checkinstall

checkinstall 1.6.2, Copyright 2009 Felipe Eduardo Sanchez Diaz Duran
           This software is released under the GNU GPL.


The package documentation directory ./doc-pak does not exist.
Should I create a default set of package docs?  [y]: n

*****************************************
**** Debian package creation selected ***
*****************************************

This package will be built according to these values:

0 -  Maintainer: [ root@beaglebone ]
1 -  Summary: [ sixad ]
2 -  Name:    [ sixad ]
3 -  Version: [ 20141224 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ armhf ]
8 -  Source location: [ sixad ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Provides: [ sixad ]
12 - Conflicts: [  ]
13 - Replaces: [  ]

Enter a number to change any of them or press ENTER to continue:

Installing with make install...

========================= Installation results ===========================
install -d /etc/default/
install -d /etc/init.d/
install -d /etc/logrotate.d/
install -d /usr/bin/
install -d /usr/sbin/
install -d /var/lib/sixad/
install -d /var/lib/sixad/profiles/
install -m 644 sixad.default /etc/default/sixad
install -m 755 sixad.init /etc/init.d/sixad
install -m 644 sixad.log /etc/logrotate.d/sixad
install -m 755 sixad /usr/bin/
install -m 755 bins/sixad-bin /usr/sbin/
install -m 755 bins/sixad-sixaxis /usr/sbin/
install -m 755 bins/sixad-remote /usr/sbin/
install -m 755 bins/sixad-3in1 /usr/sbin/
install -m 755 bins/sixad-raw /usr/sbin/
install -m 755 sixad-dbus-blocker /usr/sbin/
Installation is Complete!

======================== Installation successful ==========================

Copying files to the temporary directory...OK

Stripping ELF binaries and libraries...OK

Compressing man pages...OK

Building file list...OK

Building Debian package...OK

Installing Debian package...OK

Erasing temporary files...OK

Writing backup package...OK
OK

Deleting temp dir...OK


**********************************************************************

 Done. The new package has been installed and saved to

 /root/QtSixA-1.5.1/sixad/sixad_20141224-1_armhf.deb

 You can remove it from your system anytime using:

      dpkg -r sixad

**********************************************************************

root@beaglebone:~/QtSixA-1.5.1/sixad# dpkg -L sixad
/.
/etc
/etc/default
/etc/default/sixad
/etc/init.d
/etc/init.d/sixad
/etc/logrotate.d
/etc/logrotate.d/sixad
/usr
/usr/sbin
/usr/sbin/sixad-dbus-blocker
/usr/sbin/sixad-remote
/usr/sbin/sixad-3in1
/usr/sbin/sixad-bin
/usr/sbin/sixad-raw
/usr/sbin/sixad-sixaxis
/usr/bin
/usr/bin/sixad


root@beaglebone:~/QtSixA-1.5.1/sixad# sixad --start
sixad-bin[1972]: started
sixad-bin[1972]: sixad started, press the PS button now
sixad-bin[1972]: unable to connect to sdp session
sixad-bin[1972]: Connected Sony Computer Entertainment Wireless Controller (38:C0:96:5E:8C:74)

update-rc.d sixad defaults

root@beaglebone:~/QtSixA-1.5.1/sixad# /etc/init.d/sixad start
[ ok ] Starting sixad (via systemctl): sixad.service.
root@beaglebone:~/QtSixA-1.5.1/sixad#

[  907.328485] Bluetooth: HIDP (Human Interface Emulation) ver 1.2
[  907.335550] Bluetooth: HIDP socket layer initialized
[  917.768067] sony 0005:054C:0268.0001: Fixing up Sony Sixaxis report descriptor
[  917.793477] sony 0005:054C:0268.0001: unknown main item tag 0x0
[  917.814176] input: Sony Computer Entertainment Wireless Controller as /devices/ocp.3/47400000.usb/musb-hdrc.1.auto/usb1/1-1/1-1:1.0/bluetooth/hci0/hci0:42/input1
[  917.852215] sony 0005:054C:0268.0001: input,hidraw0: BLUETOOTH HID v1.00 Joystick [Sony Computer Entertainment Wireless Controller] on 00:15:83:07:d4:ef
root@beaglebone:~#

root@beaglebone:~# jstest /dev/input/js0
Driver version is 2.1.0.
Joystick (Sony Computer Entertainment Wireless Controller) has 27 axes (X, Y, Z, Rz, (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null))
and 19 buttons (Trigger, ThumbBtn, ThumbBtn2, TopBtn, TopBtn2, PinkieBtn, BaseBtn, BaseBtn2, BaseBtn3, BaseBtn4, BaseBtn5, BaseBtn6, BtnDead, BtnA, BtnB, BtnC, (null), (null), (null)).
Testing ... (interrupt to exit)
Axes:  0:     0  1:     0  2:     0  3:     0  4:     0  5:     0  6:     0  7:     0  8:     0  9:     0 10:     0 11:     0 12:     0 13:     0 14:     0 15:     0 16:     0 17:     0 18:     0 19:     0 20:     0 21:     0  22:-32767 23:     0 24:     0 25: -4256 26:     0 Buttons:  0:off  1:off  2:off  3:off  4:off  5:off  6:off  7:off  8:off  9:off 10:off 11:off 12:off 13:off 14:off 15:off 16:off 17:off 18:off 

Muito interessante, praticamente todos os botões são analógicos, dá para pegar a pressão de cada um deles. Também tem um acelerômetro e os 2 motores de feedback.