1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

HOWTO: Gamepad and FreeBSD

Discussion in 'Howtos and FAQs (Moderated)' started by serjsk8, Oct 11, 2010.

  1. serjsk8

    serjsk8 New Member

    Messages:
    62
    Thanks Received:
    2
    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:
    FreeBSD 8.1-RELEASE


    First, Install X. Org joystick input driver:

    Code:
    # 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:
    # cd /usr/ports/sysutils/uhidd
    # make install clean


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

    Code:
    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:
    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:
    Section "ServerLayout"
        Identifier     "Layout0"
        Screen      0  "Screen0"
        InputDevice    "Keyboard0" "CoreKeyboard"
        InputDevice    "Mouse0" "CorePointer"
        # Add Gamepad 
        InputDevice    "Logitech" "SendCoreEvents"
    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!
     
    noz and Eponasoft thanked for this.
  2. Eponasoft

    Eponasoft New Member

    Messages:
    218
    Thanks Received:
    10
    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.
     
  3. serjsk8

    serjsk8 New Member

    Messages:
    62
    Thanks Received:
    2
    Thank you!
    I have changed name of 4 buttons, and wrote POV! :)
     
  4. noz

    noz New Member

    Messages:
    41
    Thanks Received:
    11
    I can't believe I can finally use my controllers on FreeBSD. Thanks!
     
  5. Acetilene

    Acetilene New Member

    Messages:
    17
    Thanks Received:
    0
    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:
    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:
    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.
     
  6. serjsk8

    serjsk8 New Member

    Messages:
    62
    Thanks Received:
    2
    Hello.
    Please publish "All/fully" your configuration file.
     
  7. Acetilene

    Acetilene New Member

    Messages:
    17
    Thanks Received:
    0
    Ok! Actually I have removed the changes because with them I wasn't in able to use xserver.

    Code:
    # 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