28 07 | 2011

Using a gamepad under GNU/Linux

Written by Tanguy

Classified in : Homepage, Debian, Miscellaneous

Saitek PS2700 gamepad

I have just bought a gamepad, the Saitek V.3 Cyborg Rumble Pad (also marketed as PS2700), mainly to play at SuperTuxKart under Debian GNU/Linux.

It works perfectly, except for one minor feature, and it can be used for playing and as an X11 input device.

System support

This device uses USB HID so it is directly supported by the Linux kernel, with its module joydev, I guess: it appears as /dev/input/eventX and /dev/input/jsY.

It can be tested with jstest-gtk from the package jstest-gtk: it has 7 axes (two sticks, one directional pad and two triggers that count as one single axis) and 13 buttons (4 regular, 2 rear, the 2 triggers that also send button events, 3 specials and the 2 sticks that can be clicked). They are presented in an order that is rather logical, except the trigger axis is inserted between the two axis of the second stick.

It also features two strange buttons:

  • a “precision mode” switch, that is meant to “slow” the sticks, restricting them to a narrow logical range to allow a precise aim: this does not work at all, I suppose it requires some driver support;
  • a “PC/PS3” switch that produces a disconnection and an immediate reconnection and changes the events the pad reports: in PS3 mode, the triggers axis disappears (and the two axis of the second stick become consequently adjacent).

Game support

I only tested SuperTuxKart, but I think any game able to use a gamepad or a joystick should support it: after all, they all use the same protocol. The default mapping is rather logical but I find it more convenient to use the triggers rather than the main stick to accelerate and brake.

I do not know if the vibration feature can be used at all, because I do not know how it is exposed and I do not think I have any game that would be able to take advantage of it.

X.Org support

This is an interesting feature: X.Org has a joystick(4) driver, available in the package xserver-xorg-input-joystick that allows you to use a joystick or a gamepad as an input device, both for pointing and typing.

So, just for fun, I installed the joystick driver. It installs a default configuration file as /usr/share/X11/xorg.conf.d/50-joystick.conf, that is enough to provide features equivalent to a regular mouse. But given the number of axes and buttons of my pad, it deserved a special configuration in /etc/X11/xorg.conf.d/rumblepad.conf:

Section "InputClass"
    Identifier  "Rumble Pad"
    Option      "MatchIsJoystick"   "on"
    Option      "MatchProduct"      "Cyborg V.3 Rumble Pad"

    # Main stick axes: point
    Option      "MapAxis1"          "mode=relative axis=+1x deadzone=5000"
    Option      "MapAxis2"          "mode=relative axis=+1y deadzone=5000"

    # Second stick axes: scroll
    Option      "MapAxis3"          "mode=relative axis=+1zx deadzone=5000"
    Option      "MapAxis5"          "mode=relative axis=+1zy deadzone=5000"

    # Triggers: scroll vertically
    Option      "MapAxis4"          "mode=relative axis=+1zy deadzone=5000"

    # Directional pad: point
    Option      "MapAxis6"          "mode=accelerated axis=+1x deadzone=5000"
    Option      "MapAxis7"          "mode=accelerated axis=+1y deadzone=5000"

    # Buttons 1, 2 and 3 : click (no use for button 4)
    Option      "MapButton1"        "button=1"
    Option      "MapButton2"        "button=2"
    Option      "MapButton3"        "button=3"
    Option      "MapButton4"        "none"

    # Rear buttons: back and forward
    Option      "MapButton5"        "key=166"   # XF86Back
    Option      "MapButton6"        "key=167"   # XF86Forward

    # Triggers: no use
    Option      "MapButton7"        "none"
    Option      "MapButton8"        "none"

    # Special buttons
    Option      "MapButton9"        "key=135"   # select : Menu
    Option      "MapButton10"       "key=172"   # start : XF86AudioPlay
    Option      "MapButton13"       "key=180"   # home : XF86HomePage

    # Sticks click: click
    Option      "MapButton11"       "button=1"  # clic left stick
    Option      "MapButton12"       "button=3"  # clic right stick
EndSection

It is commented, but here is what it does:

  • point with the main stick and the directional pad;
  • scroll with the second stick and the triggers;
  • click with the game buttons and the sticks;
  • navigate back and forth with the rear buttons (I use that to switch between my virtual desktops);
  • do some special stuff with the special buttons: open the context menu, play the music, open a file explorer to your home directory.

It is worth noting that joysticks have one feature that mice do not have: they allow to scroll at a variable speed, proportional to the shift of an “analogue” stick. This is the meaning of these zx and zy axes I mapped to the second stick, and it provides a scrolling experience that is far superior from that of a mouse wheel.

3 comments

friday 29 july 2011 à 00:31 Tanguy said : #1

Erf, my gamepad picture looks bad with its white background on the Debian planet that puts a grey background under the posts.

Google, please hurry in adding alpha channel support to WebP and having browser support it!

thursday 23 april 2015 à 14:55 MCMic said : #2

link http://www.gamesharkstore.fr/Cyborg_V.3_Gaming_Pad_for_PC_and_PlayStation_3_2/4892/185 is dead

sunday 01 november 2015 à 22:56 Julian Kallenborn said : #3

Thank you very much my friend!

Write a comment

What is the first letter of the word jvhhi? : 

Archives