Joystick Control

From MythTV Official Wiki
Revision as of 21:10, 23 April 2013 by Jarmen (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

It is possible to control MythTV by using a Joystick. This option is especially useful for Xbox frontends, however, with the versitile USB Xbox 360 controller it may make a great deal of sense to opt for a joystick over a remote control.

For the sample configuration file below I used a Xbox 360 controller connected to an Ubuntu 12.10 installation running mythtv-0.26 ,I found it incredibly helpful to install a package called jstest-gtk by running

sudo apt-get install jstest-gtk

This GTK based program will display to you the buttons and axis that are available on your joystick.

One other small bit to note. It seems that the "chords" that you can define in the config file activate when the second button in the chord is released. This is a little strange but no big deal. In addition, you must release all buttons in the chord and then press them again to re-issue the command defined by the chord.

I found that the analog sticks (axis) will fire only one time with most of the config options found below. That's fine if you're using them as "buttons" but if you want to use them as analog sticks you need to define multiple smaller ranges for the axis. For example:

#Down
       axis   4    -32767  -15000  F10

Sets a single F10 to be issued when the axis is moved down, however this:

#Down 3 times
       axis   4    -20000  -15000  F10
       axis   4    -25000  -20001  F10
       axis   4    -32767  -25001  F10

places 3 ranges in the swing of the axis. Each time the axis passes between a range an F10 is issued. It is important to note: if you swing the axis to the maximum and then let it return to center you will actually issues 6 F10s, one for each range on the way down, one for each range on the way back up. Keep this in mind when deciding how many and how big to make the ranges.

Xbox vs PC Configuration

For the second and third example I used an XBOX controller. Strangely, the controller is handled slightly differently by the PC driver than the Xbox's native driver. Most noticeably the D-Pad is seen as a set of axis on the PC but it is a set of buttons on the XBox. This actually makes some "chords" possible that otherwise were not on the PC. Please note the 2 configuration files below. They do the same thing, one is for the XBox, the other for the PC.

There's another really cool aspect of the Xbox Controller on the XBOX. Every button also has a corresponding axis. This, no doubt, facilitates the pressure sensitivity of the buttons. Each ranges from 0 to 255. One could, if he chose, wire actions up based on the pressure placed on a button. I'm not sure how to use that intelligently, but I'm sure I'll (we'll) come up with something cool.

Configuration Files

MythTV joystick control is accomplished by defining a plain text document called joystickmenurc in the ~/.mythtv directory for the user that launches your mythfrontend.


Formatting

button num keystring
Send 'keystring' when button 'num' is released
chord cnum bnum keystring
If button cnum is down, and button 'bnum' is released, send keystring
axis num from to keystring
If axis num goes into the range of from-to send keystring


Sample File (Xbox 360 Controller on PC) I would reccommend changing it for your own taste

# ~/.mythtv/joystickmenurc
# Joystick menu config file
#  Place in /media/.mythtv/
#
#   Format:
#       devicename <devname>        Specify name of joystick device to use
#                                   (e.g. /dev/js0)
#       button num keystring        Send 'keystring' when button 'num' is released
#       chord cnum bnum keystring   If button cnum is down, and button 'bnum'
#                                   is released, send keystring
#       axis num from to keystring  If axis num goes into the range of from-to
#                                   send keystring


devicename /dev/input/js0



######################################################################
#
#       Stick/Pad Configuration
#
######################################################################


##############################################
#
#       D-Pad
#
##############################################

#Right
        axis    6       -32767       0       Right
#Left
        axis    6       0       32767       Left
#Down
        axis    7       -32767       0       Down
#Up
        axis    7       0       32767       Up


##############################################
#
#       Left Stick
#
#       Slow Mo Controls
#
##############################################
#Left Analog stick
#Left
        axis   0    -32767  -10000  U
#Right
        axis   0     10000   32767  J
#Down
#       axis   1    -32767  -15000  Down
#Up
#       axis   1     15000   32767  Up
#Button
#       button  9       Enter


##############################################
#
#       Right Stick
#
#
#
##############################################
#Right Analog stick
#Left
#       axis   3    -32767  -10000  U
#Right
#       axis   3     10000   32767  J


#####
#
#  Add 3 ranges to the Up/Down of the stick
#  Used for volume
#  Does about a 10% Jump tick.
#  Hits when moving the stick and when the stick returns to center
#    causing an extra set of presses.  This can be used for finess
#    a smaller push can hit once, a medium 3 or 4, and a full all 6
#
#####
#Down
#       axis   4    -32767  -15000  F10
        axis   4    -20000  -15000  F10
        axis   4    -25000  -20001  F10
        axis   4    -32767  -25001  F10

#Up
#       axis   4     15000   32767  F11
        axis   4     15000   20000  F11
        axis   4     20000   25000  F11
        axis   4     25001   32767  F11

#Button
#       button  10       Enter




######################################################################
#
#       Trigger Configuration  Configuration
#
######################################################################


#Left trigger pull      Rewind (Repeat to speed up)
        axis   2        -10000     25500     <
#Right trigger pull     Fastforward (Repeat to speed up)
        axis   5        -10000     25500     >




######################################################################
#
#       Button Configuration
#
######################################################################


##############################################
#
#       Baseline Buttons
#
##############################################

#Back -=- Escape
        button  6       Escape
#Start Button -=- Pause
        button  7       M

#A Button -=- Enter
        button  0       Enter
#B Button -=- On Screen Menu
        button  1       P
#X Button
       button  2       I
#Y Button
       button  3       E
#LB Button
       button  4       Left       
#RB Button
       button  5       Right
#Centre X Button
       button  8       S






######################################################################
#
#       Function Specific Configuration
#
######################################################################

#	I Do not edit mode use so commented it out.

#####################################
# Edit Mode Controls
#
# Y to Enter/Exit
# Start = Shift
#       Z   = LoadCut
#       LB = PrevCut
#       RB = NextCut
#       X   = Transcode
#
#####################################

#Y Button -=- Enter Edit Mode
#button  3       E
#Start + Y -=- Load CutpointsHOWTO
#chord   7       3       Z
#Start + RB -=- Jump Next Cutpoint
#chord   7       5       PgDown
#Start + LB -=- Jump Previous Cutpoint
#chord   7       4       PgUp
#Start + X -=- Queue for Transcode
#chord   7       2       X

Sample File (Xbox Controller on PC)

# ~/.mythtv/joystickmenurc
# Joystick menu config file
#  Place in /media/.mythtv/
#
#   Format:
#       devicename <devname>        Specify name of joystick device to use
#                                   (e.g. /dev/js0)
#       button num keystring        Send 'keystring' when button 'num' is released
#       chord cnum bnum keystring   If button cnum is down, and button 'bnum'
#                                   is released, send keystring
#       axis num from to keystring  If axis num goes into the range of from-to
#                                   send keystring


devicename /dev/input/js0



######################################################################
#
#       Stick/Pad Configuration
#
######################################################################


##############################################
#
#       D-Pad
#
##############################################

#Right
        axis    6       -1      0       Right
#Left
        axis    6       0       1       Left
#Down
        axis    7       -1      0       Down
#Up
        axis    7       0       1       Up


##############################################
#
#       Left Stick
#
#       Slow Mo Controls
#
##############################################
#Left Analog stick
#Left
        axis   0    -32767  -10000  U
#Right
        axis   0     10000   32767  J
#Down
#       axis   1    -32767  -15000  Down
#Up
#       axis   1     15000   32767  Up
#Button
#       button  7       Enter


##############################################
#
#       Right Stick
#
#
#
##############################################
#Right Analog stick
#Left
#       axis   3    -32767  -10000  U
#Right
#       axis   3     10000   32767  J


#####
#
#  Add 3 ranges to the Up/Down of the stick
#  Used for volume
#  Does about a 10% Jump tick.
#  Hits when moving the stick and when the stick returns to center
#    causing an extra set of presses.  This can be used for finess
#    a smaller push can hit once, a medium 3 or 4, and a full all 6
#
#####
#Down
#       axis   4    -32767  -15000  F10
        axis   4    -20000  -15000  F10
        axis   4    -25000  -20001  F10
        axis   4    -32767  -25001  F10

#Up
#       axis   4     15000   32767  F11
        axis   4     15000   20000  F11
        axis   4     20000   25000  F11
        axis   4     25001   32767  F11

#Button
#       button  8       Enter




######################################################################
#
#       Trigger Configuration  Configuration
#
######################################################################


#Left trigger pull      Rewind (Repeat to speed up)
        axis   2        100     255     <
#Right trigger pull     Fastforward (Repeat to speed up)
        axis   5        100     255     >




######################################################################
#
#       Button Configuration
#
######################################################################


##############################################
#
#       Baseline Buttons
#
##############################################

#Back -=- Escape
        button  9       Escape
#Start Button -=- Pause
        button  6       P

#A Button -=- Enter
        button  0       Enter
#B Button -=- On Screen Menu
        button  1       M
#X Button
#       button  3
#Y Button
#       button  4       E
#Wht Button
#       button  5
#Blk Button
#       button  2






######################################################################
#
#       Function Specific Configuration
#
######################################################################

#####################################
# Edit Mode Controls
#
# Y to Enter/Exit
# Start = Shift
#       Z   = LoadCut
#       Wht = PrevCut
#       Blk = NextCut
#       X   = Transcode
#
#####################################

#Y Button -=- Enter Edit Mode
button  4       E
#Start + Y -=- Load CutpointsHOWTO
chord   6       4       Z
#Start + Blk -=- Jump Next Cutpoint
chord   6       2       PgDown
#Start + White -=- Jump Previous Cutpoint
chord   6       5       PgUp
#Start + X -=- Queue for Transcode
chord   6       3       X

Sample File (Xbox Controller on PC, Alternate Config)

Not sure why but the buttons seem to have changed. When I tried the configuration file above on Ubuntu Feisty Fawn some of the buttons seem to have changed. I swapped the buttons around in the configuration file below... YMMV.

# ~/.mythtv/joystickmenurc
# Joystick menu config file
#  Place in /media/.mythtv/
#
#   Format:
#       devicename <devname>        Specify name of joystick device to use
#                                   (e.g. /dev/js0)
#       button num keystring        Send 'keystring' when button 'num' is released
#       chord cnum bnum keystring   If button cnum is down, and button 'bnum'
#                                   is released, send keystring
#       axis num from to keystring  If axis num goes into the range of from-to
#                                   send keystring


devicename /dev/input/js0



######################################################################
#
#       Stick/Pad Configuration
#
######################################################################


##############################################
#
#       D-Pad
#
##############################################

#Right
        axis    6       -1      0       Right
#Left
        axis    6       0       1       Left
#Down
        axis    7       -1      0       Up
#Up
        axis    7       0       1       Down


##############################################
#
#       Left Stick
#
#       Slow Mo Controls
#
##############################################
#Left Analog stick
#Left
        axis   0    -32767  -10000  U
#Right
        axis   0     10000   32767  J
#Down
#       axis   1    -32767  -15000  Down
#Up
#       axis   1     15000   32767  Up
#Button
#       button  7       Enter


##############################################
#
#       Right Stick
#
#
#
##############################################
#Right Analog stick
#Left
#       axis   3    -32767  -10000  U
#Right
#       axis   3     10000   32767  J


#####
#
#  Add 3 ranges to the Up/Down of the stick
#  Used for volume
#  Does about a 10% Jump tick.
#  Hits when moving the stick and when the stick returns to center
#    causing an extra set of presses.  This can be used for finess
#    a smaller push can hit once, a medium 3 or 4, and a full all 6
#
#####
#Down
#       axis   4    -32767  -15000  F10
        axis   4    -20000  -15000  F10
        axis   4    -25000  -20001  F10
        axis   4    -32767  -25001  F10

#Up
#       axis   4     15000   32767  F11
        axis   4     15000   20000  F11
        axis   4     20000   25000  F11
        axis   4     25001   32767  F11

#Button
#       button  8       Enter




######################################################################
#
#       Trigger Configuration  Configuration
#
######################################################################


#Left trigger pull      Rewind (Repeat to speed up)
        axis   2        100     255     <
#Right trigger pull     Fastforward (Repeat to speed up)
        axis   5        100     255     >




######################################################################
#
#       Button Configuration
#
######################################################################


##############################################
#
#       Baseline Buttons
#
##############################################

#Back -=- Escape
        button  16       Escape
#Start Button -=- Pause
        button  8       P

#A Button -=- Enter
        button  0       Enter
#B Button -=- On Screen Menu
        button  1       M
#X Button
#       button  3
#Y Button
#       button  4       E
#Wht Button
#       button  5
#Blk Button
#       button  2






######################################################################
#
#       Function Specific Configuration
#
######################################################################

#####################################
# Edit Mode Controls
#
# Y to Enter/Exit
# Start = Shift
#       Z   = LoadCut
#       Wht = PrevCut
#       Blk = NextCut
#       X   = Transcode
#
#####################################

#Y Button -=- Enter Edit Mode
button  4       E
#Start + Y -=- Load CutpointsHOWTO
chord   8       4       Z
#Start + Blk -=- Jump Next Cutpoint
chord   8       2       PgDown
#Start + White -=- Jump Previous Cutpoint
chord   8       5       PgUp
#Start + X -=- Queue for Transcode
chord   8       3       X

Sample File (Xbox Controller on Xbox)

# ~/.mythtv/joystickmenurc
# Joystick menu config file
#  Place in /media/.mythtv/
#
#   Format:
#       devicename <devname>        Specify name of joystick device to use
#                                   (e.g. /dev/js0)
#       button num keystring        Send 'keystring' when button 'num' is released
#       chord cnum bnum keystring   If button cnum is down, and button 'bnum'
#                                   is released, send keystring
#       axis num from to keystring  If axis num goes into the range of from-to
#                                   send keystring


devicename /dev/input/js0



######################################################################
#
#       Stick/Pad Configuration
#
######################################################################


##############################################
#
#       D-Pad
#
##############################################

#Down
button  11      Down
#Up
button  9       Up
#Down
button 12       Left
#Right
button  10      Right

##############################################
#
#       Left Stick
#
#       Slow Mo Controls
#
##############################################
#Left Analog stick
#Left
        axis   0    -32767  -10000  U
#Right
        axis   0     10000   32767  J
#Down
#       axis   1    -32767  -15000  Down
#Up
#       axis   1     15000   32767  Up
#Button
#       button  7       Enter


##############################################
#
#       Right Stick
#
#
#
##############################################
#Right Analog stick
#Left
#       axis   3    -32767  -10000  U
#Right
#       axis   3     10000   32767  J


#####
#
#  Add 3 ranges to the Up/Down of the stick
#  Used for volume
#  Does about a 10% Jump tick.
#  Hits when moving the stick and when the stick returns to center
#    causing an extra set of presses.  This can be used for finess
#    a smaller push can hit once, a medium 3 or 4, and a full all 6
#
#####
#Down
#       axis   4    -32767  -15000  F10
        axis   4    -20000  -15000  F10
        axis   4    -25000  -20001  F10
        axis   4    -32767  -25001  F10

#Up
#       axis   4     15000   32767  F11
        axis   4     15000   20000  F11
        axis   4     20000   25000  F11
        axis   4     25001   32767  F11

#Button
#       button  8       Enter




######################################################################
#
#       Trigger Configuration  Configuration
#
######################################################################


#Left trigger pull      Rewind (Repeat to speed up)
        axis   2        100     255     <
#Right trigger pull     Fastforward (Repeat to speed up)
        axis   5        100     255     >




######################################################################
#
#       Button Configuration
#
######################################################################


##############################################
#
#       Baseline Buttons
#
##############################################

#Back -=- Escape
        button  13       Escape
#Start Button -=- Pause
        button  6       P

#A Button -=- Enter
        button  0       Enter
#B Button -=- On Screen Menu
        button  1       M
#X Button -=- Display Information
       button  3        I
#Y Button
#       button  4       E
#Wht Button -=- Display Program Finder
       button  5        F6
#Blk Button -=- Display EPG
       button  2        S






######################################################################
#
#       Function Specific Configuration
#
######################################################################

#####################################
# Edit Mode Controls
#
# Y to Enter/Exit
# Start = Shift
#       Z   = LoadCut
#       Wht = PrevCut
#       Blk = NextCut
#       X   = Transcode
#
#####################################

#Y Button -=- Enter Edit Mode
button  4       E
#Start + Y -=- Load CutpointsHOWTO
chord   6       4       Z
#Start + Blk -=- Jump Next Cutpoint
chord   6       2       PgDown
#Start + White -=- Jump Previous Cutpoint
chord   6       5       PgUp
#Start + X -=- Queue for Transcode
chord   6       3       X