Author Topic: New Feature: USB Gamepad Support for on-screen control  (Read 5750 times)

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
New Feature: USB Gamepad Support for on-screen control
« on: September 24, 2011, 05:04:58 am »
Hello everyone, I've finished the support for using USB Gamepads to control on-screen Orbiters on TVs within LinuxMCE. I have pasted the wiki content of the following article because I am too lazy to type it out again,

Enjoy
-Thom

LinuxMCE as of 10.04 can allow any media director to control its on-screen [[Orbiter]] using a standard [http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=usb+game+pad&x=0&y=0 USB Game Pad].

== How to install ==

Simply plug in the USB Game Pad, at any time, and the system will automatically detect up to 4 USB Game pads, and allow them to control Orbiter.

== How to use ==

=== Navigating items ===

==== Direction Pad ====

Items can be navigated either by a gamepad's direction cross, or by using the analogue wheels. Pressing down and releasing will cause the cursor to move in the direction pressed on the game pad. Currently button presses are not repeated.

For MythTV, pressing up and down, will cause the channel browser to change to the previous and next channel.

==== Buttons ====

By default, the USB Game Pad Remote device installed is mapped for a SIXAXIS(tm) compatible gamepad with 12 buttons total.
* The four diamond buttons.
** Button 1 - '''OK/Select/Enter'''
** Button 2 - '''Back'''
** Button 3 - '''Pause'''
** Button 4 - '''Stop'''
* The Front buttons
** Button 5 (''aka L1 - aka the small one on the left'') - '''Volume Down'''
** Button 6 (''aka R1 - aka the small one on the right'') - '''Volume Up'''
** Button 7 (''aka L2 - aka the big one on the left'') - '''Page Down/Skip Back'''
** Button 8 (''aka R2 - aka the big one on the right'') - '''Page Up/Skip Forward'''
** Button 9 (''aka what most people think as Select'') - '''Back''' (''same as Button 2'')
** Button 10 (''aka what most people think as Start'') - '''Home'''

=== Plugging and Unplugging ===

Game Pads can be plugged and unplugged at any time. The router will not need to be reloaded.

=== Use Within Games ===

Because there is no Home Button on most USB game pads, When a game is started by the [[Game Player]], the system will automatically pass through the USB game pads directly to the Game Player engine; any subsequent usage of the gamepad will be ignored by Orbiter unless Orbiter displays another visible screen. This means that you will not be able to get to the home menu currently while playing a game (because the start button would be mapped to the game system.)

== Changing the controller mapping ==

(preliminary instructions follow)

The controller mapping can currently be changed by accessing the web admin, selecting [[Advanced Pages Devices|Advanced > Configuration > Devices]], selecting the USB Game Pad remote device closest to your media director, and scrolling down to see the Configuration device data entry.

By default, the controller mapping is:

 up USB-GAMEPAD-UP USB-GAMEPAD-UP
 down USB-GAMEPAD-DOWN USB-GAMEPAD-DOWN
 left USB-GAMEPAD-LEFT USB-GAMEPAD-LEFT
 right USB-GAMEPAD-RIGHT USB-GAMEPAD-RIGHT
 ok USB-GAMEPAD-B1 USB-GAMEPAD-B1
 back USB-GAMEPAD-B9 USB-GAMEPAD-B9
 back USB-GAMEPAD-B2 USB-GAMEPAD-B2
 skipback USB-GAMEPAD-B5 USB-GAMEPAD-B5
 skipback USB-GAMEPAD-B7 USB-GAMEPAD-B7
 skipfwd USB-GAMEPAD-B6 USB-GAMEPAD-B6
 skipfwd USB-GAMEPAD-B8 USB-GAMEPAD-B8
 menu USB-GAMEPAD-B3 USB-GAMEPAD-B3
 menu USB-GAMEPAD-B10 USB-GAMEPAD-B10

The syntax is very simple:

 remotemapping USB-GAMEPAD-XX USB-GAMEPAD-XX

The remotemapping entry corresponds to an entry in the [[Infrared Remote Buttons Understood by LinuxMCE|RemoteMapping]] table,

The second and third components right now correspond to the same thing (the third field is unused, but must be specified), that is, what USB button to press, either consisting of:

* A direction: UP, DOWN, LEFT, and RIGHT are currently understood. (do we need more?)
* A Button #, B1, B2, B3, ... B11, B12, for example.

Using this nomenclature, and the link to the [[Infrared Remote Buttons Understood by LinuxMCE|RemoteMapping]] table, it is possible to map any button on the gamepad to something useful in LinuxMCE. The Remote control template used will be the one closest to that media director (so yes, it is possible, although ill advised, for each media director to have a different button mapping.)

== Usage in AV Wizard ==

It is possible, to use the gamepad with the AV Wizard. Simply attach a game pad before powering up the unit. Holding down the 1 button while the system is booting will cause the [[AVWizard]] to launch.

Once the [[AVWizard]] has been started, it is possible to use the gamepad to navigate and select items within the wizard, and also to select explicit video modes, just as if number keys had been pressed on a real keyboard:

The following buttons are mapped for the AV Wizard:

* Button 2 - DVI
* Button 3 - DVI-2
* Button 4 - HDMI
* Button 5 - VGA
* Button 6 - VGA-2
* Button 7 - Component
* Button 8 - Composite
* Button 9 - S-Video

== Source Code ==

Source code for this module may be found here:
* [http://svn.linuxmce.org/svn/branches/LinuxMCE-1004/src/USB_Game_Pad/ http://svn.linuxmce.org/svn/branches/LinuxMCE-1004/src/USB_Game_Pad/]

== Trademarks ==

SIXAXIS(tm) is a trademark of Sony Corporation.

(and before anyone asks, yes, SixAxis controllers that are connected via a USB cable work. Bluetooth support will not work yet until we do some serious re-engineering of our BlueTooth stack!)

Murdock

  • Guru
  • ****
  • Posts: 229
    • View Profile
Re: New Feature: USB Gamepad Support for on-screen control
« Reply #1 on: September 24, 2011, 04:24:26 pm »
Thanks Thom! My usb logitech works great!

After an afternoon of playing punch out on my core, I'm loving the game integration!
« Last Edit: September 25, 2011, 03:14:11 am by Murdock »

Armor Gnome

  • Guru
  • ****
  • Posts: 309
    • View Profile
Re: New Feature: USB Gamepad Support for on-screen control
« Reply #2 on: May 06, 2013, 12:49:17 am »
I wanted to list a few of the usb-gamepads I have used and their detection issues, performance and what I have done to get them working as game remotes. 

Common Problems:
USB-Gamepad is detected and two devices are created, usb-gamepad & usb-gamepad remote.
Use as controller for onscreen orbiter works very well however the device is not "grabbed" by the game player.  When a game is being played pressing back still brings up the onscreen UI.
I overcome this problem by using the remotes exclusively for gameplay by disabling "usb-gamepad remote" and deleting its key settings.


MicroSoft Plug & Play Game Pad (part no. X04-97602)
Comfortable, very much like a madcatz 'stretched' PS2 remote feel.  4 buttons with L & R triggers.  D-pad is not analog but works well for older titles using very clean UP, DOWN, etc etc without rolled diagonal inputs being common.  Good little gamepad for people who prefer very deliberate key presses, also the most simple of my game pads as in it doesn't require toggling between modes or having too many unused buttons.  Short usb cable requires an extension to play comfortably

Game Foundry USB GAME PAD (G60310A)
Used as my main living room gamepad, dual analog (doubling as buttons 9 & 10), d-pad, esc & enter located centrally where start select would be, 4 front buttons, 2 L & 2 R shoulder buttons, "mode" button.  The mode button toggles use of the analog controls which for most of the games playable currently are just a tad over sensitive.  Pressing down on the analogs for buttons 9 & 10 is disabled when "mode" is not illuminated.  Some titles for reasons I have not resolved also require "mode" while others do not, regardless of if d-pad or analog stick is used...   Good cord length does not need an extension in small to medium rooms.

GameStop branded Mad Catz Xbox 360 wired controller
Horrible, sorry I have nothing good to say about this controller under lmce as a gamepad remote.  As a orbiter remote I have nothing short of 4 letter words about it.  The sensitivity is just so high that trying to select Lights on UI2 could easily end up bringing up KDE desktop!  Maybe for some of the later MegaDrive games this could be useful but I haven't come across a use for it yet.
I made a wiki!  Click here to check out my system.

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: New Feature: USB Gamepad Support for on-screen control
« Reply #3 on: May 06, 2013, 02:19:39 am »
Gamepads typically do not have a _back_ button, and with the current code, while game play is happening, all game pad buttons literally are ignored by the USB Game Pad device, so I think you'll need to be a bit more specific, here.

-Thom

Armor Gnome

  • Guru
  • ****
  • Posts: 309
    • View Profile
Re: New Feature: USB Gamepad Support for on-screen control
« Reply #4 on: May 06, 2013, 06:27:02 am »
I understand the button mapping 'should' change when in gameplay.  When I say BACK I mean the gamepad beings up the onscreen UI just as it would if I was at flicker art and wanted to see the menu or wanted to exit a media file grid.  Because each remote labels these buttons differently I have a hard time explaining...

On the simple 4 button remote.  The topmost button works as a left mouse button would, rightmost button works like a right mouse click.

Enter gameplay. Super Mario Bros NES for example.
Topmost button = A (menus, fireballs)
Rightmost button = B (jump)

Pressing the rightmost button jumps but it also brings up the UI overlay.  This is bad because until you press "B" again, all directional key presses navigate the UI and "A" works like "enter". 
I made a wiki!  Click here to check out my system.

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: New Feature: USB Gamepad Support for on-screen control
« Reply #5 on: May 07, 2013, 01:58:46 am »
Ok, that is a very strange bug, that should never happen. Can you tell me the version of the lmce-usb-gamepad package that you have ?

-Thom

Marie.O

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 3676
  • Wastes Life On LinuxMCE Since 2007
    • View Profile
    • My Home
Re: New Feature: USB Gamepad Support for on-screen control
« Reply #6 on: May 07, 2013, 12:33:17 pm »
To get the version, go to the commandline and dpkg -l lmce-usb-gamepad

Armor Gnome

  • Guru
  • ****
  • Posts: 309
    • View Profile
Re: New Feature: USB Gamepad Support for on-screen control
« Reply #7 on: May 07, 2013, 11:20:53 pm »
Result:

Quote
lmce-usb-gamep 2.0.0.45.13020

For the sake of completeness I checked version on my hybrid and three media directors where I have gameplayer running.  I also performed:

apt-get update
apt-get install lmce-usb-gamepad

This returned that I had the most current version.

My work around as I said basically kills all orbiter remote functionality by disabling and removing its keymapping.  Here are some environmental variables that may be helpful.

Install method for gameplayer:  Select gameplayer from web-admin>media directors>edit modules?>checkbox>save>close>reload router.  Gameplayer-plugin is unassigned to a room so I put it in the room with the hybrid since it is category 'controlled by dcerouter'

Install method for usb-gamepad:  Plug it in, gamepad detection picks it up within a few seconds, use as an orbiter remote is automagic, open gameplayer and individually map buttons for each system the way I like them (ie, 1 button consoles using the bottom button, 2 buttons using top and right, genesis using left, top, right, etc)

Connections:  Gamepads are disconnected when not in use,  typically connected after a game is initiated via orbiter.

Equipment variables: 
LivingRoom MD - MSI P45-Neo3 w/ usb-uirt 0056, gyration 'fiire clone' dongle, cm15a & occasionally a generic USB keyboard making up lsusb. 
Den MD - Revo R1600 (mem upgraded, hdd ignored) w/ occasional USB mouse or USB keyboard on lsusb.
Desk MD (hybrid/core) - Asus M4A785TD-M EVO w/ USB keyboard, USB mouse full time

lsusb -v from Revo when connected: Sidewinder & GameFoundry (unused hub info removed)
Quote
root@moon64:~# lsusb -v

Bus 002 Device 005: ID 045e:0027 Microsoft Corp. SideWinder PnP GamePad
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x045e Microsoft Corp.
  idProduct          0x0027 SideWinder PnP GamePad
  bcdDevice            1.05
  iManufacturer           1 Microsoft�
  iProduct                2 Microsoft� SideWinder� Plug & Play Game Pad
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.00
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      57
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0003  1x 3 bytes
        bInterval              10
Device Status:     0x0000
  (Bus Powered)
Quote
Bus 002 Device 004: ID 0e8f:0003 GreenAsia Inc.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x0e8f GreenAsia Inc.
  idProduct          0x0003
  bcdDevice            1.07
  iManufacturer           1 GreenAsia Inc.   
  iProduct                2 USB Joystick     
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode           33 US
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength     101
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              17
Device Status:     0x0001
  Self Powered


I made a wiki!  Click here to check out my system.