Multi-touch (MT) Protocol-------------------------Copyright (C) 2009-2010Henrik Rydberg <rydberg@euromail.se>Introduction------------In order to utilize the full power of the new multi-touch and multi-userdevices, a way to report detailed data from multiple contacts, i.e.,objects in direct contact with the device surface, is needed.  Thisdocument describes the multi-touch (MT) protocol which allows kerneldrivers to report details for an arbitrary number of contacts.The protocol is divided into two types, depending on the capabilities of thehardware. For devices handling anonymous contacts (type A), the protocoldescribes how to send the raw data for all contacts to the receiver. Fordevices capable of tracking identifiable contacts (type B), the protocoldescribes how to send updates for individual contacts via event slots.Protocol Usage--------------Contact details are sent sequentially as separate packets of ABS_MTevents. Only the ABS_MT events are recognized as part of a contactpacket. Since these events are ignored by current single-touch (ST)applications, the MT protocol can be implemented on top of the ST protocolin an existing driver.Drivers for type A devices separate contact packets by callinginput_mt_sync() at the end of each packet. This generates a SYN_MT_REPORTevent, which instructs the receiver to accept the data for the currentcontact and prepare to receive another.Drivers for type B devices separate contact packets by callinginput_mt_slot(), with a slot as argument, at the beginning of each packet.This generates an ABS_MT_SLOT event, which instructs the receiver toprepare for updates of the given slot.All drivers mark the end of a multi-touch transfer by calling the usualinput_sync() function. This instructs the receiver to act upon eventsaccumulated since last EV_SYN/SYN_REPORT and prepare to receive a new setof events/packets.The main difference between the stateless type A protocol and the statefultype B slot protocol lies in the usage of identifiable contacts to reducethe amount of data sent to userspace. The slot protocol requires the use ofthe ABS_MT_TRACKING_ID, either provided by the hardware or computed fromthe raw data [5].For type A devices, the kernel driver should generate an arbitraryenumeration of the full set of anonymous contacts currently on thesurface. The order in which the packets appear in the event stream is notimportant.  Event filtering and finger tracking is left to user space [3].For type B devices, the kernel driver should associate a slot with eachidentified contact, and use that slot to propagate changes for the contact.Creation, replacement and destruction of contacts is achieved by modifyingthe ABS_MT_TRACKING_ID of the associated slot.  A non-negative tracking idis interpreted as a contact, and the value -1 denotes an unused slot.  Atracking id not previously present is considered new, and a tracking id nolonger present is considered removed.  Since only changes are propagated,the full state of each initiated contact has to reside in the receivingend.  Upon receiving an MT event, one simply updates the appropriateattribute of the current slot.Some devices identify and/or track more contacts than they can report to thedriver.  A driver for such a device should associate one type B slot with eachcontact that is reported by the hardware.  Whenever the identity of thecontact associated with a slot changes, the driver should invalidate thatslot by changing its ABS_MT_TRACKING_ID.  If the hardware signals that it istracking more contacts than it is currently reporting, the driver should usea BTN_TOOL_*TAP event to inform userspace of the total number of contactsbeing tracked by the hardware at that moment.  The driver should do this byexplicitly sending the corresponding BTN_TOOL_*TAP event and settinguse_count to false when calling input_mt_report_pointer_emulation().The driver should only advertise as many slots as the hardware can report.Userspace can detect that a driver can report more total contacts than slotsby noting that the largest supported BTN_TOOL_*TAP event is larger than thetotal number of type B slots reported in the absinfo for the ABS_MT_SLOT axis.The minimum value of the ABS_MT_SLOT axis must be 0.Protocol Example A------------------Here is what a minimal event sequence for a two-contact touch would looklike for a type A device:   ABS_MT_POSITION_X x[0]   ABS_MT_POSITION_Y y[0]   SYN_MT_REPORT   ABS_MT_POSITION_X x[1]   ABS_MT_POSITION_Y y[1]   SYN_MT_REPORT   SYN_REPORTThe sequence after moving one of the contacts looks exactly the same; theraw data for all present contacts are sent between every synchronizationwith SYN_REPORT.Here is the sequence after lifting the first contact:   ABS_MT_POSITION_X x[1]   ABS_MT_POSITION_Y y[1]   SYN_MT_REPORT   SYN_REPORTAnd here is the sequence after lifting the second contact:   SYN_MT_REPORT   SYN_REPORTIf the driver reports one of BTN_TOUCH or ABS_PRESSURE in addition to theABS_MT events, the last SYN_MT_REPORT event may be omitted. Otherwise, thelast SYN_REPORT will be dropped by the input core, resulting in nozero-contact event reaching userland.Protocol Example B------------------Here is what a minimal event sequence for a two-contact touch would looklike for a type B device:   ABS_MT_SLOT 0   ABS_MT_TRACKING_ID 45   ABS_MT_POSITION_X x[0]   ABS_MT_POSITION_Y y[0]   ABS_MT_SLOT 1   ABS_MT_TRACKING_ID 46   ABS_MT_POSITION_X x[1]   ABS_MT_POSITION_Y y[1]   SYN_REPORTHere is the sequence after moving contact 45 in the x direction:   ABS_MT_SLOT 0   ABS_MT_POSITION_X x[0]   SYN_REPORTHere is the sequence after lifting the contact in slot 0:   ABS_MT_TRACKING_ID -1   SYN_REPORTThe slot being modified is already 0, so the ABS_MT_SLOT is omitted.  Themessage removes the association of slot 0 with contact 45, therebydestroying contact 45 and freeing slot 0 to be reused for another contact.Finally, here is the sequence after lifting the second contact:   ABS_MT_SLOT 1   ABS_MT_TRACKING_ID -1   SYN_REPORTEvent Usage-----------A set of ABS_MT events with the desired properties is defined. The eventsare divided into categories, to allow for partial implementation.  Theminimum set consists of ABS_MT_POSITION_X and ABS_MT_POSITION_Y, whichallows for multiple contacts to be tracked.  If the device supports it, theABS_MT_TOUCH_MAJOR and ABS_MT_WIDTH_MAJOR may be used to provide the sizeof the contact area and approaching tool, respectively.The TOUCH and WIDTH parameters have a geometrical interpretation; imaginelooking through a window at someone gently holding a finger against theglass.  You will see two regions, one inner region consisting of the partof the finger actually touching the glass, and one outer region formed bythe perimeter of the finger. The center of the touching region (a) isABS_MT_POSITION_X/Y and the center of the approaching finger (b) isABS_MT_TOOL_X/Y. The touch diameter is ABS_MT_TOUCH_MAJOR and the fingerdiameter is ABS_MT_WIDTH_MAJOR. Now imagine the person pressing the fingerharder against the glass. The touch region will increase, and in general,the ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR, which is always smallerthan unity, is related to the contact pressure. For pressure-based devices,ABS_MT_PRESSURE may be used to provide the pressure on the contact areainstead. Devices capable of contact hovering can use ABS_MT_DISTANCE toindicate the distance between the contact and the surface.  Linux MT                               Win8         __________                     _______________________        /          \                   |                       |       /            \                  |                       |      /     ____     \                 |                       |     /     /    \     \                |                       |     \     \  a  \     \               |       a               |      \     \____/      \              |                       |       \                 \             |                       |        \        b        \            |           b           |         \                 \           |                       |          \                 \          |                       |           \                 \         |                       |            \                /         |                       |             \              /          |                       |              \            /           |                       |               \__________/            |_______________________|In addition to the MAJOR parameters, the oval shape of the touch and fingerregions can be described by adding the MINOR parameters, such that MAJORand MINOR are the major and minor axis of an ellipse. The orientation ofthe touch ellipse can be described with the ORIENTATION parameter, and thedirection of the finger ellipse is given by the vector (a - b).For type A devices, further specification of the touch shape is possiblevia ABS_MT_BLOB_ID.The ABS_MT_TOOL_TYPE may be used to specify whether the touching tool is afinger or a pen or something else. Finally, the ABS_MT_TRACKING_ID eventmay be used to track identified contacts over time [5].In the type B protocol, ABS_MT_TOOL_TYPE and ABS_MT_TRACKING_ID areimplicitly handled by input core; drivers should instead callinput_mt_report_slot_state().Event Semantics---------------ABS_MT_TOUCH_MAJORThe length of the major axis of the contact. The length should be given insurface units. If the surface has an X times Y resolution, the largestpossible value of ABS_MT_TOUCH_MAJOR is sqrt(X^2 + Y^2), the diagonal [4].ABS_MT_TOUCH_MINORThe length, in surface units, of the minor axis of the contact. If thecontact is circular, this event can be omitted [4].ABS_MT_WIDTH_MAJORThe length, in surface units, of the major axis of the approachingtool. This should be understood as the size of the tool itself. Theorientation of the contact and the approaching tool are assumed to be thesame [4].ABS_MT_WIDTH_MINORThe length, in surface units, of the minor axis of the approachingtool. Omit if circular [4].The above four values can be used to derive additional information aboutthe contact. The ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR approximatesthe notion of pressure. The fingers of the hand and the palm all havedifferent characteristic widths.ABS_MT_PRESSUREThe pressure, in arbitrary units, on the contact area. May be used insteadof TOUCH and WIDTH for pressure-based devices or any device with a spatialsignal intensity distribution.ABS_MT_DISTANCEThe distance, in surface units, between the contact and the surface. Zerodistance means the contact is touching the surface. A positive number meansthe contact is hovering above the surface.ABS_MT_ORIENTATIONThe orientation of the touching ellipse. The value should describe a signedquarter of a revolution clockwise around the touch center. The signed valuerange is arbitrary, but zero should be returned for an ellipse aligned withthe Y axis of the surface, a negative value when the ellipse is turned tothe left, and a positive value when the ellipse is turned to theright. When completely aligned with the X axis, the range max should bereturned.Touch ellipsis are symmetrical by default. For devices capable of true 360degree orientation, the reported orientation must exceed the range max toindicate more than a quarter of a revolution. For an upside-down finger,range max * 2 should be returned.Orientation can be omitted if the touch area is circular, or if theinformation is not available in the kernel driver. Partial orientationsupport is possible if the device can distinguish between the two axis, butnot (uniquely) any values in between. In such cases, the range ofABS_MT_ORIENTATION should be [0, 1] [4].ABS_MT_POSITION_XThe surface X coordinate of the center of the touching ellipse.ABS_MT_POSITION_YThe surface Y coordinate of the center of the touching ellipse.ABS_MT_TOOL_XThe surface X coordinate of the center of the approaching tool. Omit ifthe device cannot distinguish between the intended touch point and thetool itself.ABS_MT_TOOL_YThe surface Y coordinate of the center of the approaching tool. Omit if thedevice cannot distinguish between the intended touch point and the toolitself.The four position values can be used to separate the position of the touchfrom the position of the tool. If both positions are present, the majortool axis points towards the touch point [1]. Otherwise, the tool axes arealigned with the touch axes.ABS_MT_TOOL_TYPEThe type of approaching tool. A lot of kernel drivers cannot distinguishbetween different tool types, such as a finger or a pen. In such cases, theevent should be omitted. The protocol currently supports MT_TOOL_FINGER andMT_TOOL_PEN [2]. For type B devices, this event is handled by input core;drivers should instead use input_mt_report_slot_state().ABS_MT_BLOB_IDThe BLOB_ID groups several packets together into one arbitrarily shapedcontact. The sequence of points forms a polygon which defines the shape ofthe contact. This is a low-level anonymous grouping for type A devices, andshould not be confused with the high-level trackingID [5]. Most type Adevices do not have blob capability, so drivers can safely omit this event.ABS_MT_TRACKING_IDThe TRACKING_ID identifies an initiated contact throughout its life cycle[5]. The value range of the TRACKING_ID should be large enough to ensureunique identification of a contact maintained over an extended period oftime. For type B devices, this event is handled by input core; driversshould instead use input_mt_report_slot_state().Event Computation-----------------The flora of different hardware unavoidably leads to some devices fittingbetter to the MT protocol than others. To simplify and unify the mapping,this section gives recipes for how to compute certain events.For devices reporting contacts as rectangular shapes, signed orientationcannot be obtained. Assuming X and Y are the lengths of the sides of thetouching rectangle, here is a simple formula that retains the mostinformation possible:   ABS_MT_TOUCH_MAJOR := max(X, Y)   ABS_MT_TOUCH_MINOR := min(X, Y)   ABS_MT_ORIENTATION := bool(X > Y)The range of ABS_MT_ORIENTATION should be set to [0, 1], to indicate thatthe device can distinguish between a finger along the Y axis (0) and afinger along the X axis (1).For win8 devices with both T and C coordinates, the position mapping is   ABS_MT_POSITION_X := T_X   ABS_MT_POSITION_Y := T_Y   ABS_MT_TOOL_X := C_X   ABS_MT_TOOL_X := C_YUnfortunately, there is not enough information to specify both the touchingellipse and the tool ellipse, so one has to resort to approximations.  Onesimple scheme, which is compatible with earlier usage, is:   ABS_MT_TOUCH_MAJOR := min(X, Y)   ABS_MT_TOUCH_MINOR := <not used>   ABS_MT_ORIENTATION := <not used>   ABS_MT_WIDTH_MAJOR := min(X, Y) + distance(T, C)   ABS_MT_WIDTH_MINOR := min(X, Y)Rationale: We have no information about the orientation of the touchingellipse, so approximate it with an inscribed circle instead. The toolellipse should align with the vector (T - C), so the diameter mustincrease with distance(T, C). Finally, assume that the touch diameter isequal to the tool thickness, and we arrive at the formulas above.Finger Tracking---------------The process of finger tracking, i.e., to assign a unique trackingID to eachinitiated contact on the surface, is a Euclidian Bipartite Matchingproblem.  At each event synchronization, the set of actual contacts ismatched to the set of contacts from the previous synchronization. A fullimplementation can be found in [3].Gestures--------In the specific application of creating gesture events, the TOUCH and WIDTHparameters can be used to, e.g., approximate finger pressure or distinguishbetween index finger and thumb. With the addition of the MINOR parameters,one can also distinguish between a sweeping finger and a pointing finger,and with ORIENTATION, one can detect twisting of fingers.Notes-----In order to stay compatible with existing applications, the data reportedin a finger packet must not be recognized as single-touch events.For type A devices, all finger data bypasses input filtering, sincesubsequent events of the same type refer to different fingers.For example usage of the type A protocol, see the bcm5974 driver. Forexample usage of the type B protocol, see the hid-egalax driver.[1] Also, the difference (TOOL_X - POSITION_X) can be used to model tilt.[2] The list can of course be extended.[3] The mtdev project: http://bitmath.org/code/mtdev/.[4] See the section on event computation.

[5] See the section on finger tracking.

From: https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android 动画显示文字与bitmap的BadgeVie
  2. Android 开发上奇怪的问题
  3. Android动态加载――加载已安装APK中的类
  4. Android视图绘画与属性动画
  5. Android程序开发通过HttpURLConnection上
  6. [Android]attrs.xml文件中属性类型format
  7. Anroid中两台手机连接同一wifi通过socket
  8. Android(安卓)自定义View - 网络加载 Pro
  9. ros安装android
  10. Cocos2dx android 部分代码的理解