HOWTO: Gamepad and FreeBSD

Would you like to share some of your solutions for certain problems? Tips or tricks? Post here. All new topics are automatically moderated.

HOWTO: Gamepad and FreeBSD

Postby serjsk8 » 11 Oct 2010, 00:27

Hi everyone!
This is my first HOWTO!:)

Sometimes I play different games on the emulator SNES9x and play on the keyboard is not very convenient. I remembered that I have a USB Gamepad (Logitech Dual Action â„¢ Gamepad).
http://www.logitech.com/en-us/gaming...rs/devices/288
So I decided to connect it ....

I heve OS:

Code: Select all
FreeBSD 8.1-RELEASE


First, Install X. Org joystick input driver:

Code: Select all
# pkg_add -r xf86-input-joystick


Next, install uhidd (USB HID daemon). uhidd is a userland driver/daemon for USB HID devices like mouse, keyboard etc...

Code: Select all
# cd /usr/ports/sysutils/uhidd
# make install clean


To start "uhidd" automatically, add the following lines to the file /etc/rc.conf

Code: Select all
uhidd_flags="-kmohs"
uhidd_enable="YES"


More info about "uhidd" you can read hear:
http://wiki.freebsd.org/uhidd

Connect gamepad and restart your computer.
When you start you can see something like this:

Code: Select all
ugen1.2: <vendor 0x046d> at usbus1
uhid0: <vendor 0x046d product 0xc216, class 0/0, rev 1.10/3.00, addr 2> on usbus1


This is may gamepad! System has found it!

Now we add our device in /etc/X11/xorg.conf
Need to mapping the buttons and axis.
Explane:
"MapAxis1","MapAxis2" - POV control, cross of four buttons with the left. I assign to them the following keys from the keyboard: UP - w, DOWN - s, LEFT - a, RIGHT-d.
"MapAxis3","MapAxis4" - right analog sticks will work like mouse.
"MapAxis5","MapAxis6" - left analog sticks will work like ARROW up, down, left, right on the keyboard.
Four button whith the right will work like buttons of keyboard "1", "2", "3", "4".
Two buttons in the middle, it will be "space" and "enter".
Buttons LU y RU - "5", "6"
Buttons LD y RD - will be mouse click.

Code: Select all
Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0"
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
    # Add Gamepad
    [B]InputDevice    "Logitech" "SendCoreEvents"[/B]
EndSection

Section "InputDevice"
    Identifier     "Logitech"
    Option         "Vendor" "Logitech"
    Driver         "joystick"
    Option         "Path" "/dev/uhid0"
    Option         "Device" "/dev/uhid0"
    Option         "DebugLevel" "99"
    # Right Buttons
    # Button w(Up)/s(Down)
    # Button a(Left)/s(Right)
    Option         "MapAxis1" "mode=accelerated keylow=38 keyhigh=40"
    Option         "MapAxis2" "mode=accelerated keylow=25 keyhigh=39"
    # Right joystick: Like mouse
    Option         "MapAxis3" "mode=relative axis=+1x deadzone=5000"
    Option         "MapAxis4" "mode=relative axis=+1y deadzone=5000"
    # Left joystick:
    # axis X - Left/Right
    # axis Y - Up/Down
    Option "MapAxis5"       "mode=relative deadzone=28000 keylow=100 keyhigh=102 axis=0.15key"
    Option "MapAxis6"       "mode=relative deadzone=28000 keylow=98 keyhigh=104 axis=0.15key"
    #
    Option         "MapButton1" "key=10"
    Option         "MapButton2" "key=11"
    Option         "MapButton3" "key=12"
    Option         "MapButton4" "key=13"
    Option         "MapButton5" "key=14"
    Option         "MapButton6" "key=15"
    # mouse button: left
    Option         "MapButton7" "button=1"
    # mouse button: right
    Option         "MapButton8" "button=3"
    # button "Space"
    Option         "MapButton9" "key=65"
    # button "Enter"
    Option         "MapButton10" "key=36"
EndSection


That's all... setting is finished!
Restart X.

For check the gamepad you can use "xev".
Now run the emulator Snes9x or the other, assign buttons and play!

Thank all!
Code: Select all
serjsk8
Junior Member
 
Posts: 48
Joined: 26 Mar 2010, 16:16

Postby Eponasoft » 11 Oct 2010, 02:46

If MapAxis1 and MapAxis2 correspond to the D-pad on the left, then it's called a POV or "hat" control. I'd personally assign it differently, but this layout would be fine for many applications. Good tutorial, we need more like this. :) I personally have a PS to USB adapter so I use my PS controllers on my computers.
OS fanaticism is for the cranially disadvantaged. I use FreeBSD because I like FreeBSD, not because I dislike Linux or Windows... although the latter is still true...
User avatar
Eponasoft
Member
 
Posts: 218
Joined: 23 Nov 2008, 07:16

Postby serjsk8 » 11 Oct 2010, 09:10

Thank you!
I have changed name of 4 buttons, and wrote POV! :)
serjsk8
Junior Member
 
Posts: 48
Joined: 26 Mar 2010, 16:16

Postby noz » 25 Oct 2010, 08:23

I can't believe I can finally use my controllers on FreeBSD. Thanks!
noz
Junior Member
 
Posts: 41
Joined: 02 Aug 2010, 16:33

Postby Acetilene » 23 Apr 2012, 20:39

Hi guys! I'm an Italian user of freebsd FreeBSD. I'm very new to this beautiful system, so I have started with GhostBSD (a freebsd FreeBSD version with gnome already started). I have tried to follow this howto but when I add the gamepad to xorg.conf the mouse stops working correctly and I must press ctrl+alt+F2 for enter in a shell and restore xorg.conf.
Here are the sections of xorg.conf that I have changed:

Code: Select all
Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0"
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
    InputDevice    "Joy0" "SendCoreEvents"
EndSection

Section "InputDevice"
    Identifier     "Joy0"
    Driver         "joystick"
    Option         "Path" "/dev/uhid0"
    Option         "Device" "/dev/uhid0"
EndSection


When I restart I can see this:
Code: Select all
ugen3.2: <vendor 0x0079> at usbus3
uhid0: <vendor 0x0079 usbgamepad, class 0/0, rev 1.00/1.06, addr 2> on usbus3


Any idea? Thanks to everyone.
Acetilene
Junior Member
 
Posts: 17
Joined: 23 Apr 2012, 20:03
Location: Italy

Postby serjsk8 » 24 Apr 2012, 07:56

Hello.
Please publish "All/fully" your configuration file.
serjsk8
Junior Member
 
Posts: 48
Joined: 26 Mar 2010, 16:16

Postby Acetilene » 25 Apr 2012, 16:57

Ok! Actually I have removed the changes because with them I wasn't in able to use xserver.

Code: Select all
# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig:  version 285.05.09  (root@GhostBSD)  Ven  9 Mar 2012 00:59:30 CET


Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0" 0 0
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
EndSection

Section "Files"
    FontPath        "/usr/local/lib/X11/fonts/TTF/"
EndSection

Section "InputDevice"

    # generated from default
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/sysmouse"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"

    # generated from default
    Identifier     "Keyboard0"
    Driver         "keyboard"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Unknown"
    HorizSync       28.0 - 33.0
    VertRefresh     43.0 - 72.0
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection
Acetilene
Junior Member
 
Posts: 17
Joined: 23 Apr 2012, 20:03
Location: Italy


Return to Howtos & FAQs (Moderated)

Who is online

Users browsing this forum: No registered users and 0 guests