Tslib
From OpenTom
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, and an initialised kernel source are needed.
Checking Out and Compiling the Source
The source for tslib is available from the CVS repository of handhelds.org:
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
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. The generic iPaq H3600 seems ok:
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 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

