Support this project:
or send me something from my Amazon wishlist.

Using the Cetexx CX-T100 touchscreen under Linux

I recently bought some computer parts for a Linux/emc driven milling machine. One of the parts is a Cetexx CX-T100, a 8" color TFT screen with a resultion of 800x600 pixel (SVGA). But the really nice part is the built in touchscreen. With this i would be able to control major parts of the machine without keyboard. This screen is advertised for car PCs, but it includes a 220V power supply to operate it stationary.

Included drivers

The device came with a driver CD which was an unlabeled CDR with just some weird named (just four questionmarks) folder in the root directory. I was expecting this to be some linux issue so i put the disc into a windows PC where the folder was displayed as four squares ... perhaps some asian font issue or so. The folder was browsable anyway and i was surprised to even find some linux related files. The disk also contains the windows drivers which didn't work out of the box and needed some manual installation to work on my Windows XP test machine ... but that's a different story ...

But my main interest was Linux, namely the Ubuntu 6.06 Dapper that's the basis of the machining software i was going to use. So i was pleased to find some drivers there. Unfortunately some closer investigation soon made it obvious that these were outdated closed source drivers that didn't even fit into the concepts of a current linux input system. So these drivers were quite useless.

Just plugging it in

As the first step i just plugged the USB connection of the display into my linux box. I did this in order to get USB vendor and product details to start a search in the internet. What i didn't expect was that the linux actually began to react on the touchscreen. The x and y axes were swapped and one was even reversed and it behaved more like a mouse than a touchscreen. But it worked and i was hoping that it was just a matter of a few adjustements here and there to get it working correctly. But it wasn't that simple.

The fact that the linux treats the device like mouse is a problem as a touchscreen just isn't a mouse. Even if the axis and direction problems were solved this would still be a problem as a mouse is a relative device. This means that you can repeatedly do the same movement with the mouse and the mouse coursor will be advanced over the screen just a bit further with every step. Notebook touchpads also work like that. A touchscreen instead is an abolute device. You want the mouse jump where you touch the screen. If you move the finger you want it to follow, but if you lift the finger and touch the screen at a different location you want the cursor to move there. A mouse/touchpad doesn't work like that.

Step 1: Avoiding a mouse like service

So my first job was to prevent the mouse drivers to attach to the touchscreen. For the xorg xwindow system used by recent linux distros this can be done in the file /etc/X11/xorg.conf. Be aware that you need to be root in order to modify this file. The same is true for most of the other commands following. If you do not intend to use a real mouse in parallel you can just remove all mouse related parts from /etc/X11/xorg.conf. If you want to use a real mouse in parallel things get a little more complicated.

Linux uses several system device entries for its mouse handling. There are e.g. the hardware specific devices like /dev/psaux for the ps2 mice. But there's also more abstract devices /dev/input/mouseX used mice of any hardware type. And there's even a device collecting everything that's mouse related and providing all mouse events through the single /dev/input/mice device. This is usually used in /etc/X11/xorg.conf to control the mouse cursor by any mouse like device attached. Infortunately this is not what we want. But all mice also have a seperate entry in /dev/input/mouseX. The easiest solution is to figure out which of the plenty /dev/input/mouseX belongs to your mouse and use that instead of /dev/input/mice. The only problem is to figure out which of these devices the mouse is using. To find this out type cat /proc/bus/input/devices. The result may include something like this:

I: Bus=0003 Vendor=05e3 Product=1205 Version=0242
N: Name="USB Mouse"
P: Phys=usb-0000:00:1d.0-1/input0
S: Sysfs=/class/input/input2
H: Handlers=mouse1 event2 ts1
B: EV=7
B: KEY=70000 0 0 0 0 0 0 0 0
B: REL=103

In the H: line are you being told that your mouse is using the handler mouse1 which means that you can use /dev/input/mouse1 in /etc/X11/xorg.conf. Try it!

But here's a problem: The handlers are assigned following no fixed scheme and with USB the order of detection may vary and sure will if you start plugging and unplugging devices. If you are using a recent linux distro using the udev device system there's a solution for this: You can force udev to create special handlers for a device.

Create a file /etc/udev/rules.d/69-touchscreen.rules (we use that name as we'll later add more touchscreen related entries to this) and add the following line.

KERNEL=="mouse*", SUBSYSTEM=="input", SYSFS{idVendor}=="05e3", SYSFS{idProduct}=="1205", SYMLINK+="input/mouse"

This will force the above mouse to get an additional handler entry named /dev/input/mouse. Note the matching product and vendor ids. You have to adjust them to the values of your mouse! To test this type cat /dev/input/mouse. Whenever you move the mouse, some garbage characters should be printed to the screen. On the other hand, touching the screen should not cause any output. You can now use the new /dev/input/mouse in /etc/X11/xorg.conf without caring for the order of device detection and the mouse cursor should not react on the touchscreen anymore.

So the first hurdle is taken, the touchscreen doesn't work at all anymore :-)

Step 2: Redirecting the touchscreen events

Now that we've prevented the touchscreen from interfering with the mouse, we'll need another access to the touchscreen. The first step is quite similar to the one we've just done with the mouse. Adding the following line to /etc/udev/rules.d/69-touchscreen.rules will redirct the touchscreen events to /dev/input/evtouch_event:

KERNEL=="event*", SUBSYSTEM=="input", SYSFS{idVendor}=="0eef", SYSFS{idProduct}=="0001", SYMLINK+="input/evtouch_event"

Only the touchscreen events are redirected to /dev/input/evtouch_event. You can test this with the command cat /dev/input/evtouch_event. This should write some garbage characters onto the screen whenever you touch the touchscreen. Moving the mouse should not generate any output.

Step 3: Installing Xorg touchscreen drivers for

In the next step we'll have to make xorg use the touchscreen driver and make the CX-T100 attach to it. Touchscreen drivers are usually not a part of standard Xorg installations. But they are available in the internet e.g. here. You'll have to download the correct version of the evtouch driver. E.g. Ubuntu 6.06 (the version EMC is built upon) requires evtouch-0.8.0. If in doubt you can just try different versions and take a look at /var/log/Xorg.0.log after restarting the X server and trying to load that driver. If you find a line like

(EE) Failed to load /usr/lib/xorg/modules/input/evtouch_drv.so

then the driver wasn't loaded and you should try a different version. To install the driver just untar it and copy it to the Xorg installation:

cp evtouch-0.8.0/evtouch_drv.o /usr/lib/xorg/modules/input/evtouch_drv.so

Note that i rename the file to evtouch_drv.so. This is only necessary with the old 0.8.0 version. The newer version are already named correctly.

Copying the driver to that position is only the first step. We'll also have to make xorg use that driver. This is accomplished by adding the following section to /etc/X11/xorg.conf, it makes use of the /dev/input/evtouch_event entry:

Section "InputDevice"
        Identifier "touchscreen"
        Driver "evtouch"
        Option "Device" "/dev/input/evtouch_event"
        Option "DeviceName" "touchscreen"
        Option "MinX" "32"
        Option "MinY" "84"
        Option "MaxX" "1899"
        Option "MaxY" "1921"
        Option "ReportingMode" "Raw"
        Option "Rotate" "cw"
        Option "SwapX" "true"
EndSection

An addional entry in the Section "ServerLayout" is required to actually use the section above:

       InputDevice     "touchscreen" "SendCoreEvents"

The above section also controls the touchpads axes and the options "Rotate" and "SwapX" make sure that the axes are used correctly and that they work in the correct direction. These settings are for the CX-T100 and may not work with different displays and touchscreens. If the touchscreen now works satisfying for you, you are done!

Step 4: Calibration

You might face the fact, that the mouse cursor does not move to exactly the position you are touching on the screen. If this is the case your setup needs calibration. The evtouch drivers contain some calibration tools and scripts which i found a little bit uncomfortable to use. Instead i found this little source code of unknown origin in the net. This is easily compiled using the following command:

gcc -o calibrator calibrator.c -lX11

Just run the resulting executable on the touchscreens event handler by typing:

./calibrator /dev/input/evtouch_event
Touch the screen as requested by that tool and use the values printed in the xorg.conf file for the min and max values.

Files

Links