Xbox 360 USB Gamepad

De wikijoan
Salta a la navegació Salta a la cerca

Introducció

La versió mínima per jugar és la RPi pelada (o amb una caixeta), cable HDMI per connectar a la tele, i mando Xbox USB. Existeix el driver xboxdrv que està instal.lat a la imatge del piplay. Per tant, es tracta d'aconseguir un d'aquests mandos i configurar els diferents emuladors amb el mando i que sigui compatible amb les altres màquines que tinc.

Compro aquest mando: (14e)

Interessa tenir ben configurat el xboxdrv per poder jugar de forma fàcil als diferents emuladors, amb 1 i dos jugadors. Tant els jocs normals com els jocs de spinner, i no haver d'anar canviant les configuracions. També s'ha de buscar la compatibilitat amb els diferents emuladors.

Una imatge dels diferents botons:

Allò interessant seria que l'ús del Gamepad fos totalment compatible amb l'ús del joystick/botons. Per això és interessant:

it allows you to simulate keyboard and mouse events

man page:

Table 2. Button Names
Name 	Description
start, back: start, back buttons
guide: big X-button in the middle (Xbox360 only)
a(1), b(2), x(3), y(4): face buttons
black, white: black, white buttons (Xbox1 only, mapped to lb, rb on Xbox360)
lb(5), rb(6): shoulder buttons (Xbox360 only, mapped to black, white on Xbox1)
lt(7), rt(8): analog trigger (needs --trigger-as-button option)
tl, tr: pressing the left or right analog stick
du(up), dd(down), dl(left), dr(right): dpad directions (needs --dpad-as-button option)
green, red, yellow, blue, orange: guitar buttons

Instal.lació

No cal instal.lar-ho, perquè si vinc d'una imatge de Piplay ja està instal.lat.

You can get xboxdrv from GitHub:

$ git clone git://github.com/xboxdrv/xboxdrv.git

Connectem el dispositiu i el sistema el reconeix:

$ lsusb
Bus 001 Device 004: ID 045e:028e Microsoft Corp. Xbox360 Controller

Configuració

Preàmbul

The following configuration will cause xboxdrv to emulate a keyboard, which can be useful for games that are played with keyboard, like Flash games or games that don't support a joystick. Since different games use different keyboard keys you might have to adjust the keybindings to fit the game:

$ xboxdrv \
  --ui-clear \
  --ui-buttonmap a=XK_a,b=XK_b,x=XK_x,y=XK_y \
  --ui-buttonmap dl=XK_Left,dr=XK_Right,du=XK_Up,dd=XK_Down

El fitxer de configuració està a:

/home/pi/pimame/config/xboxdrv_mapping.cfg

Si vulgués utilitzar dos mandos XBOX360 també es pot fer: you just need to run multiple instances of the xboxdrv utility. Check out this post:

Configuració amb la meva configuració de màquines

Un dels avantatges d'aquest driver és que puc tenir carregades vàries configuracions, que commuten apretant el botó del mig (Guide). Per tant, tindré en principi dues configuracions, que tenen la principal diferència en la configuració dels dos sticks analògics:

  1. configuració normal, que serveix dels jocs de disparar. El stick de l'esquerra fa de joystick (és més còmode que el DPad, botons de joystick). I el stick de la dreta és analògic de manera que vagi bé amb l'arkanoid (tot i que és difícil de configurar) (que sigui prou ràpid i prou sensible).
  2. configuració driving. El stick de l'esquerra és analògic i serveix pel volant (amb un paràmetre x1=REL_X:-1:10 que fa que el volant giri més lent). El stick de la dreta són els botons. D'aquesta manera es pot jugar al Pac-man amb el stick de la dreta (i va molt bé, ni punt de comparació respecte jugar amb el joystick).

xboxdrv_joanillo.cfg:

[xboxdrv]
silent=true
deadzone=6000
dpad-as-button=true
trigger-as-button=true

[ui-axismap]
x1=KEY_LEFT:KEY_RIGHT
y1=KEY_UP:KEY_DOWN
x2=REL_X:-5:10
y2=REL_Y:-5:10

[ui-buttonmap]
a=KEY_3
b=KEY_4
x=KEY_5
y=KEY_6

[ui-buttonmap]
lb=KEY_TAB
rb=KEY_ENTER
#black, white buttons (Xbox1 only, mapped to lb, rb on Xbox360)
#black=KEY_7
#white=KEY_8
#guide és el botó gros del mig
guide=KEY_C

[ui-buttonmap]
lt=KEY_5
rt=KEY_2
#tl, tr: pressing the left or right analog stick
tl=KEY_A
tr=KEY_1

[ui-buttonmap]
dl=KEY_LEFT
dr=KEY_RIGHT
du=KEY_UP
dd=KEY_DOWN

[ui-buttonmap]
back=KEY_0
start=KEY_1

# EOF #

xboxdrv_joanillo_driving.cfg:

[xboxdrv]
silent=true
deadzone=6000
dpad-as-button=true
trigger-as-button=true

[ui-axismap]
x1=REL_X:-1:10
y1=REL_Y:-1:10
x2=KEY_LEFT:KEY_RIGHT
y2=KEY_UP:KEY_DOWN

[ui-buttonmap]
a=KEY_3
b=KEY_4
x=KEY_5
y=KEY_6

[ui-buttonmap]
lb=KEY_TAB
rb=KEY_ENTER
#black, white buttons (Xbox1 only, mapped to lb, rb on Xbox360)
#black=KEY_7
#white=KEY_8
#guide és el botó gros del mig
guide=KEY_C

[ui-buttonmap]
lt=KEY_5
rt=KEY_2
#tl, tr: pressing the left or right analog stick
tl=KEY_A
tr=KEY_1

[ui-buttonmap]
dl=KEY_LEFT
dr=KEY_RIGHT
du=KEY_UP
dd=KEY_DOWN

[ui-buttonmap]
back=KEY_0
start=KEY_1

# EOF #

La manera com arrenco els dos fitxers de configuració:

$ sudo rmmod xpad
$ sudo xboxdrv -c /home/pi/xboxdrv_joanillo.cfg --alt-config /home/pi/xboxdrv_joanillo_driving.cfg &

Afegim aquestes dues comandes al final del fitxer /etc/rc.local (allà on està el pikeyd), sense el sudo (doncs ja s'executa com a root).


creat per Joan Quintana Compte, gener 2016