Hardware Touchscreen
From OpenTom
Contents |
[edit]
General
- see Hello world example
- The touch screen must be calibrated if you replace ttn (which does calibration for you). The calibration data is stored in flash memory, and can be accessed (on OpenTom 0.0.2) by reading the file /mnt/flash/sysfile/cal .
- The touch screen is available on character device 254:0 (should be /dev/ts)
[edit]
Calibration
Here is an exemple for the TomTom One. For other models, it may be necessary to swap horizontal and vertical calibration data.
static MATRIX cal_data;
ioctl(tsfd,TS_GET_CAL,&cal_data);
// Read calibration data in flash memory
FILE * cal_file = fopen ("/mnt/flash/sysfile/cal","rb");
if ((cal_file == NULL) || (fread (&cal_data.xMin, sizeof(int), 4, cal_file) != 4))
{
perror ("Reading calibration file");
exit (1);
}
fclose (cal_file);
ioctl(tsfd,TS_SET_CAL,&cal_data);
ioctl(tsfd,TS_SET_RAW_OFF,NULL);
[edit]
Using the touch screen
Try something like this (written freehand, maybe contains small errors):
// Event struct TS_EVENT ev;
// Open the device
int ts = open("/dev/ts", O_RDONLY | O_NONBLOCK);
// Read a dataset, store it in ev
if ( read(ts,&ev,sizeof(TS_EVENT)) == sizeof(TS_EVENT) ) {
...
}
// Better flush the device, otherwise TTs navigation software would use waiting data
while ( read(ts,&ev,sizeof(TS_EVENT)) == sizeof(TS_EVENT) ) {}
// Clean up... close(ts);
TS_EVENT can be found in barcelona/Barc_ts.h and looks like this:
typedef struct {
short pressure; // 255 -> pressed, 0 -> released
short x;
short y;
short pad;
} TS_EVENT;
Also check Tslib.
[edit]
Future
Check if device /dev/input/event0 provides raw "input_event"s, convertible from raw using routines similar to these found in the toolchain-kernel-diff (see tomtom.com/gpl) using calibration-data from /mnt/flash/sysfile/cal.

