[Home]Using X11 Joystick Driver

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

It is possible to use X11 joystick driver to redirect joypad events into axis as hot keys. Unfortunately, xserver in Hurdy Heron (Ubuntu 8.04) has a bug, preventing use of multiaxis devices, including joypads. So, first try easy way in hope that xserver is fixed. 1. Install joystick driver package:
apt-get install xserver-xorg-input-joystick
2. Add joystick section into your /etc/X11/xorg.conf file (read 'man joystick' for more information):
Section "InputDevice"
	Identifier      "joystick"
	Driver		"joystick"
# proper path to your joypad could be found by looking into '/dev/input/by-id' directory
	Option "Device"		"/dev/input/event2"
# axis -X
	Option "MapButton1"	"key=Left"
# axis -Y
	Option "MapButton2"	"key=Down"
# axis +X
        Option "MapButton3"	"key=Right"
# axis +Y
	Option "MapButton4"	"key=Up"
# axis "step program"
	Option "MapButton5"	"key=t"
# axis "continus program"
	Option "MapButton7"	"key=s"
# axis -Z
	Option "MapButton6"	"key=Prior"
# axis +Z
	Option "MapButton8"	"key=Next"
# axis "continuos jogging"
	Option "MapButton9"	"key=c"
# axis "zero G54 offset on selected axis"
	Option "MapButton10"	"key=Shift_L,Home"
# axis "change jogging speed"
	Option "MapAxis1"	"mode=accelerated keylow=comma keyhigh=period"
# axis "change jogging step"
	Option "MapAxis2"	"mode=accelerated keylow=i, keyhigh=Shift_L,i"
3. Add new device to "ServerLayout?" section (if your xorg.conf file does not have it, just create it)
Section "ServerLayout"
	InputDevice "joystick" "SendCoreEvents"
4. save xorg.conf and do a restart of X server (Ctrl-Alt-Backspace is fastest way to do this). Then X come back again try to press any side of the pad. If you see some symbols being printed you are all set, but if the server crashes, you need to continue reading and typing some more.

5. Get source and build dependencies for xserver:

apt-get source xserver-xorg-core
apt-get build-dep xserver-xorg-core
6a. Edit the source of the Xserver: cd xorg-server-* if you still have some luck left, this patch will apply: save following fragment into file, and feed it to patch command:
patch -p1 -i filename:
commit 333e7123dc484888d79c0f5aa3977bd72f1eb341
Author: Adam Jackson <ajax@redhat.com>
Date:   Tue Mar 25 12:48:22 2008 -0400

    Fix that last commit.
    I can apply patches, really.

diff --git a/dix/getevents.c b/dix/getevents.c
index 6a2f7ba..bf9331e 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -349,7 +349,7 @@ getValuatorEvents(xEvent *events, DeviceIntPtr pDev, int first_valuator,
     for (i = first_valuator; i < final_valuator; i += 6, xv++, events++) {
         xv->type = DeviceValuator;
         xv->first_valuator = i;
-        xv->num_valuators = ((num_valuators - i) > 6) ? 6 : (final_valuator - i);
+        xv->num_valuators = ((final_valuator - i) > 6) ? 6 : (final_valuator - i);
         xv->deviceid = pDev->id;
         switch (final_valuator - i) {
         case 6:

6b. if the above didn't work, you need to make changes manually:

gedit dix/getevents.c
change to line 352, you should appear in the middle of the for(...) statement, looking almost like one above. All you need to do is to replace all 'num_valuators' to 'final_valuator' on the right side of equation and save the file.

7. Build a new xserver package:

dpkg-buildpackage -uc -nc 
8. Install it:
cd ..
dpkg -i xserver-xorg-core_1.4.1*.deb
9. restart X server once again (Ctrl-Alt-Backspace, remember?) and hopefully, now it will work.

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited February 22, 2009 1:54 pm by Aystarik (diff)
Published under a Creative Commons License