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

Setting up a USB gamepad on FreeBSD

Discussion in 'Peripheral Hardware' started by phpwolf, May 6, 2012.

  1. phpwolf

    phpwolf New Member

    Messages:
    24
    Thanks Received:
    0
    Hello,

    I have a cheap but cool Thrustmaster gamepad and I want to use it for playing games in FreeBSD emulators. I tried to configure it but I really don't now very much about this process. Here is what I've done.

    1. I installed xf86-input-joystick and uhidd from ports
    2. I added these lines to rc.conf:
      Code:
      uhidd_flags="-kmohs"
      uhidd_enable="YES"
    3. When the gamepad is plugged in, the kernel said:
      Code:
      uhid0: <Mega World USB 2-Axis 8-Button Gamepad, class 0/0, rev 1.10/1.01, addr 3> on usbus1
      so it seems like the gamepad is seen by uhidd
    4. I added these lines to xorg.conf:
      Code:
      Section "ServerLayout"
      	Identifier     "X.org Configured"
      	Screen      1  "Screen1" 0 0
      	InputDevice    "Mouse0" "CorePointer"
      	InputDevice    "Keyboard0" "CoreKeyboard"
      	InputDevice    "Joy0" "SendCoreEvents"
      EndSection
      
      Section "InputDevice"
          Identifier     "Joy0"
          Driver         "joystick"
          Option         "Path" "/dev/uhid0"
          Option         "Device" "/dev/uhid0"
          # 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
      

      [/lit]

      The current behavior: xev doesn't show any event when the gamepad buttons are pressed.

      The Xorg.0.log joystick part here:

      Code:
      [    52.975] (II) Using input driver 'joystick' for 'Joy0'
      [    52.975] (II) Loading /usr/local/lib/xorg/modules/input/joystick_drv.so
      [    52.975] (**) Option "SendCoreEvents"
      [    52.975] (**) Joy0: always reports core events
      [    52.975] (II) No input driver specified, ignoring this device.
      [    52.975] (II) This device may have been added with another device file.
      [    52.975] (EE) PreInit returned 11 for "Joy0"
      [    52.975] (II) UnloadModule: "joystick"
      [    52.975] (II) Unloading joystick


      Can you help me, please, to understand what have I done wrong here?

      Thank you.
     
  2. phpwolf

    phpwolf New Member

    Messages:
    24
    Thanks Received:
    0
    It seems like the gamepad buttons respond to:

    uhidd -vvv -kmoh /dev/ugen1.3

    Here is the result:

    Code:
    ugen1.3[0]-> HID interface
    ugen1.3[0]-> Report descriptor size = 51
    ugen1.3[0]-> Find IN interrupt ep: 0x81 packet_size=0x8
    HID APPLICATION COLLECTION (Game Pad) size(51)
      HID REPORT: ID 0
        INPUT: 
          POS:0 SIZE:8 COUNT:2 [VARIABLE]
            USAGE X
            USAGE Y
          POS:16 SIZE:1 COUNT:8 [VARIABLE]
            USAGE Button1
            USAGE Button2
            USAGE Button3
            USAGE Button4
            USAGE Button5
            USAGE Button6
            USAGE Button7
            USAGE Button8
    ugen1.3[0]-> vhid device created: uvhidctl17
    ugen1.3[0]-> HID interface task started
    ugen1.3[0]-> vhid device created: uvhidctl17
    ugen1.3[0]-> HID interface task started
    ugen1.3[0]-> received data(3): -128 -128 04 
    hid_appcol_recv_data: len(3) 0x80 0x80 0x04
    ugen1.3[0]-> uvhidctl17 received data: 128 128 4
    ugen1.3[0]-> received data(3): -128 -128 00 
    hid_appcol_recv_data: len(3) 0x80 0x80 0x00
    ugen1.3[0]-> uvhidctl17 received data: 128 128 0
    ugen1.3[0]-> received data(3): -128 -128 02 
    hid_appcol_recv_data: len(3) 0x80 0x80 0x02
    ugen1.3[0]-> uvhidctl17 received data: 128 128 2
    ugen1.3[0]-> received data(3): -128 -128 00 
    hid_appcol_recv_data: len(3) 0x80 0x80 0x00
    ugen1.3[0]-> uvhidctl17 received data: 128 128 0
    ugen1.3[0]-> received data(3): -128 -128 01 
    hid_appcol_recv_data: len(3) 0x80 0x80 0x01
    ugen1.3[0]-> uvhidctl17 received data: 128 128 1
    ugen1.3[0]-> received data(3): -128 -128 00 
    hid_appcol_recv_data: len(3) 0x80 0x80 0x00
    ugen1.3[0]-> uvhidctl17 received data: 128 128 0
    ugen1.3[0]-> received data(3): -128 00 00 
    hid_appcol_recv_data: len(3) 0x80 0x00 0x00
    ugen1.3[0]-> uvhidctl17 received data: 128 0 0
    ugen1.3[0]-> received data(3): -128 -128 00 
    hid_appcol_recv_data: len(3) 0x80 0x80 0x00
    ugen1.3[0]-> uvhidctl17 received data: 128 128 0
    ugen1.3[0]-> received data(3): -128 -1 00 
    hid_appcol_recv_data: len(3) 0x80 0xff 0x00
    ugen1.3[0]-> uvhidctl17 received data: 128 255 0
    ugen1.3[0]-> received data(3): -128 -128 00 
    hid_appcol_recv_data: len(3) 0x80 0x80 0x00
    ugen1.3[0]-> uvhidctl17 received data: 128 128 0


    Now, I created a /usr/local/etc/uhidd.conf with this content, to map my gamepad buttons to keyboard buttons:

    Code:
    # 0x045e is the vendor id and 0x009d is the product id.
    # See `uhidd.conf(5)` manual page for details about configuration file.
    0x045e:0x009d={
            cc_keymap={
    		KEY_C="0x04"
    		KEY_X="0x01"
    		KEY_D="0x08"
    		KEY_S="0x02"
    		KEY_Z="0x10"
    		KEY_V="0x20"
            }
    }


    Then restarted the uhidd daemon with:

    /usr/local/etc/rc.d/uhidd stop /dev/ugen1.3

    Nothing happens (I suppose after pressing gamepad buttons to see the C, X, D, S, Z and V key typed to the console). Another thing: how can I found the vendor id and the product id for my keyboard?
     
  3. DutchDaemon

    DutchDaemon Administrator Staff Member Administrator Moderator

    Messages:
    10,767
    Thanks Received:
    1,872
  4. phpwolf

    phpwolf New Member

    Messages:
    24
    Thanks Received:
    0