Use ts_calibrate to calibrate the touch screen

Source: Internet
Author: User

From http://www.qqread.com/linux/2010/01/u487324.html

The ts_calibrate calibration touch screen provided by the ts_lib package is very simple and practical, but there are two problems in the xsever-based GUI application environment. 1. After calibration, you must restart X for the application to take effect. In this way, the user cannot accept it, because it is time-consuming to start a machine. 2. When the touch screen is calibrated using ts_calibrate.

UseThe ts_calibrate calibration touch screen provided by the ts_lib package is very simple and practical. However, in the xsever-based GUI application environment, there are two problems:

1. After calibration, you must restart X for the application to take effect. In this way, the user cannot accept it, because it is time-consuming to start a machine.

2. InUseWhen the ts_calibrate is used to calibrate the touch screen, you need to touch 5 points. If the GUI application is running another program that responds to the touch event (mouse event), the system will become confused. Therefore, the safe practice should be to perform screen lock operations when the touch screen is calibrated.

Before solving these two problems, let's take a look at the tslib calibration principles. If we have a clear understanding of the principles, the rest will be the problem of method implementation.

Tslib is the Adaptation Layer Between the touch screen driver and the application layer. It obtains the original device coordinate data from the touch screen driver, through a series of operations such as noise reduction, deshake, and coordinate transformation, to remove noise and convert the original device coordinates to the corresponding screen coordinates. Use tslib/src/tslib. the H file shows that two main interfaces ts_open (), ts_close (), ts_read (), and ts_read_raw () are provided for the application layer in tslib, where ts_read () is the normal interface, and ts_read_raw () is the calibrationUse. The default ts. conf file of tslib contains the following basic plug-ins:

Pthres is the touch screen sensitivity threshold plug-in provided by tslib;

Variance is the touch screen filtering algorithm plug-in provided by tslib;

Dejitter is the touch screen Noise Removal Algorithm plug-in provided by tslib;

Linear is the touch screen Coordinate Transformation plug-in provided by tslib.

The process for tslib to process the device coordinates sampled from the touch screen driver and then supply them to the application end is as follows:

Raw device --> variance --> dejitter --> linear --> Application

Module module Module

Let's take a look at what ts_calibrate does. In the case of calibration, tslib processes the data sampled by the driver as follows:

1. Read the coordinates (top left, top right, bottom left, bottom right, center) of the five points on the screen. Perform a series of transformations and sample the five points, it actually contains three different x values and three different y values. And the scaling value have a total of 7 values, and are saved to/etc/pointercal together.

2. This/etc/pointercal file is mainly used by the linear plug-in. Each touch operation performed multiple touch coordinate transformations.

Now we have found a general solution to the problem. After the touch screen is calibrated, the linear plug-in only needs to promptly read the new/etc/pointeracal file, so that the coordinates of the new calibration are updated to the upper-layer application in a timely manner. The specific implementation issues should be considered below.

1. From the linear. c file, we can see that the/etc/pointercal file was read during the module initialization. You only need to read the new/etc/pointercal file in linear_read.

2. After calibration, a new pointercal file is saved, but how does ts_lib know that the current pointercal file is the new file to be read. At the beginning, we were in linear. in the linear_read () function of C, the last update time of the/etc/poinercal file is checked by counting round robin. If the current update time is later than the last update time, the pointercal file is read. For the time being, we will not say that the RTC time of a new assembly line machine is uncertain. If we compare the time, an error will occur. In addition, the always-round method and the ts_lib sampling interval value are very small. In this way, the system resources are obviously consumed when the touch screen is usually operated by the user.

3. At this point, the thought is process communication. ts_lib is a dynamic library running in the system. It does not exist in the system as a process, but it can take a compromise, save the Process Code that calls ts_lib (actually the Process Code of X) to a configuration file. In this way, after the touch screen is calibrated using ts_calibrate, the User-Defined signal is sent to ts_lib using the signal method. A simple signal processing function is added to lineral. C of ts_lib. After receiving the signal, read the new pointercal file. Normally, no Round Robin or read operations are performed.

The three steps above completely solve the problem that the application touch takes effect immediately after calibration. Another secondary issue is how to lock the screen? This requires starting with the kernel. Check linux2.6 kernel/Drivers/input/evdev. C. From the ioctl provided by the driver, you can see that eviocgrab is provided for evdev-based input devices. As the name suggests, grab captures the current input operation to the current operation, so that all applications outside the current operation cannot read the touch screen operation. The source code of the driver makes it easy to know how to unlock the lock screen. The source code is as follows:

Truct tsdev * ts;

Char * tsdevice = "/dev/input/event0 ";

TS = ts_open (tsdevice, 0 );

Int ts_tmpfd = ts_fd (TS );

If (ts_tmpfd =-1)

{

Perror ("ts_open ");

Exit (1 );

}

Unsigned long Val = 1;

Int ioctl_ret = IOCTL (ts_tmpfd, eviocgrab, & Val );

Printf ("Now lock the ts ioctl ret is: % d \ n", ioctl_ret );

If (ioctl_ret! = 0)

{

Printf ("error: % s \ n", strerror (errno ));

Exit (1 );

}

Printf ("lock the TS success \ n ");

Original address http://blog.chinaunix.net/u3/94694/showart_1915009.html

Additional reading:Install touch screen for Linux

Gnome/Nautilus, openwindows, wine, and so on-many guis allow users to simplify the access and use of powerful Linux applications. What components can we add here to make Linux more stable to the consumer device field? The answer is the touch screen. With touch screen, Linux programs can become controllers of many devices.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.