Tslib
Contents |
tslib
tslib is a linux library for initialising and reading data from a range of touchscreen devices, using standard methods. Amongst other things, it can also be used to filter and smooth the data if required. As it was originally developed for use with PDA's such as the iPaq, there should be no reason it can't be used a TomTom. The main reason for doing so being that it can be used by libSDL to provide "mouse" data to SDL based applications.
Requirements
It is not essential, but before building any libraries or applications, particularly when cross-compiling, I recommend setting up a development environment with a common install directory. A suggestion of such a development environment can be found here. Instructions hereafter are based on the setup described in this link.
In particular, a working compilation toolchain (including autoconf and libtool), and an initialised kernel source are needed.
Checking Out and Compiling the Source
The source for tslib was available from the CVS repository of handhelds.org. It is now available from github as a ZIP. The following CVS instructions are no longer necessary.
cd $TT_SOURCE cvs -d :pserver:anoncvs@cvs.handhelds.org:/cvs login
When prompted, enter the password "anoncvs" to continue.
cvs checkout -d tslib apps/tslib
cd tslib
./autogen.sh
echo "ac_cv_func_malloc_0_nonnull=yes" > arm-linux.site
./configure --prefix=$TT_INSTALLDIR --sysconfdir=$TT_CONFIGDIR --host=arm-linux --target=arm-linux CPPFLAGS="-I${TT_LINUXINCLUDEDIR}" CONFIG_SITE=arm-linux.site
make
If you get a "previous declaration of __kernel_dev_t" error, this is because of conflicting include files. This can be resolved by removing the CPPFLAGS directive from the configure arguments.
When using a newer version of tslib (available at berlios), you may get the following error:
input-raw.c: In function `check_fd': input-raw.c:120: error: `EVIOCGRAB' undeclared (first use in this function) input-raw.c:120: error: (Each undeclared identifier is reported only once input-raw.c:120: error: for each function it appears in.) input-raw.c: In function `ts_input_fini': input-raw.c:285: error: `EVIOCGRAB' undeclared (first use in this function) input-raw.c: In function `mod_init': input-raw.c:329: warning: unused parameter `dev' make[2]: *** [input-raw.lo] Error 1
This is because the kernel headers in the TomTom toolchain predate the addition of EVIOCGRAB. The fix is to add #ifdef EVIOCGRAB statements around the 2 constructs using EVIOCGRAB.
Configuring and Installing
tslib requires a "module_raw" value to be set in its config file. It is easier to update the file before it is installed. For older TomTom units with input readable from /dev/ts, the generic iPaq H3600 seems ok. From the TT root directory, run the following commands.
rm etc/ts.conf cat > etc/ts.conf << "EOF" module_raw h3600 module pthres pmin=1 module variance delta=30 module dejitter delta=100 module linear EOF
and then from the tslib usource directory
make install
Newer hardware versions as noted in Hardware Touchscreen have /dev/input/event0 rather than /dev/ts as the touchscreen device and have different driver requirements. The concordant commands to create the ts.conf file and install would be as follows in this case.
rm etc/ts.conf cat > etc/ts.conf << "EOF" module_raw input module pthres pmin=1 module variance delta=30 module dejitter delta=100 module linear EOF
and then
make install
Using tslib
When using tslib, a number of environmental variables must be set on the TomTom. These can be added to the start of a script which executes the desired application, such as ts_calibrate and ts_test. Values I have used are as follows:
export ROOT_DIR=/mnt/sdcard/root export TSLIB_CONSOLEDEVICE=none export TSLIB_FBDEVICE=/dev/fb export TSLIB_TSDEVICE=/dev/ts export TSLIB_CALIBFILE=$ROOT_DIR/etc/pointercal export TSLIB_CONFFILE=$ROOT_DIR/etc/ts.conf export TSLIB_PLUGINDIR=$ROOT_DIR/usr/lib/ts
The LD_LIBRARY_PATH must also be set to allow the runtime loading of tslib. An example shell script to run the calibration and then test applications would look like this:
#!/bin/sh export ROOT_DIR=/mnt/sdcard/root export TSLIB_CONSOLEDEVICE=none export TSLIB_FBDEVICE=/dev/fb export TSLIB_TSDEVICE=/dev/ts export TSLIB_CALIBFILE=$ROOT_DIR/etc/pointercal export TSLIB_CONFFILE=$ROOT_DIR/etc/ts.conf export TSLIB_PLUGINDIR=$ROOT_DIR/usr/lib/ts export PATH=$ROOT_DIR/usr/bin:$PATH export LD_LIBRARY_PATH=$ROOT_DIR/usr/lib export LOGFILE=$ROOT_DIR/tsliblog.txt cd $ROOT_DIR echo "==============" >> $LOGFILE echo "Starting tslib" >> $LOGFILE #echo "Running ts_calibrate..." >> $LOGFILE #ts_calibrate 2>&1 >> $LOGFILE #echo "done." >> $LOGFILE echo "Running ts_test..." >> $LOGFILE ts_test 2>&1 >> $LOGFILE echo "done." >> $LOGFILE echo "Exiting..." >> $LOGFILE
Since I don't currently have access to a console on my 910, I dump as much output to log files as possible for debugging purposes.
Executing the ts_configure app should result in a black screen with tslib text in the centre, and a calibration square. On my 910, the resulting logged output is as follows:
xres = 480, yres = 272 Took 127 samples... Top left : X = 57 Y = 52 Took 127 samples... Top right : X = 435 Y = 52 Took 127 samples... Bot right : X = 435 Y = 227 Took 127 samples... Bot left : X = 53 Y = 225 Took 127 samples... Center : X = 245 Y = 140 -6.576660 0.999942 0.011427 -0.947144 -0.002615 0.988418 Calibration constants: -431008 65532 748 -62072 -171 64776 65536
The calibration data is also written to the file specified by TSLIB_CALIBFILE. To eliminate the need to run ts_calibration every time before using tslib, copy this file to the local root directory.
cp $TT_TARGETDIR/etc/pointercal $TT_ROOT/etc