Android multi-point touch interface

Source: Internet
Author: User

Introduction

To use a powerful multi-touch device, you need a solution to report the detailed finger touch data required by the user layer. The multi-touch protocol described in this document allows the kernel driver to report any multi-finger data information to the user layer.

Instructions for use

The single touch information is carried by ABS and sent in a certain order, such as btn_touch, abs_x, abs_y, and sync. The multi-point touch information is carried by abs_mt and sent in a certain order, such as abs_mt_position_x and abs_mt_position_y. Then, a syn_mt_report event is generated by calling input_mt_sync () to mark the end of a vertex, tell the recipient to receive the information of the current finger and prepare to receive the touch information of other fingers. Finally, call the input_sync () function to report the start action of the touch information and tell the receiver to start receiving a series of multi-touch information.

The Protocol defines a series of abs_mt events. These events are divided into several categories and may only apply one of them. The smallest event set of multi-touch should include abs_mt_touch_major, abs_mt_position_x, and abs_mt_position_y, to achieve multi-point touch. If the device supports the abs_mt_width_major event, this event can provide the contact area for finger touch. Information such as the touch direction can be provided by abs_mt_touch_minor, abs_mt_width_minor and abs_mt_orientation. Abs_mt_tool_type indicates the type of a touch device, such as a hand, pen, or other device. Finally, some devices may support abs_mt_tracking_id, which is used to support hardware tracking of Multi-Point information, that is, the line to which the point belongs.

The following is the minimum event set sequence supported by two-point touch:

Abs_mt_touch_major
Abs_mt_position_x
Abs_mt_position_y
Syn_mt_report // report the first Vertex
Abs_mt_touch_major
Abs_mt_position_x
Abs_mt_position_y
Syn_mt_report // report the second Vertex
Syn_report // start action

Event primitive

The term "Contact" is used to describe the surface of an object directly hitting another object.

Abs_mt_touch_major describes the long axis of the main contact plane. It is in the same unit as X and Y. If the resolution of a plane is x * y, then, the maximum value of abs_mt_touch_major is SQRT (x ^ 2 + y ^ 2)

Abs_mt_touch_minor describes the short axis of the contact surface. If the contact surface is circular, it does not need to be used.

Abs_mt_width_major describes the long axis of the contact tool.

Abs_mt_width_minor describes the short axis of the contact tool.

Abs_mt_touch_major: = max (x, y)
Abs_mt_touch_minor: = min (x, y)
Abs_mt_orientation: = bool (x> Y)

The preceding four parameters can be used to generate additional touch information. For example, the ratio of abs_mt_touch_major/abs_mt_width_major can be used to describe the pressure.

Abs_mt_orientation

Abs_mt_position_x coordinates of the contact center x

Abs_mt_position_y y coordinate of the center of the contact surface

Abs_mt_tool_type describes the contact tool type. Many kernel drivers cannot distinguish this parameter, such as finger and pen. If so, this parameter is not required. Currently, the protocol supports mt_tool_finger and mt_tool_pen.

Abs_mt_blob_id: ID of the Shape set, which contains several points to describe a shape. Many drivers do not have shape attributes. this parameter is optional.

Abs_mt_tracking_id describes the entire process set from the beginning of contact to the release. If the device does not support this parameter, this parameter is not required.

Touch track

Only a few devices can clearly identify the real trackingid. In most cases, trackingid can only identify the process of one touch operation.

Gesture

The application specified by multi-point touch is to create a gesture action. The touch and width parameters are often used to distinguish the pressure of the finger from the distance between the fingers, in addition, minor class parameters can be used to differentiate the contact surface size (point contact or surface contact) of a device, and orientation can generate rotation events.

========================================================== ========================================================== ====================================

Based on Linux Kernel support, Android adds the multi-touch feature to its 2.0 source code. Thus, the touch screen is completely divided into two ways in the framework of Android: single-point touch screen single-point mode, multi-point touch screen single-point and multi-point mode.

In Linux input. H, the multi-touch function depends on the following main software bits:

.............................

# Define syn_report0

# Define syn_config1

# Define syn_mt_report2

..............................

# Define abs_mt_touch_major0x30/* major axis of touching ellipse */

# Define abs_mt_touch_minor0x31/* minor axis (omit if circular )*/

# Define abs_mt_width_major0x32/* major axis of Approaching Ellipse */

# Define abs_mt_width_minor0x33/* minor axis (omit if circular )*/

# Define abs_mt_orientation0x34/* ellipse orientation */

# Define abs_mt_position_x0x35/* center x ellipse position */

# Define abs_mt_position_y0x36/* center y ellipse position */

# Define abs_mt_tool_type0x37/* type of touching device */

# Define abs_mt_blob_id0x38/* group a set of packets as a blob */

..............................

The corresponding software bits in Android are defined in rawinputevent. Java:

.......................

Public class rawinputevent {

...................

Public static final int class_touchscreen_mt = 0x00000010;

....................

Public static final int abs_mt_touch_major = 0x30;

Public static final int abs_mt_touch_minor = 0x31;

Public static final int abs_mt_width_major = 0x32;

Public static final int abs_mt_width_minor = 0x33;

Public static final int abs_mt_orientation = 0x34;

Public static final int abs_mt_position_x = 0x35;

Public static final int abs_mt_position_y = 0x36;

Public static final int abs_mt_tool_type = 0x37;

Public static final int abs_mt_blob_id = 0x38;

......................

Public static final int syn_report = 0;

Public static final int syn_config = 1;

Public static final int syn_mt_report = 2;

....................

In Android, the implementation of multi-point touch is completely separated from the single point in the specific code implementation. In eventhub. cpp of Android code, single screen and multi-screen are determined by the following code segment:

Int eventhub: open_device (const char * devicename)

{

...........................

If (test_bit (abs_mt_touch_major, abs_bitmask)

& Test_bit (abs_mt_position_x, abs_bitmask)

& Test_bit (abs_mt_position_y, abs_bitmask )){

Device-> classes | = class_touchscreen | class_touchscreen_mt;

// Logi ("it is a multi-touch screen! ");

}

// Single-touch?

Else if (test_bit (btn_touch, key_bitmask)

& Test_bit (abs_x, abs_bitmask)

& Test_bit (abs_y, abs_bitmask )){

Device-> classes | = class_touchscreen;

// Logi ("it is a single-touch screen! ");

}

....................

}

We know that in touch screen drivers, the probe function usually calls input_set_abs_params to initialize the input_dev struct to the device. These input_dev parameters will be read in eventhub. cpp of Android. As shown above, if our touch screen is to be processed as a multi-point screen, you only need to add the following parameters to input_dev in the driver:

Input_set_abs_params (mcs_data.input, abs_mt_position_x, pdata-> abs_x_min, pdata-> abs_x_max, 0, 0 );

Input_set_abs_params (mcs_data.input, abs_mt_position_y, pdata-> abs_y_min, pdata-> abs_y_max, 0, 0 );

Input_set_abs_params (mcs_data.input, abs_mt_touch_major, 0, 15, 0, 0 );

// Equivalent to the abx_pressure of a single screen

Input_set_abs_params (mcs_data.input, abs_mt_width_major, 0, 15, 0, 0 );

// Equivalent to abs_tool_width of a single screen

Because the multi-touch technology needs to collect multiple points and then process them together, the accuracy and integrity of each wave of points must be ensured in software implementation. Therefore, the Linux Kernel provides the input_mt_sync (struct input_dev * input) function. After each vertex of each wave is reported, an input_mt_sync () statement must be followed. When all vertices of this wave are reported, input_sync () is used for synchronization. For example, three points must be reported in a wave:

/* Report point 1 */

.................

Input_mt_sync (input );

/* Report point 2 */

.................

Input_mt_sync (input );

/* Report point 3 */

.................

Input_mt_sync (input );

Input_sync (input );

Note: even if only one single point event is reported, one input_my_sync is required.

 

Related Article

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.