linux 触摸屏校准
时间: 2023-12-19 08:31:32 浏览: 55
以下是两种Linux触摸屏校准的方法:
1. 使用tslib编写触摸屏校准程序
如果你使用的是嵌入式Linux系统,并且已经安装了QT5.6版本和tslib库,你可以编写一个触摸屏校准程序。以下是一个示例程序:
```c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>
#include <tslib.h>
#define DEVICE_NAME "/dev/input/event0"
#define CALIBRATION_FILE "/etc/pointercal"
int main(int argc, char *argv[])
{
struct tsdev *ts;
struct ts_sample samp[5];
int fd, i;
struct ts_sample *calib;
struct ts_sample *calib_result;
int xres, yres;
ts = ts_open(DEVICE_NAME, 0);
if (!ts) {
perror("ts_open");
exit(1);
}
if (ts_config(ts)) {
perror("ts_config");
exit(1);
}
calib = malloc(sizeof(struct ts_sample) * 5);
calib_result = malloc(sizeof(struct ts_sample) * 5);
printf("Please touch the screen at the center of the cross.\n");
for (i = 0; i < 5; i++) {
ts_read(ts, &samp[i], 1);
calib[i] = samp[i];
}
calib_result[2].x = xres / 2;
calib_result[2].y = yres / 2;
printf("Please touch the screen at the top-left corner of the screen.\n"); for (i = 0; i < 5; i++) {
ts_read(ts, &samp[i], 1);
calib[i].x = samp[i].x;
calib[i].y = samp[i].y;
}
calib_result[0].x = 0;
calib_result[0].y = 0;
printf("Please touch the screen at the bottom-right corner of the screen.\n");
for (i = 0; i < 5; i++) {
ts_read(ts, &samp[i], 1);
calib[i].x = samp[i].x;
calib[i].y = samp[i].y;
}
calib_result[4].x = xres - 1;
calib_result[4].y = yres - 1;
printf("Please touch the screen at the top-right corner of the screen.\n");
for (i = 0; i < 5; i++) {
ts_read(ts, &samp[i], 1);
calib[i].x = samp[i].x;
calib[i].y = samp[i].y;
}
calib_result[1].x = xres - 1;
calib_result[1].y = 0;
printf("Please touch the screen at the bottom-left corner of the screen.\n");
for (i = 0; i < 5; i++) {
ts_read(ts, &samp[i], 1);
calib[i].x = samp[i].x;
calib[i].y = samp[i].y;
}
calib_result[3].x = 0;
calib_result[3].y = yres - 1;
ts_close(ts);
fd = open(CALIBRATION_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) {
perror("open");
exit(1);
}
dprintf(fd, "%d %d %d %d %d %d %d %d %d\n",
calib_result[0].x, calib_result[0].y,
calib_result[1].x, calib_result[1].y,
calib_result[2].x, calib_result[2].y,
calib_result[3].x, calib_result[3].y,
calib_result[4].x, calib_result[4].y);
close(fd);
printf("Calibration data saved to %s.\n", CALIBRATION_FILE);
return 0;
}
```
2. 使用xinput_calibrator命令行工具校准触摸设备
如果你使用的是Linux桌面系统,你可以使用xinput_calibrator命令行工具校准触摸设备。以下是一个示例命令:
```
xinput_calibrator -v --device <device name or id>
```
其中,`<device name or id>`是你要校准的触摸设备的名称或ID。你可以使用`xinput list`命令查看所有输入设备的列表。