Qt tslib校准程序

在电阻式的触摸屏上开发嵌入式应用时,Qt+tslib的组合很常见,可谓经典组合。tslib库中提供了一些测试程序,比如ts_calibrate,ts_test,可以用来对触摸屏进行校准,测试。在Qt中也提供了一个例程,也是用来触屏校准的(http://doc.qt.io/qt-4.8/qt-qws-mousecalibration-calibration-cpp.html) ,Qt库中把触摸屏模拟成鼠标设备来实现,我试了这种方法,发现校准后在/etc/pointercal产生的数据不大对,和ts_calibrate程序产生的数据相差很大,校准后触屏无法正常使用,而且用鼠标点点点也能触发校准完成。由于我的项目应用中是鼠标和触屏混用的,这种校准方式不可取,于是就想到了利用tslib库中的方法,来实现Qt上的触摸屏校准应用。
首先分下下tslib库中的test/ts_calibrate.c程序,去除显示部分(显示校准点十字框),代码如下。

typedef struct {
   
	int x[5], xfb[5];
	int y[5], yfb[5];
	int a[7];
} calibration;


int perform_calibration(calibration *cal) {
   
	int j;
	float n, x, y, x2, y2, xy, z, zx, zy;
	float det, a, b, c, e, f, i;
	float scaling = 65536.0;
	...
}

static void get_sample (struct tsdev *ts, calibration *cal,
			int index, int x, int y, char *name)
{
   
	...
	put_cross(x, y, 2 | XORMODE);
	...
	getxy (ts, &cal->x [index], &cal->y [index]);
	cal->xfb [index] = x;
	cal->yfb [index] = y;
}

int main()
{
   
	struct tsdev *ts;	calibration cal;
	int cal_fd;			char cal_buffer[256];
	char *tsdevice = NULL;	char *calfile = NULL;

	if( (tsdevice = getenv("TSLIB_TSDEVICE")) != NULL ) {
   
		ts = ts_open(tsdevice,0);
	} else {
   
		...
	}

	if (ts_config(ts)) {
   
		perror("ts_config");
		exit(1);
	}

	get_sample (ts, &cal, 0, 50,        50,        "Top left");
	get_sample (ts, &cal, 1, xres - 50, 50,        "Top right");
	get_sample (ts, &cal, 2, xres - 50, yres - 50, "Bot right");
	get_sample (ts, &cal, 3, 50,        yres - 50, "Bot left");
	get_sample (ts, &cal, 4, xres / 2,  yres / 2,  "Center");

	if (perform_calibration (&cal)) {
   
	
		if ((calfile = getenv(
  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值