From the perspective of the correction method,
Android
System touch screen calibration is generally divided into two types: Linear Calibration and three-point (usually five points) calibration; from the calibration position, there are also two types, the driving layer calibration and
Android
Layer calibration. Generally speaking
Android
Layer correction works with Application Software
Android
Layers are complete, with high flexibility and intelligence. Correction is not allowed at any time. Here, we will introduce in detail
Android
Layer correction process.
In order to better understand the detailed correction process, it is necessary to understand the motion process of touch screen data, at least the principle of correction, which is not mentioned in this report because of the specific algorithms involved.
Touch screen data is generated
Linux
In the touch screen driver
Ad
Converts a touch point into a group of data (touch screen coordinates). This data is called raw data. This raw data is very important. After all, our goal is to convert a group of touch screen coordinates
LCD
Coordinates. After raw data is generated
Input_report_abs
Report on
Android
Layer. In
Android
The layer will pass
Getx
And
Gety
Capture this data, and then pass the captured data through
Reportdata
Distribute to the window.
From the data movement process, we probably know where to start with correction. The correction process is data interception.
-
Modification Process. This is because
Android
Therefore, we need
Android
Layer data is intercepted.
Android
The data of the layer touch screen is
/Frameworks/base/services/Java/COM/Android/Server/
Files in the directory
Inputdevice. Java
So you need to add some code in this file to intercept the original data and correct the original data.
At this point, we have always had a major premise:
1
,
Linux
The driver layer reports raw data;
2
The correction coefficient for the original data has been generated. Therefore
Inputdevice. Java
Before adding the code, we should solve these two problems.
The correction process is completed in four steps:
1
Touch screen driver Modification
For the first question, we need
Linux
The Touch Screen driver of the layer is modified to ensure
Report
Is the original data that has not been modified.
If you are using an over-corrected touch screen driver, you need to note the following two changes:
The first part is:
If (xtmp <0) Xtmp = 0;
Else if (xtmp> TS_RESOLUTION_X-1)
Xtmp = TS_RESOLUTION_X-1;
If (ytmp <0)
Ytmp = 0;
Else if (ytmp> TS_RESOLUTION_Y-1)
Ytmp = TS_RESOLUTION_Y-1;
|
The above code needs to be commented out. The result is that the touch screen will not respond no matter how you click the touch screen when you are on time. Take a closer look at this piece of code and you will know that this piece of code ensures that the reported data is
LCD
Within the range of coordinates, this is a piece of code that must be written in the driver layer correction, but it is the binding stone for our software correction.
The second is
_ Init initi_ts_probe
A piece of code in:
If (maid-> resol_bit = 12 ){ Input_set_abs_params (ts-> Dev, abs_x, 0, ts_resolution_x, 0, 0 );
Input_set_abs_params (ts-> Dev, abs_y, 0, ts_resolution_y, 0, 0 );
}
|
You need to modify it as follows :()
If (maid-> resol_bit = 12 ){ Input_set_abs_params (ts-> Dev, abs_x, 0, 0 xfff , 0, 0 );
Input_set_abs_params (ts-> Dev, abs_y, 0, 0 xfff , 0, 0 );
}
|
The same is true for a piece of code. For example, my debugging
6410
The Board uses
12
During system startup, the following print information is displayed:
I/keyinputqueue ( 58 ): X: min = 0 max = 4095 flat = 0 fuzz = 0 I/keyinputqueue ( 58 ): Y: min = 0 max = 4095 flat = 0 fuzz = 0 |
From this we can see that the principle of modifying the driver is to ensure that the data reported by the driver is original data that has not been modified.
2
Generation of correction coefficients
The generation of off-core coefficients relies on software. Because of the specific touch screen correction algorithm, correction applications are universal. There are two items to be modified in this application. First, don't forget to change the screen resolution to the desired resolution. Second, adjust the data according to the conversion precision adopted by the driver layer:
Final int ui_screen_width = ts_resolution_x;
Final int ui_screen_height = ts_resolution_y;
X1 = (INT) (event. getx () * 4095 )/(TS_RESOLUTION_X-1 )); // 2 ^ 12-1 = 4095
Y1 = (INT) (event. Gety () * 4095 )/(TS_RESOLUTION_Y-1 )); |
This part should be noted in the correction coefficient file.
Pointercal
For permission issues, you need
Init. RC
To generate the file:
Chmod 0777/data/etc Chmod 0644/data/etc/pointercal
|
The first sentence is "allow ".
/Data/etc
Generate
Pointercal
File, the second sentence is to ensure
Pointercal
The file can be read.
Now you can
Inputdevice. Java
Added the following code:
3
Read the calibration File
Static void readpointercalfile (){
Transforminfo T = NULL;
Try {
Fileinputstream is;
If (custom_file_exist ){
Log. I ("ts_dbg", "inputdevice. readpointercalfile: Read calibration_file from/data/etc ");
Is = new fileinputstream (calibration_file2 );
} Else {
Log. I ("ts_dbg", "inputdevice. readpointercalfile: Read calibration_file from/system/etc ");
Is = new fileinputstream (calibration_file1 );
}
Byte [] mbuffer = new byte [64];
Int Len = is. Read (mbuffer );
Is. Close ();
If (LEN> 0 ){
Int I;
For (I = 0; I <Len; I ++ ){
If (mbuffer [I] = '/N' | mbuffer [I] = 0 ){
Break;
}
}
Len = I;
}
Stringtokenizer ST = new stringtokenizer (new string (mbuffer, 0, 0, Len ));
T = new transforminfo ();
T. X1 = integer. parseint (St. nexttoken ());
T. Y1 = integer. parseint (St. nexttoken ());
T. z1 = integer. parseint (St. nexttoken ());
T. X2 = integer. parseint (St. nexttoken ());
T. y2 = integer. parseint (St. nexttoken ());
T. Z2 = integer. parseint (St. nexttoken ());
T. s = Integer. parseint (St. nexttoken ());
Log. I ("inputdevice. readpointercalfile :",
"T. X1 =" + T. X1 + "T. Y1 =" + T. Y1 + "T. z1 =" + T. Z1
+ "T. x2 = "+ T. x2 + "T. y2 = "+ T. y2 + "T. z2 = "+ T. z2 + "T. S = "+ T. s );
} Catch (Java. Io. filenotfoundexception e ){
Custom_file_exist = false;
Log. I ("ts_dbg", "filenotfound! ");
} Catch (Java. Io. ioexception e ){
Log. I ("ts_dbg", "ioexception ");
}
Tinfo = T;
|
4
, Truncate the original data and use the calibration coefficient for calibration
If (device. tinfo! = NULL) Reportdata [J + motionevent. sample_x] =
(Device. tinfo. X1 * x_tmp +
Device. tinfo. Y1 * y_tmp +
Device. tinfo. Z1)/device. tinfo. S;
Else
Reportdata [J + motionevent. sample_x] =
(Reportdata [J + motionevent. sample_x]-absx. minvalue)
/Absx. Range) * W;
If (device. tinfo! = NULL)
Reportdata [J + motionevent. sample_y] =
(Device. tinfo. X2 * x_tmp +
Device. tinfo. Y2 * y_tmp +
Device. tinfo. Z2)/device. tinfo. S;
Else
Reportdata [J + motionevent. sample_y] =
(Reportdata [J + motionevent. sample_y]-absy. minvalue)
/Absy. Range) * h;
|
Note: To ensure
Pointercal
By the way, make sure that the keyboard works properly. Because the first time I used software correction, the touch screen was not good, at least I had to have a direction key to ensure that the correction program would be smooth (of course the second and later ). In addition, ensure that
Menu
The key works properly because the last step of the correction program is required
Meun
Key validation, generated only after the touch
Pointercal
File. Of course, if your buttons are not enough, you can change the verification key to another key by modifying the correction application.