Controller PS3 su Gentoo/Sabayon e altre distro

 

Come da titolo vedremo oggi come configurare il controller PS3 anche compatibile comprato dai cinesi su linux. Preciso che è stato testato su Sabayon/Gentoo ma dovrebbe funzionare anche per le altre distro.

 

Per prima cosa apriamo il terminale e da utente root aggiungiamo il server layman “nirvana”

layman -a nirvana

 

Adesso scarichiamo il repository nirvana

layman -s nirvana

 

Fatto questo, adesso, scarichiamo il file QtSixA-1.5.1 da qui

Ora ci serve spostare il file scaricato chiamato QtSixA-1.5.1-src.tar.gz in /usr/portage/distfiles

Per prima cosa ora ci serve scaricare la patch per i controller conpatibili, ecco la patch:

From 71500fc4535846bc4294541d675ae2d0877c1e6d Mon Sep 17 00:00:00 2001
From: falkTX
Date: Mon, 24 Oct 2011 21:11:17 +0100
Subject: [PATCH] More gasia gamepad hacks, now working
 
sixad/Makefile | 13 +++++++++++++
sixad/bluetooth.cpp | 2 +-
sixad/shared.cpp | 20 +++++++++++++++++++-
sixad/sixad-sixaxis.cpp | 4 ++–
sixad/sixaxis.cpp | 35 +++++++++++++++++++++++++++——–
5 files changed, 62 insertions(+), 12 deletions(-)
 
diff –git a/sixad/Makefile b/sixad/Makefile
index 0386a18..466d36e 100644
— a/sixad/Makefile
+++ b/sixad/Makefile
@@ -4,6 +4,12 @@ CXX ?= g++
CXXFLAGS ?= -O2 -Wall
LDFLAGS += -Wl,-Bsymbolic-functions
 
+GASIA_GAMEPAD_HACKS = true
+
+ifeq ($(GASIA_GAMEPAD_HACKS),true)
+CXXFLAGS += -DGASIA_GAMEPAD_HACKS
+endif
+
all: sixad_bins
 
sixad_bins:
@@ -35,6 +41,13 @@ install:
install -m 755 bins/sixad-3in1 $(DESTDIR)/usr/sbin/
install -m 755 bins/sixad-raw $(DESTDIR)/usr/sbin/
install -m 755 sixad-dbus-blocker $(DESTDIR)/usr/sbin/
+
+ifeq “$(wildcard /usr/bin/python2 )” “”
+else
+ # Python2 force
+ sed -i “s/env python/env python2/” $(DESTDIR)/usr/sbin/sixad-dbus-blocker
+endif
+
@chmod 777 -R $(DESTDIR)/var/lib/sixad/
@echo “Installation is Complete!”
 
diff –git a/sixad/bluetooth.cpp b/sixad/bluetooth.cpp
index 3ad6bdb..19d2077 100644
— a/sixad/bluetooth.cpp
+++ b/sixad/bluetooth.cpp
@@ -57,7 +57,7 @@ void do_search(int ctl, bdaddr_t *bdaddr, int debug)
 
for (i = 0; i < num_rsp; i++) {
memcpy(_class, (info+i)->dev_class, 3);
+
if (debug) syslog(LOG_INFO, “Got device %02X | %02X | %02X”, _class[0], _class[1], _class[2]);
 
if (_class[1] == 0x25 && (_class[2] == 0x00 || _class[2] == 0x01)) {
diff –git a/sixad/shared.cpp b/sixad/shared.cpp
index d5239bf..34c8da5 100644
— a/sixad/shared.cpp
+++ b/sixad/shared.cpp
@@ -268,14 +268,32 @@ int get_joystick_number()
 
void enable_sixaxis(int csk)
{
+#ifdef GASIA_GAMEPAD_HACKS
+ unsigned char enable[] = {
+ 0xA2,
+ 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, // rumble values [0x00, right-timeout, right-force, left-timeout, left-force]
+ 0x00, 0x00, 0x00, 0x00, 0x02, // 0x02=LED1 .. 0x10=LED4
+ 0xff, 0x27, 0x10, 0x00, 0x32, // LED 4
+ 0xff, 0x27, 0x10, 0x00, 0x32, // LED 3
+ 0xff, 0x27, 0x10, 0x00, 0x32, // LED 2
+ 0xff, 0x27, 0x10, 0x00, 0x32, // LED 1
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00
+ };
+#else
char buf[128];
unsigned char enable[] = {
0x53, /* HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE */
0xf4, 0x42, 0x03, 0x00, 0x00
};
+#endif
 
/* enable reporting */
send(csk, enable, sizeof(enable), 0);
+#ifndef GASIA_GAMEPAD_HACKS
recv(csk, buf, sizeof(buf), 0);
+#endif
}
diff –git a/sixad/sixad-sixaxis.cpp b/sixad/sixad-sixaxis.cpp
index 23ee9f6..7aa0f7c 100644
— a/sixad/sixad-sixaxis.cpp
+++ b/sixad/sixad-sixaxis.cpp
@@ -293,7 +293,7 @@ int main(int argc, char *argv[])
p[1].events = POLLIN | POLLERR | POLLHUP;
p[2].events = POLLIN | POLLERR | POLLHUP;
p[3].events = POLLIN | POLLERR | POLLHUP;
+
p[0].fd = 0;
p[1].fd = 1;
p[2].fd = ufd->js;
@@ -353,7 +353,7 @@ int main(int argc, char *argv[])
}
 
delete ufd;
+
do_rumble(csk, 10, 0xff, 0xff, 0x01);
 
shutdown(isk, SHUT_RDWR);
diff –git a/sixad/sixaxis.cpp b/sixad/sixaxis.cpp
index fbe5d10..dee5fa4 100644
— a/sixad/sixaxis.cpp
+++ b/sixad/sixaxis.cpp
@@ -380,9 +380,12 @@ void do_input(int fd, unsigned char* buf, struct dev_input input)
 
void do_rumble(int csk, int led_n, int weak, int strong, int timeout)
{
– unsigned char buf[128];
unsigned char setrumble[] = {
+#ifdef GASIA_GAMEPAD_HACKS
+ 0x92,
+#else
0x52, /* HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_OUTPUT */
+#endif
0x01,
0x00, 0x00, 0x00, 0x00, 0x00, // rumble values [0x00, right-timeout, right-force, left-timeout, left-force]
0x00, 0x00, 0x00, 0x00, 0x1E, // 0x02=LED1 .. 0x10=LED4
@@ -419,22 +422,34 @@ void do_rumble(int csk, int led_n, int weak, int strong, int timeout)
 
setrumble[11] = ledpattern[led_n]; //keep old led
send(csk, setrumble, sizeof(setrumble), 0);
+#ifndef GASIA_GAMEPAD_HACKS
+ unsigned char buf[128];
recv(csk, buf, sizeof(buf), 0); //MSG_DONTWAIT?
+#endif
}
 
int set_sixaxis_led(int csk, struct dev_led led, int rumble)
{
– int i, led_n, led_number;
+ int led_n, led_number;
+
+#ifndef GASIA_GAMEPAD_HACKS
+ int i;
unsigned char buf[128];
+#endif
+
unsigned char setleds[] = {
+#ifdef GASIA_GAMEPAD_HACKS
+ 0x92,
+#else
0x52, /* HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_OUTPUT */
+#endif
0x01,
– 0x00, 0x00, 0x00, 0x00, 0x00, // rumble values [0x00, right-timeout, right-force, left-timeout, left-force]
– 0x00, 0x00, 0x00, 0x00, 0x1E, // 0x02=LED1 .. 0x10=LED4
– 0xff, 0x27, 0x10, 0x00, 0x32, // LED 4
– 0xff, 0x27, 0x10, 0x00, 0x32, // LED 3
– 0xff, 0x27, 0x10, 0x00, 0x32, // LED 2
– 0xff, 0x27, 0x10, 0x00, 0x32, // LED 1
+ 0x00, 0x00, 0x00, 0x00, 0x00, // rumble values [0x00, right-timeout, right-force, left-timeout, left-force]
+ 0x00, 0x00, 0x00, 0x00, 0x1E, // 0x02=LED1 .. 0x10=LED4
+ 0xff, 0x27, 0x10, 0x00, 0x32, // LED 4
+ 0xff, 0x27, 0x10, 0x00, 0x32, // LED 3
+ 0xff, 0x27, 0x10, 0x00, 0x32, // LED 2
+ 0xff, 0x27, 0x10, 0x00, 0x32, // LED 1
0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char ledpattern[11] = {
@@ -460,6 +475,7 @@ int set_sixaxis_led(int csk, struct dev_led led, int rumble)
} else
led_n = 0;
 
+#ifndef GASIA_GAMEPAD_HACKS
if (led.enabled && led.anim)
{
/* Sixaxis LED animation – Way Cool!! */
@@ -523,12 +539,15 @@ int set_sixaxis_led(int csk, struct dev_led led, int rumble)
recv(csk, buf, sizeof(buf), 0);
}
}
+#endif
 
/* set LEDs (final) */
setleds[11] = ledpattern[led_n];
if (rumble) setleds[3] = setleds[4] = setleds[5] = setleds[6] = 0x00;
send(csk, setleds, sizeof(setleds), 0);
+#ifndef GASIA_GAMEPAD_HACKS
recv(csk, buf, sizeof(buf), 0);
+#endif
 
return led_n;
}
1.7.4.1
 
 
Copiate la patch in un file di testo e chiamatela in questo modo:

gasia.patch

Ora copiate la patch in:

/var/lib/layman/nirvana/games-util/qtsixa/files/

 

Ora spostiamo nella cartella

 

/var/lib/layman/nirvana/games-util/qtsixa/

 

ed editiamo il file ebuild qtsixa-1.5.1.ebuild in questo modo, da notare, la riga di colore rosso è quella da aggiungere:

 

# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
 
EAPI=5
 
PYTHON_COMPAT=( python2_7 )
inherit eutils linux-info python-single-r1 systemd udev
 
MY_P=”QtSixA-${PV}”
DESCRIPTION=”Sixaxis Joystick Manager”
HOMEPAGE=”http://qtsixa.sourceforge.net/”
SRC_URI=”mirror://sourceforge/${PN}/${MY_P/-/%20}/${MY_P}-src.tar.gz”
 
LICENSE=”GPL-2″
SLOT=”0″
KEYWORDS=”~amd64 ~x86″
IUSE=”jack qt4″
 
DEPEND=”net-wireless/bluez
virtual/libusb:1
jack? ( media-sound/jack-audio-connection-kit )
qt4? ( dev-python/PyQt4[${PYTHON_USEDEP}] )”
 
RDEPEND=”${DEPEND}
dev-python/dbus-python[${PYTHON_USEDEP}]
qt4? (
net-wireless/bluez-hcidump
x11-libs/libnotify
x11-misc/xdg-utils
)”
 
S=”${WORKDIR}/${MY_P}”
 
CONFIG_CHECK=”~BT_HIDP ~INPUT_UINPUT”
 
pkg_setup() {
python-single-r1_pkg_setup
linux-info_pkg_setup
}
 
src_prepare() {
epatch “${FILESDIR}”/qtsixa-1.5.1-fix-missing-includes.patch
epatch “${FILESDIR}”/gasia.patch
 
sed -i -e s/exec\ python/exec\ “${EPYTHON}”/g qtsixa/qtsixa ||
die “Replace hardcoded python executable fails.”
}
 
src_compile() {
use qt4 && emake -C qtsixa
emake -C utils WANT_JACK=$(use jack && echo true)
emake -C sixad
}
 
src_install() {
use qt4 && emake -C qtsixa install DESTDIR=”${D}”
emake -C utils install DESTDIR=”${D}” WANT_JACK=$(use jack && echo true)
emake -C sixad install DESTDIR=”${D}”
 
dodoc INSTALL manual.pdf README TODO
 
if use qt4; then
python_fix_shebang “${D}”/usr/bin/sixad-lq
python_fix_shebang “${D}”/usr/bin/sixad-notify
python_fix_shebang “${D}”/usr/share/qtsixa/gui
python_optimize “${D}”/usr/share/qtsixa/gui
fi
 
# Remove unused configuration file.
# Since we are using hand-written startup files.
# We could coexist with the bluetooth daemon if input plugin is disabled.
rm -r “${D}etc/default” || die “Remove not needed configuration file fails.”
 
# Remove unused logrotate configuration file.
rm -r “${D}etc/logrotate.d” ||
die “Remove not needed log configuration fails.”
 
# Do not install upstream start script.
# It does not work nicely.
# We added custom startup scripts for OpenRC and systemd.
rm “${D}usr/bin/sixad” || die “Could not remove upstream start script.”
 
# Use our own init script compatible with OpenRC.
newinitd “${FILESDIR}”/sixad.initd sixad
 
# Install systemd unit file.
systemd_dounit “${FILESDIR}”/sixad.service
 
# Add an udev rule for automatically pairing.
udev_dorules “${FILESDIR}”/97-sixpair.rules
}
 
pkg_postinst() {
udev_reload
 
einfo “Requirements:”
einfo “Ensure that the uinput module is loaded.”
einfo “”
einfo “Solve conflicts:”
einfo “Do not forget to disable the input plugin of your bluetooth daemon.”
einfo “You could disable the plugin by adding the following line to the”
einfo “configuration file of the bluetooth daemon (/etc/bluetooth/main.conf):”
einfo “DisablePlugins = input”
einfo “”
einfo “Pairing:”
einfo “There is an udev rule installed, that will pair PS3 remote”
einfo “controllers if they are plugged in on USB.”
}
Salviamo il file ebuild e diamo il seguente comando:
ebuild qtsixa-1.5.1.ebuild digest
Ora lanciamo

emerge qtsixa

Finita la compilazione, visto che avrete il problema che mancherà l’eseguibile sixad copiate il seguente file bash e lo salvate con il nome sixad:
 
#!/bin/bash
 
# sixad-bin wrapper
# written by falkTX
 
DEBUG=0
LEGACY=0
 
. /etc/default/sixad
 
if [ -f /usr/bin/sudo ]; then
SUDO=”/usr/bin/sudo”
else
SUDO=””
fi
 
bt_device_check () {
if (which hciconfig > /dev/null); then
if (hciconfig dev > /dev/null); then
VER=`hciconfig default version | grep “HCI Ver” | awk ‘{print$3}’`
if [ “$VER” == “1.1” ]; then
echo “***** NOTICE *****”
echo “You’re using a very old bluetooth dongle,”
echo “the Sixaxis will not work properly!”
elif [ “$VER” == “1.0” ]; then
echo “***** WARNING *****”
echo “You’re using a _really_ old bluetooth dongle,”
echo “the Sixaxis will just not work!”
fi
else
echo “No bluetooth adapters found on the system!”
echo “sixad will now quit”
exit
fi
fi
}
 
sixad_running_check () {
ps -e | grep sixad-bin > /dev/null
}
 
bluetoothd_running_check () {
ps -e | grep bluetoothd > /dev/null
}
 
modprobe_check () {
$SUDO /sbin/modprobe uinput
}
 
bt_start () {
$SUDO rm -f /tmp/.sixad-dbus-blocker.pid
env sleep 1
 
if [ -f /lib/udev/rules.d/97-bluetooth.rules ]; then
$SUDO /usr/sbin/bluetoothd –udev
elif [ -f /etc/rc.d/bluetooth ]; then
$SUDO /etc/rc.d/bluetooth start
else
$SUDO /etc/init.d/bluetooth start
fi
}
 
bt_stop() {
if (bluetoothd_running_check); then
$SUDO restart bluetoothd
fi
 
$SUDO /usr/sbin/sixad-dbus-blocker &
}
 
case $1 in
 
–start|-start|start|-s)
REMOTE=0
bt_device_check
if (sixad_running_check); then
echo “sixad is already running.”
echo “run ‘$0 –stop’ to stop it”
else
if (modprobe_check); then #Check for root access before running, If NO access, quit
bt_stop
$SUDO /usr/sbin/sixad-bin $DEBUG $LEGACY $REMOTE
else
echo “You need admin/root access to run this application”
fi
fi
;;
 
–stop|-stop|stop)
$SUDO pkill -KILL sixad-sixaxis
$SUDO pkill -KILL sixad-remote
$SUDO pkill -TERM sixad-bin
bt_start
;;
 
–remote|-remote|remote)
REMOTE=1
bt_device_check
if (modprobe_check); then #Check for root access before running, If NO access, quit
bt_stop
$SUDO /usr/sbin/sixad-bin $DEBUG $LEGACY $REMOTE
else
echo “You need admin/root access to run this application”
fi
;;
 
–restore|-restore|restore|-r)
bt_start
;;
 
–boot-yes)
# ArchLinux
if [ -f /etc/arch-release ]; then
$SUDO sed ‘/DAEMONS=/ s/)/ sixad)/g’ -i /etc/rc.conf
# Gentoo
elif [ -f /etc/gentoo-release ]; then
$SUDO rc-update add sixad
# Debian (default)
else
if [ -f /etc/rc2.d/S90sixad ]; then true; else $SUDO ln -s /etc/init.d/sixad /etc/rc2.d/S90sixad; fi
if [ -f /etc/rc3.d/S90sixad ]; then true; else $SUDO ln -s /etc/init.d/sixad /etc/rc3.d/S90sixad; fi
if [ -f /etc/rc4.d/S90sixad ]; then true; else $SUDO ln -s /etc/init.d/sixad /etc/rc4.d/S90sixad; fi
if [ -f /etc/rc5.d/S90sixad ]; then true; else $SUDO ln -s /etc/init.d/sixad /etc/rc5.d/S90sixad; fi
fi
;;
 
–boot-no)
# ArchLinux
if [ -f /etc/arch-release ]; then
$SUDO sed “s/ sixad//” -i /etc/rc.conf
# Gentoo
elif [ -f /etc/gentoo-release ]; then
$SUDO rc-update delete sixad
# Debian (default)
else
if [ -f /etc/rc2.d/S90sixad ]; then $SUDO rm /etc/rc2.d/S90sixad; fi
if [ -f /etc/rc3.d/S90sixad ]; then $SUDO rm /etc/rc3.d/S90sixad; fi
if [ -f /etc/rc4.d/S90sixad ]; then $SUDO rm /etc/rc4.d/S90sixad; fi
if [ -f /etc/rc5.d/S90sixad ]; then $SUDO rm /etc/rc5.d/S90sixad; fi
fi
;;
 
–help|-help|help|-h)
echo “[Qt]SixA Daemon”
$0
;;
 
–version|-version|version|-v)
echo “[Qt]SixA Daemon – version 1.5.1”
;;
 
*)
echo “usage: $0
 
command can be:
-h, –help Show help (this message)
-v, –version Show sixad version
 
-s, –start Start sixad
–stop Stop sixad
–remote BD Remote mode
 
-r, –restore Restore regular bluetooth
 
–boot-yes Auto-starts sixad at boot time
–boot-no Does not auto-start sixad at boot time
 
You can also check: sixad-raw, sixad-notify”
;;
 
esac
Copiate il file bash in /usr/bin e rendetelo eseguibile dando il comando:

chmod a+x sixad

Ora non ci resta che avviare il servizio di sixad con systemd, ecco il servizio:
[Unit]
Description=sixad – Sixaxis Daemon
# It does not conflict, if the input plugin is disabled.
#Conflicts=bluetooth.service
After=bluetooth.service
Requires=bluetooth.service
 
[Service]
ExecStart=/usr/sbin/sixad-bin 0 0 0
Restart=on-failure
 
[Install]
WantedBy=bluetooth.target
#WantedBy=multi-user.target
Salvatelo con il nome sixad.service e lo copiate in /usr/lib64/systemd/system .
Ora non ci rimane che avviare al boot il servizio così:
systemctl enable sixad.service
systemctl start sixad.service
Ora riavviamo il sistema e il joystic PS3 funziona correttamente.
 
Calogero Scarnà
Calogero Scarnà
Articoli: 299

Newsletter

Inserisci il tuo nome e il tuo indirizzo email qui sotto e iscriviti alla nostra newsletter