转载1:
TSLib ported to Android for touchscreen calibration.
Since Android doesn't provide a calibration tool, tslib can be used to calibrate the touchscreen . The values obtained from ts_calibrate in pointercal file can be used in android frameworks/services/java/com/android/server/InputDevice.java to have the correct screen coordinates.
ts_calibrate can be run from a serial console along with android with the proper environment variables set (these variables are documented in Android.mk too), the default values are:
export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CONFFILE=/system/etc/ts.conf
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_PLUGINDIR=/system/lib
export TSLIB_CONSOLEDEVICE=/dev/tty
export TSLIB_FBDEVICE=/dev/graphics/fb0
To compile tslib for your device make a link for bionic/libc/include/fcntl.h to bionic/libc/include/sys/fcntl.h import build/envsetup.sh and execute make or m.
To make tslib build everytime you build your android distribution copy the android-tslib folder to android external/ folder.
Download:
GIT: git clone git://git.linuxconsulting.ro/android-tslib.git
HTTP: http://git.linuxconsulting.ro
转载2:
Android Porting(Touch Screen)
![眨眼 眨眼](http://shared.live.com/HjKMzTS-xzcms40!CabizA/emoticons/smile_wink.gif)
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <linux/input.h>
static int init_device()
{
if((ts_fd = open(TS_DEV, O_RDONLY)) < 0)
{
printf("Error open %s/n", TS_DEV);
return -1;
}
}
{
int i;
return -1;
{
read(ts_fd, &data, sizeof(data));
if (data.type == EV_KEY)
{
printf("type: EV_KEY, event = %s, value = %d/n",
data.code == BTN_TOUCH ? "BTN_TOUCH" : "Unkown", data.value);
}
else if(data.type == EV_ABS)
{
printf("type: EV_ABS, event = %s, value = %d/n",
data.code == ABS_X ? "ABS_X" :
data.code == ABS_Y ? "ABS_Y" :
data.code == ABS_PRESSURE ? "ABS_PRESSURE" :
"Unkown", data.value);
}
else if (data.type == EV_SYN)
{
printf("type: EV_SYN, event = %s, value = %d/n",
data.code == SYN_REPORT ? "SYN_REPORT" : "Unkown", data.value);
}
else
{
}
}
}
![悲伤 悲伤](http://shared.live.com/HjKMzTS-xzcms40!CabizA/emoticons/smile_sad.gif)
samp->x = ( lin->a[2] +
lin->a[0]*xtemp +
lin->a[1]*ytemp ) / lin->a[6];
samp->y = ( lin->a[5] +
lin->a[3]*xtemp +
lin->a[4]*ytemp ) / lin->a[6];
and the lin->a[] is read from the /etc/pointercal. But the division "/" is hard for Linux kernel. Surprised that the a[6] is 65536, and can do the /65536 by >>16.
![大笑 大笑](http://shared.live.com/HjKMzTS-xzcms40!CabizA/emoticons/smile_teeth.gif)
int xraw, yraw, xtmp, ytmp;
"pen down: x=%x:%d, y=%x:%d, pressure=%x:%d/n",
data.x >> 12, data.x & 0xfff, data.y >> 12,
data.y & 0xfff, data.p >> 12, data.p & 0xfff);
xraw = (data.x & 0xfff);
yraw = (data.y & 0xfff);
xtmp = (axis_table[2] + axis_table[0]*xraw + axis_table[1]*yraw )
>> axis_table[6];
ytmp = (axis_table[5] + axis_table[3]*xraw + axis_table[4]*yraw )
>> axis_table[6];
input_report_abs(wm->input_dev, ABS_X, xtmp);
input_report_abs(wm->input_dev, ABS_Y, ytmp);
#else
input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff);
input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff);
#endif
![破碎的心 破碎的心](http://shared.live.com/HjKMzTS-xzcms40!CabizA/emoticons/heart_broken.gif)
if (wm->pen_is_down) {
wm->pen_is_down = 0;
dev_dbg(wm->dev, "pen up/n");
input_report_abs(wm->input_dev, ABS_PRESSURE, 0);
input_report_key(wm->input_dev, BTN_TOUCH, wm->pen_is_down);
input_sync(wm->input_dev);
wm->pen_is_down = 1;
input_report_key(wm->input_dev, BTN_TOUCH, wm->pen_is_down);
input_sync(wm->input_dev);
set_bit(ABS_X, wm->input_dev->absbit);
set_bit(ABS_Y, wm->input_dev->absbit);
set_bit(ABS_PRESSURE, wm->input_dev->absbit);
so, the bit mask should be done for EV_KEY
set_bit(BTN_TOUCH, wm->input_dev->keybit);