在上一篇文章中提到的方式之后,我发现这不是我想要的。非常纠结。为什么它不能被使用?usb接口触屏呢?
我用的是15寸触摸屏,10寸屏用的时候没问题。15英寸完全废弃,我用示波器测试,因为芯片支持触摸屏接口,所以触摸屏直接连接到芯片上。但芯片的电压是3.3v是的,我觉得是因为电压太低,不足以满足15寸的电阻屏,个人愚见。若有仁兄仁姐实现,弟弟求教。后来想自己修改tslib来适应usb接口的电阻屏看了好几天tslib在我看来,源代码是可以实现的。如果什么都不改,直接改变环境变量
<span style="white-space:pre"> </span>export QWS_MOUSE_PROTO="LinuxInput:/dev/input/event2
这样,就会提示
selected device is not a touchscreen I understand。在网上发现问题的关键是在tslib有以下代码:
<span style="color:#666666;">if (! ((ioctl(ts->fd, EVIOCGVERSION, &version) >= 0) && (version == </span><span style="color:#ff0000;">EV_VERSION</span><span style="color:#666666;">) && (ioctl(ts->fd, EVIOCGBIT(0, sizeof(bit) * 8), &bit) >= 0) && (bit & (1 << EV_ABS)) && (ioctl(ts->fd, EVIOCGBIT(EV_ABS, sizeof(absbit) * 8), &absbit) >= 0) && (absbit & (1 << ABS_X)) && (absbit & (1 << ABS_Y)) && (absbit & (1 << ABS_PRESSURE)))) { fprintf(stderr, "selected device is not a touchscreen I understand\n"); return -1; }</span>
红色部分是原因之一,需要修改编译器中的宏定义
#define EV_VERSION 0x010001 改成#define EV_VERSION 0x010000。
void QWSCalibratedMouseHandler::calibrate(const QWSPointerCalibrationData *data) { // Algorithm derived from // "How To Calibrate Touch Screens" by Carlos E. Vidales, // printed in Embedded Systems Programming, Vol. 15 no 6, June 2002 // URL: http://www.embedded.com/showArticle.jhtml?articleID=9900629 const QPoint pd0 = data->devPoints[QWSPointerCalibrationData::TopLeft]; const QPoint pd1 = data->devPoints[QWSPointerCalibrationData::TopRight]; const QPoint pd2 = data->devPoints[QWSPointerCalibrationData::BottomRight]; const QPoint p0 = data->screenPoints[QWSPointerCalibrationData::TopLeft]; const QPoint p1 = data->screenPoints[QWSPointerCalibrationData::TopRight]; const QPoint p2 = data->screenPoints[QWSPointerCalibrationData::BottomRight]; const qint64 xd0 = pd0.x(); const qint64 xd1 = pd1.x(); const qint64 xd2 = pd2.x(); const qint64 yd0 = pd0.y(); const qint64 yd1 = pd1.y(); const qint64 yd2 = pd2.y(); const qint64 x0 = p0.x(); const qint64 x1 = p1.x(); const qint64 x2 = p2.x(); const qint64 y0 = p0.y(); const qint64 y1 = p1.y(); const qint64 y2 = p2.y(); qint64 scale = ((xd0 - xd2)*(yd1 - yd2) - (xd1 - xd2)*(yd0 - yd2)); int shift = 0; qint64 absScale = qAbs(scale); // use maximum 16 bit precision to reduce risk of integer overflow if (absScale > (1 << 16)) { shift = ilog2(absScale >> 16) 1; scale >>= shift; } s = scale; a = ((x0 -x2)*(yd1 - yd2) - (x1 - x2)*(yd0 - yd2)) >> shift;
b = ((xd0 - xd2)*(x1 - x2) - (x0 - x2)*(xd1 - xd2)) >> shift;
c = (yd0*(xd2*x1 - xd1*x2) + yd1*(xd0*x2 - xd2*x0) + yd2*(xd1*x0 - xd0*x1)) >> shift;
d = ((y0 - y2)*(yd1 - yd2) - (y1 - y2)*(yd0 - yd2)) >> shift;
e = ((xd0 - xd2)*(y1 - y2) - (y0 - y2)*(xd1 - xd2)) >> shift;
f = (yd0*(xd2*y1 - xd1*y2) + yd1*(xd0*y2 - xd2*y0) + yd2*(xd1*y0 - xd0*y1)) >> shift;
<p> writeCalibration();</p>}
这个东西QWSPointerCalibrationData,里面只定义了两个数组,devPoint和screenPoint,这个是我不太懂的地方,devPoint是代表触摸屏上面的点,screenPoing代表的是显示器上面的点。这是通过mousecalibration这个软件的源代码推出来的。
对于calibrate只需要显示器和触摸屏上面,左上、右上和右下几个点就可以了。看着很简单。但是我通过自己设置一些调试信息,发现进入软件后,按触摸屏的中心点靠右和靠下的部分,分别是(799,*)和(*,599),而如果触摸右下角部分就直接是(799,599)。不知道是什么原因,我猜想可能是内核传递上来的数据,对于Qt的QWSserver来说太大了。才出现这样的问题,具体还没找到原因。所以屏幕还不是特别好用。如果有明白的仁兄仁姐,请不吝赐教。以上仅做参考,欢迎交流讨论。