Multi-touch (MT) Protocol(翻譯)

轉載於: http://www.arm9home.net/read.php?tid=24754


前段時間改寫了一個GT801的內核驅動,仔細閱讀 MT Event 上報的時候,發現這個驅動是針對 Android 系統有所偏重的。
於是便仔細閱讀了一下內核文檔中關於多點觸摸協議的介紹。

多點觸摸的信息,是觸摸屏這樣的觸摸設備向 input core 上報 MT 消息傳遞的。
這些 MT消息,可以通過 設備文件的接口,被應用程序讀取到。

整個消息傳遞過程,以及 上層應用程序(DirectFB / Xorg / EFL  / Tslib)的支持情況,還沒有完全弄清楚。
等弄清楚了再和大家分享。

將 multi-touch-protocol.txt 文檔翻譯了一下,有些地方感覺理解得不太正確,還請指正。
可以在內核目錄中找到這個文件:Documentation/input/multi-touch-protocol.txt

----------------------------------------------------------------------------------------------------------------------

[en] Multi-touch (MT) Protocol
[zh] 多點觸摸(MT)協議
-------------------------
[en]    Copyright (C) 2009-2010    Henrik Rydberg <[email protected]>

[en]Introduction
[zh]介紹
------------

[en] In order to utilize the full power of the new multi-touch and multi-user
[en] devices, a way to report detailed data from multiple contacts, i.e.,
[en] objects in direct contact with the device surface, is needed.  This
[en] document describes the multi-touch (MT) protocol which allows kernel
[en] drivers to report details for an arbitrary number of contacts.
[zh] 爲了發揮新出現的多點觸摸設備、多用戶同時操作設備的全部能力,
[zh] 需要一種能夠報告多個觸摸點的數據的方法。
[zh] 本文檔介紹的內容是多點觸摸協議,它允許內核驅動程序上報任意多個觸摸點的信息。
[zh] 譯者注:多點觸摸設備,比如iphone4的觸摸屏。
[zh] 譯者注:多用戶操作設備,比如電子黑板的書寫筆,允許多個用戶各用一支筆,並且同時各寫各的。

[en] The protocol is divided into two types, depending on the capabilities of the
[en] hardware. For devices handling anonymous contacts (type A), the protocol
[en] describes how to send the raw data for all contacts to the receiver. For
[en] devices capable of tracking identifiable contacts (type B), the protocol
[en] describes how to send updates for individual contacts via event slots.
[zh] 依據硬件設備的能力,本協議分成兩種類型。
[zh] type A:觸摸點不能被區分和追蹤,本協議描述如何上報這些原始數據給監聽者。
[zh] type B:硬件有能力追蹤並區分觸摸點,本協議描述如何通過slot更新某一個觸摸點的信息。

[en]Protocol Usage
[zh]協議的使用方法
--------------

[en] Contact details are sent sequentially as separate packets of ABS_MT
[en] events. Only the ABS_MT events are recognized as part of a contact
[en] packet. Since these events are ignored by current single-touch (ST)
[en] applications, the MT protocol can be implemented on top of the ST protocol
[en] in an existing driver.
[zh] 觸摸點的信息是通過一串ABS_MT系列的消息上報的。
[zh] 只有ABS_MT系列的消息是當做多點觸摸消息識別的,
[zh] 因爲目前只對應了單點觸摸(ST)的應用程序會忽略掉這些消息,
[zh] 所以已有的驅動程序可以在單點觸摸協議之上獨立實現多點觸摸協議。
[zh] -------------------------
[zh] 在 <linux/input.h> 中定義的:
[zh] #define ABS_MT_SLOT         0x2f    /* MT slot being modified */
[zh] #define ABS_MT_TOUCH_MAJOR  0x30    /* Major axis of touching ellipse */
[zh] #define ABS_MT_TOUCH_MINOR  0x31    /* Minor axis (omit if circular) */
[zh] #define ABS_MT_WIDTH_MAJOR  0x32    /* Major axis of approaching ellipse */
[zh] #define ABS_MT_WIDTH_MINOR  0x33    /* Minor axis (omit if circular) */
[zh] #define ABS_MT_ORIENTATION  0x34    /* Ellipse orientation */
[zh] #define ABS_MT_POSITION_X   0x35    /* Center X ellipse position */
[zh] #define ABS_MT_POSITION_Y   0x36    /* Center Y ellipse position */
[zh] #define ABS_MT_TOOL_TYPE    0x37    /* Type of touching device */
[zh] #define ABS_MT_BLOB_ID      0x38    /* Group a set of packets as a blob */
[zh] #define ABS_MT_TRACKING_ID  0x39    /* Unique ID of initiated contact */
[zh] #define ABS_MT_PRESSURE     0x3a    /* Pressure on contact area */
[zh] #define ABS_MT_DISTANCE     0x3b    /* Contact hover distance */

[en] Drivers for type A devices separate contact packets by calling
[en] input_mt_sync() at the end of each packet. This generates a SYN_MT_REPORT
[en] event, which instructs the receiver to accept the data for the current
[en] contact and prepare to receive another.
[zh] 對於type A設備的驅動程序,在上報某個觸摸點信息的最後,
[zh] 通過調用input_mt_sync()隔開不通觸摸點的信息。
[zh] 調用input_mt_sync()會產生一個SYN_MT_REPORT消息,
[zh] 這個消息會觸發接受者獲取到某一個觸摸點的信息,並準備接收下一個觸摸點信息。

[en] Drivers for type B devices separate contact packets by calling
[en] input_mt_slot(), with a slot as argument, at the beginning of each packet.
[en] This generates an ABS_MT_SLOT event, which instructs the receiver to
[en] prepare for updates of the given slot.
[zh] 對於type B設備的驅動程序,在開始上報某個觸摸點信息的時候,
[zh] 調用input_mt_slot()用於區分是哪一個觸摸點的信息,傳遞slot作爲參數。
[zh] 通過調用input_mt_slot()會產生一個SYN_MT_REPORT消息,
[zh] 這個消息告訴接收者正在針對哪個slot更新信息。

[en] All drivers mark the end of a multi-touch transfer by calling the usual
[en] input_sync() function. This instructs the receiver to act upon events
[en] accumulated since last EV_SYN/SYN_REPORT and prepare to receive a new set
[en] of events/packets.
[zh] 驅動程序通常調用input_sync()標示多點觸摸信息傳輸結束。
[zh] 調用input_sync()會觸發接收者處理上次input_sync()到這次input_sync()之間累積的所有消息。
[zh] 並讓接收者準備下一次接收。

[en] The main difference between the stateless type A protocol and the stateful
[en] type B slot protocol lies in the usage of identifiable contacts to reduce
[en] the amount of data sent to userspace. The slot protocol requires the use of
[en] the ABS_MT_TRACKING_ID, either provided by the hardware or computed from
[en] the raw data [5].
[zh] type B協議和type A協議相比,最大的區別是能夠識別某一個觸摸點,
[zh] 因此能夠減少發送給用戶空間的數據。
[zh] 要使用slot 區分觸摸點,需要使用ABS_MT_TRACKING_ID 這個消息,
[zh] 這個ID可以是來自於硬件的,也可以是從原始數據計算得來的。

[en] For type A devices, the kernel driver should generate an arbitrary
[en] enumeration of the full set of anonymous contacts currently on the
[en] surface. The order in which the packets appear in the event stream is not
[en] important.  Event filtering and finger tracking is left to user space [3].
[zh] type A設備的驅動程序,需要一次性將當前觸摸屏上的所有觸摸點的信息全部上報。
[zh] 上報消息的順序並不重要,因爲消息的過濾和觸摸點的跟蹤是在用戶空間處理的。

[en] For type B devices, the kernel driver should associate a slot with each
[en] identified contact, and use that slot to propagate changes for the contact.
[en] Creation, replacement and destruction of contacts is achieved by modifying
[en] the ABS_MT_TRACKING_ID of the associated slot.  A non-negative tracking id
[en] is interpreted as a contact, and the value -1 denotes an unused slot.  A
[en] tracking id not previously present is considered new, and a tracking id no
[en] longer present is considered removed.  Since only changes are propagated,
[en] the full state of each initiated contact has to reside in the receiving
[en] end.  Upon receiving an MT event, one simply updates the appropriate
[en] attribute of the current slot.
[zh] type B設備的驅動程序,需要給已經識別的觸摸點分配一個slot,
[zh] 並且用這個slot上報這個觸摸點的變化信息。
[zh] 通過修改slot的ABS_MT_TRACKING_ID,可以實現新增加、替換,去除觸摸點。
[zh] 非負數的 ID 被認爲是觸摸點, -1 的 ID被認爲是未使用的slot。
[zh] 一個以前不存在的 ID 出現了表示是一個新的,一個 ID 不存在了表示 刪除了。
[zh] 因爲只有變化的信息被上報,因此每一個觸摸點的完整信息必須放在接收端進行維護。
[zh] 根據接收到的MT(MultiTouch)消息,應用程序更新當前slot的相關屬性。


[en] Some devices identify and/or track more contacts than they can report to the
[en] driver.  A driver for such a device should associate one type B slot with each
[en] contact that is reported by the hardware.  Whenever the identity of the
[en] contact associated with a slot changes, the driver should invalidate that
[en] slot by changing its ABS_MT_TRACKING_ID.  If the hardware signals that it is
[en] tracking more contacts than it is currently reporting, the driver should use
[en] a BTN_TOOL_*TAP event to inform userspace of the total number of contacts
[en] being tracked by the hardware at that moment.  The driver should do this by
[en] explicitly sending the corresponding BTN_TOOL_*TAP event and setting
[en] use_count to false when calling input_mt_report_pointer_emulation().
[en] The driver should only advertise as many slots as the hardware can report.
[en] Userspace can detect that a driver can report more total contacts than slots
[en] by noting that the largest supported BTN_TOOL_*TAP event is larger than the
[en] total number of type B slots reported in the absinfo for the ABS_MT_SLOT axis.
[zh] 一些設備識別或者追蹤的觸摸點比它報告給驅動程序它能夠識別的要多。
[zh] 這些設備的驅動應該將每一個觸摸點上報成 type B類型的slot信息。
[zh] 一旦某一個slot關聯的觸摸點的ID發生變化,
[zh] 驅動程序應該改變這個slot的ABS_MT_TRACKING_ID讓slot變爲無效。
[zh] 如果硬件設備告訴驅動程序他正在追蹤比他能力多的觸摸點,
[zh] 那麼驅動程序應該上報BTN_TOOL_*TAP消息給用戶程序,告知當前硬件設備追蹤的觸摸點總數。
[zh] 方法是:
[zh] 1. 顯示地發送 BTN_TOOL_*TAP 消息,
[zh] 2. 並且調用input_mt_report_pointer_emulation(),設置 use_count 爲 false。
[zh] 驅動程序上報的slot總數應該和硬件設備能夠支持的總數一致,
[zh] 用戶程序通過 對比 BTN_TOOL_*TAP信息中的slot總數和 ABS_MT_SLOT 中的 absinfo 中的 slot總數對比,
[zh] 能夠檢測出來驅動程序上報的觸摸點總數超過了slot總數。
[zh] -------------------------
[zh] 在 <linux/input.h> 中定義的:
[zh] #define BTN_TOOL_FINGER     0x145
[zh] #define BTN_TOOL_DOUBLETAP  0x14d
[zh] #define BTN_TOOL_TRIPLETAP  0x14e
[zh] #define BTN_TOOL_QUADTAP    0x14f   /* Four fingers on trackpad */
[zh] #define BTN_TOOL_QUINTTAP   0x148   /* Five fingers on trackpad */


[en] Protocol Example A
[zh] 協議舉例: type A
------------------

[en] Here is what a minimal event sequence for a two-contact touch would look
[en] like for a type A device:
[zh] 這是一個針對 type A 設備的, 2個觸摸點的最小消息時序。

    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_REPORT

[en] The sequence after moving one of the contacts looks exactly the same; the
[en] raw data for all present contacts are sent between every synchronization
[en] with SYN_REPORT.
[zh] 移走任何一個觸摸點的時序應該都是一致的。
[zh] 針對每一個當前還在的觸摸點,信息應該在SYN_REPORT之前上報。

[en] Here is the sequence after lifting the first contact:
[zh] 這是移走其中一個觸摸點的時序。

    ABS_MT_POSITION_X x[1]
    ABS_MT_POSITION_Y y[1]
    SYN_MT_REPORT
    SYN_REPORT

[en] And here is the sequence after lifting the second contact:
[zh] 這是移走第二個觸摸點的時序。

   SYN_MT_REPORT
   SYN_REPORT

[en] If the driver reports one of BTN_TOUCH or ABS_PRESSURE in addition to the
[en] ABS_MT events, the last SYN_MT_REPORT event may be omitted. Otherwise, the
[en] last SYN_REPORT will be dropped by the input core, resulting in no
[en] zero-contact event reaching userland.
[zh] 如果驅動程序想要附加BTN_TOUCH或者ABS_PRESSURE消息給ABS_MT消息,
[zh] 那麼最後一個SYN_MT_REPORT消息可以被省略。
[zh] 除此之外,SYN_MT_REPORT不能被省略,
[zh] 如果最後一個SYN_MT_REPORT被省略,
[zh] SYN_REPORT消息會被內核的input core丟棄,導致“沒有觸摸點了”的消息無法到達用戶空間。

[en] Protocol Example B
[zh] 協議舉例: type B
------------------

[en] Here is what a minimal event sequence for a two-contact touch would look
[en] like for a type B device:
[zh] 這是一個針對 type B 設備的, 2個觸摸點的最小消息時序。

   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_REPORT

[en] Here is the sequence after moving contact 45 in the x direction:
[zh] 這是向 X軸方向移動 ID 爲 45的觸摸點的時序。

[en]    ABS_MT_SLOT 0
[en]    ABS_MT_POSITION_X x[0]
[en]    SYN_REPORT

[en] Here is the sequence after lifting the contact in slot 0:
[zh] 這是移走其中一個觸摸點( slot 0 )的時序。

[en]    ABS_MT_TRACKING_ID -1
[en]    SYN_REPORT

[en] The slot being modified is already 0, so the ABS_MT_SLOT is omitted.  The
[en] message removes the association of slot 0 with contact 45, thereby
[en] destroying contact 45 and freeing slot 0 to be reused for another contact.
[zh] 正在被編輯的slot已經是slot 0了,所以ABS_MT_SLOT消息就省略了。
[zh] 這串消息將slot 0和觸摸點ID 爲 45之間的聯繫刪除,
[zh] 也就是觸摸點ID 爲 45的被刪除了, slot 0 可以給其他的觸摸點使用了。

[en] Finally, here is the sequence after lifting the second contact:
[zh] 最後是移走第二個觸摸點的時序。

   ABS_MT_SLOT 1
   ABS_MT_TRACKING_ID -1
   SYN_REPORT


[en] Event Usage
[zh] 消息使用方法
-----------

[en] A set of ABS_MT events with the desired properties is defined. The events
[en] are divided into categories, to allow for partial implementation.  The
[en] minimum set consists of ABS_MT_POSITION_X and ABS_MT_POSITION_Y, which
[en] allows for multiple contacts to be tracked.  If the device supports it, the
[en] ABS_MT_TOUCH_MAJOR and ABS_MT_WIDTH_MAJOR may be used to provide the size
[en] of the contact area and approaching contact, respectively.
[zh] 一套ABS_MT消息在內核中已經被定義了。
[zh] 這些消息分成多個類別,用於開發者按照自己喜歡的方式開發。
[zh] 最小的組合是ABS_MT_POSITION_X和ABS_MT_POSITION_Y消息,用於跟蹤多個觸摸點的位置。
[zh] 如果外部設備支持的話,
[zh] 還可以用ABS_MT_TOUCH_MAJOR和ABS_MT_WIDTH_MAJOR這兩個消息上報觸摸面積的信息。


[en] The TOUCH and WIDTH parameters have a geometrical interpretation; imagine
[en] looking through a window at someone gently holding a finger against the
[en] glass.  You will see two regions, one inner region consisting of the part
[en] of the finger actually touching the glass, and one outer region formed by
[en] the perimeter of the finger. The diameter of the inner region is the
[en] ABS_MT_TOUCH_MAJOR, the diameter of the outer region is
[en] ABS_MT_WIDTH_MAJOR. Now imagine the person pressing the finger harder
[en] against the glass. The inner region will increase, and in general, the
[en] ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR, which is always smaller than
[en] unity, is related to the contact pressure. For pressure-based devices,
[en] ABS_MT_PRESSURE may be used to provide the pressure on the contact area
[en] instead. Devices capable of contact hovering can use ABS_MT_DISTANCE to
[en] indicate the distance between the contact and the surface.
[zh] TOUCH和WITH是有幾何意義的。
[zh] 想象一下,有個人的手指頭壓着一片玻璃,我們從玻璃這邊看手指頭。
[zh] 可以看到2個區域,中間的區域是實際壓着的部分,外面那個區域是手指頭在玻璃上的投影。
[zh] 中間區域的直徑 就是ABS_MT_TOUCH_MAJOR。
[zh] 外面大得區域的直徑 就是ABS_MT_WIDTH_MAJOR。
[zh] 現在想象一下,壓的力氣變大一些,裏面的區域就會變大,
[zh] ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR 的值就能反映壓力的大小,
[zh] 這個值通常是小於1的。
[zh] 對於支持壓力檢測的設備來說,ABS_MT_PRESSURE可以用來替代按壓面積,上報壓力。
[zh] 對於支持haovring的設備來說,可以使用ABS_MT_DISTANCE來表明手指和觸摸屏表面的距離。



[en] In addition to the MAJOR parameters, the oval shape of the contact can be
[en] described by adding the MINOR parameters, such that MAJOR and MINOR are the
[en] major and minor axis of an ellipse. Finally, the orientation of the oval
[en] shape can be describe with the ORIENTATION parameter.
[zh] 作爲MAJOR的補充,觸摸點的橢圓形的形狀,還可以用MINOR來說明。
[zh] MAJOR和MINOR分別表示最長的方向和短一些的那個方向。
[zh] 最後也可以用ORIENTATION來說明這個橢圓的方位,是不是水平的。

[en] For type A devices, further specification of the touch shape is possible
[en] via ABS_MT_BLOB_ID.
[zh] 對於type A類型的設備而言,觸摸點形狀的更多特徵還可以使用ABS_MT_BLOB_ID消息進行通知。

[en] The ABS_MT_TOOL_TYPE may be used to specify whether the touching tool is a
[en] finger or a pen or something else. Finally, the ABS_MT_TRACKING_ID event
[en] may be used to track identified contacts over time [5].
[zh] ABS_MT_TOOL_TYPE可以用來說明觸摸的工具是手指、筆或者其他的什麼。
[zh] 最後,ABS_MT_TRACKING_ID消息可以用來跟蹤被識別的觸摸點。

[en] In the type B protocol, ABS_MT_TOOL_TYPE and ABS_MT_TRACKING_ID are
[en] implicitly handled by input core; drivers should instead call
[en] input_mt_report_slot_state().
[zh] 對於type B類型的設備,
[zh] ABS_MT_TOOL_TYPE 和 ABS_MT_TRACKING_ID 會被 input core 在暗地裏處理。
[zh] 因此驅動程序應該調用 input_mt_report_slot_state()。

[en] Event Semantics
[zh] 消息含義
---------------

ABS_MT_TOUCH_MAJOR

[en] The length of the major axis of the contact. The length should be given in
[en] surface units. If the surface has an X times Y resolution, the largest
[en] possible value of ABS_MT_TOUCH_MAJOR is sqrt(X^2 + Y^2), the diagonal [4].
[zh] 觸摸點橢圓形最長的那個方向的直徑。
[zh] 這個長度應該是觸摸表面的長度單位,
[zh] 如果觸摸表面的X是Y的幾倍(矩形),
[zh] 那麼ABS_MT_TOUCH_MAJOR的長度最長爲 ( x平方 +  y平方 )開根號,也就是對角線的長度。

ABS_MT_TOUCH_MINOR

[en] The length, in surface units, of the minor axis of the contact. If the
[en] contact is circular, this event can be omitted [4].
[zh] 觸摸點橢圓形短一點的那個方向的直徑,如果是圓形,ABS_MT_TOUCH_MINOR可以省略。

ABS_MT_WIDTH_MAJOR

[en] The length, in surface units, of the major axis of the approaching
[en] tool. This should be understood as the size of the tool itself. The
[en] orientation of the contact and the approaching tool are assumed to be the
[en] same [4].
[zh] 以觸摸面的長度單位爲單位的觸摸工具,在觸摸面上的最長的長度,
[zh] 這個長度可以理解爲觸摸工具本身的長度。
[zh] 觸摸點和觸摸工具的水平方向假設是一致的。

ABS_MT_WIDTH_MINOR

[en] The length, in surface units, of the minor axis of the approaching
[en] tool. Omit if circular [4].
[zh] 以觸摸面的長度單位爲單位的觸摸工具,在觸摸面上的短一點的長度。
[zh] 如果是圓形可以省略。

[en] The above four values can be used to derive additional information about
[en] the contact. The ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR approximates
[en] the notion of pressure. The fingers of the hand and the palm all have
[en] different characteristic widths [1].
[zh] 上面的4個數據可以用來傳遞觸摸點的一些額外信息。
[zh] ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR 的比值用來估計壓力的大小。
[zh] 這些寬度信息也可以用於識別手指還是手掌。(手掌比手指要寬)

ABS_MT_PRESSURE

[en] The pressure, in arbitrary units, on the contact area. May be used instead
[en] of TOUCH and WIDTH for pressure-based devices or any device with a spatial
[en] signal intensity distribution.
[zh] 觸摸點的壓力大小,可以是任意衡量單位。
[zh] 對於能夠測量壓力的設備,可以用來替代TOUCH 和 WIDTH。

ABS_MT_DISTANCE

[en] The distance, in surface units, between the contact and the surface. Zero
[en] distance means the contact is touching the surface. A positive number means
[en] the contact is hovering above the surface.
[zh] 手指頭距離觸摸屏表面的距離,以觸摸面的長度單位爲單位。
[zh] 0意味着已經接觸到觸摸屏。
[zh] 大於0的數是指手指頭在觸摸屏上面的高度。

ABS_MT_ORIENTATION

[en] The orientation of the ellipse. The value should describe a signed quarter
[en] of a revolution clockwise around the touch center. The signed value range
[en] is arbitrary, but zero should be returned for a finger aligned along the Y
[en] axis of the surface, a negative value when finger is turned to the left, and
[en] a positive value when finger turned to the right. When completely aligned with
[en] the X axis, the range max should be returned.  Orientation can be omitted
[en] if the touching object is circular, or if the information is not available
[en] in the kernel driver. Partial orientation support is possible if the device
[en] can distinguish between the two axis, but not (uniquely) any values in
[en] between. In such cases, the range of ABS_MT_ORIENTATION should be [0, 1]
[en] [4].
[zh] 橢圓形觸摸點的方向(水平還是垂直)。
[zh] 它的值應該是有符號的、和旋轉方向有關、90度爲一個週期的。
[zh] 取值範圍是有符號的,取值範圍可以任意定,
[zh] 但0應該表示爲長軸沿着Y方向,
[zh] 負數表示逆時針旋轉了,正數表示順時針旋轉了。
[zh] 長軸方向如果完全變成X方向,那麼值就變成最大的了。
[zh] 如果觸摸點的形狀是圓形,或者得不到形狀信息,可以不上報ABS_MT_ORIENTATION這個消息。
[zh] 如果設備只能檢測到是水平或者是垂直信息,那麼ABS_MT_ORIENTATION的值就應該是0或者1。


ABS_MT_POSITION_X

[en] The surface X coordinate of the center of the touching ellipse.
[zh] 觸摸中心位置的X軸座標。

ABS_MT_POSITION_Y

[en] The surface Y coordinate of the center of the touching ellipse.
[zh] 觸摸中心位置的Y軸座標。

ABS_MT_TOOL_TYPE

[en] The type of approaching tool. A lot of kernel drivers cannot distinguish
[en] between different tool types, such as a finger or a pen. In such cases, the
[en] event should be omitted. The protocol currently supports MT_TOOL_FINGER and
[en] MT_TOOL_PEN [2]. For type B devices, this event is handled by input core;
[en] drivers should instead use input_mt_report_slot_state().
[zh] 觸摸工具類型,很多內核驅動都不能區分是什麼觸摸工具,比如是手指還是筆。
[zh] 如果是這樣的內核驅動,那麼應該省略掉這個消息。
[zh] 目前的多點觸摸協議支持 MT_TOOL_FINGER 和 MT_TOOL_PEN。
[zh] 對於 type B 類型的設備,這個消息是在 input core 處理的,
[zh] 因此驅動程序應該調用 input_mt_report_slot_state() 上報觸摸工具的類型。

ABS_MT_BLOB_ID

[en] The BLOB_ID groups several packets together into one arbitrarily shaped
[en] contact. The sequence of points forms a polygon which defines the shape of
[en] the contact. This is a low-level anonymous grouping for type A devices, and
[en] should not be confused with the high-level trackingID [5]. Most type A
[en] devices do not have blob capability, so drivers can safely omit this event.
[zh] 將多個座標消息組合成一個BLOB_ID,用於描述觸摸點的形狀。
[zh] 多個點的信息按照一定順序上報,能夠形成一個代表觸摸點形狀的多邊形。
[zh] 這個是針對 type A 的更底層的信息打包,不要和 高級的 TRACKING ID 弄混了。
[zh] 大部分 type A 的設備並不支持這個功能,所以驅動程序忽略掉這個消息也沒有關係。

ABS_MT_TRACKING_ID

[en] The TRACKING_ID identifies an initiated contact throughout its life cycle
[en] [5]. The value range of the TRACKING_ID should be large enough to ensure
[en] unique identification of a contact maintained over an extended period of
[en] time. For type B devices, this event is handled by input core; drivers
[en] should instead use input_mt_report_slot_state().
[zh] TRACKING ID用來追蹤和識別壓下到提起期間的某一個觸摸點。
[zh] TRACKING ID的取值範圍應該是足夠大的,用於更方便區分是哪一個觸摸點。
[zh] 對於 type B 類型的設備,這個消息是 input core 內部處理的,
[zh] 驅動程序應該調用 input_mt_report_slot_state() 來告訴input core當前slot是否是無效了。

[en] Event Computation
[zh] 消息的處理
-----------------

[en] The flora of different hardware unavoidably leads to some devices fitting
[en] better to the MT protocol than others. To simplify and unify the mapping,
[en] this section gives recipes for how to compute certain events.
[zh] 由於硬件設備衆多,其中的一些設備比其他的設備,更容易編寫多點觸摸協議的驅動。
[zh] 爲了簡化和統一驅動程序的處理方式,這個章節給出了驅動程序對於主要消息的處理方式的建議。

[en] For devices reporting contacts as rectangular shapes, signed orientation
[en] cannot be obtained. Assuming X and Y are the lengths of the sides of the
[en] touching rectangle, here is a simple formula that retains the most
[en] information possible:
[zh] 如果設備提供的觸摸點信息是矩形,有符號的水平位置信息就無法獲取到。
[zh] 假設X和Y是矩形的兩個邊長,下面的計算方法可以得到最主要的信息。

   ABS_MT_TOUCH_MAJOR := max(X, Y)
   ABS_MT_TOUCH_MINOR := min(X, Y)
   ABS_MT_ORIENTATION := bool(X > Y)

[en] The range of ABS_MT_ORIENTATION should be set to [0, 1], to indicate that
[en] the device can distinguish between a finger along the Y axis (0) and a
[en] finger along the X axis (1).
[zh] ABS_MT_ORIENTATION 的範圍應該是 0 或者 1,
[zh] 用於表明設備能夠區分手指是Y方向還是X方向的。

[en] Finger Tracking
[zh] 手指的追蹤
---------------

[en] The process of finger tracking, i.e., to assign a unique trackingID to each
[en] initiated contact on the surface, is a Euclidian Bipartite Matching
[en] problem.  At each event synchronization, the set of actual contacts is
[en] matched to the set of contacts from the previous synchronization. A full
[en] implementation can be found in [3].
[zh] 給觸摸點分配一個唯一的 TRACKING ID 的判斷方法,是幾何問題。
[zh] 每次進行消息同步的時候,本次同步的觸摸點信息會和上次同步的觸摸點信息進行匹配。
[zh] 你可以在mtdev項目中找到如何匹配的具體的實現。


[en] Gestures
[zh] 手勢
--------

[en] In the specific application of creating gesture events, the TOUCH and WIDTH
[en] parameters can be used to, e.g., approximate finger pressure or distinguish
[en] between index finger and thumb. With the addition of the MINOR parameters,
[en] one can also distinguish between a sweeping finger and a pointing finger,
[en] and with ORIENTATION, one can detect twisting of fingers.
[zh] 對於手勢識別的這類程序,可以使用 TOUCH 和 WIDTH 信息來識別壓力的大小,或者區分哪個是食指,哪個是拇指。
[zh] 如果還有 MINOR 信息的話,還可以識別是滑動的手指或是輕輕點得手指。(沒太看懂 sweeping 和 pointing )
[zh] 如果有 ORIENTATION 信息的話,也可以識別出來手指的轉動。

[en] Notes
[zh] 備註
-----

[en] In order to stay compatible with existing applications, the data reported
[en] in a finger packet must not be recognized as single-touch events.
[zh] 爲了讓已有的應用程序也兼容多點觸摸協議,驅動程序不應該將多點觸摸消息上報成單點觸摸消息。

[en] For type A devices, all finger data bypasses input filtering, since
[en] subsequent events of the same type refer to different fingers.
[zh] 對於 type A 的設備而言,所有的觸摸信息都會繞開 input core 的過濾處理,
[zh] 因爲相同的消息出現2次也許是針對不同的觸摸點。(如果被過濾,就變成一個了)

[en] For example usage of the type A protocol, see the bcm5974 driver. For
[en] example usage of the type B protocol, see the hid-egalax driver.
[zh] type A設備可以參考 bcm5974 的驅動。
[zh] type B設備可以參考 hid-egalax 的驅動。

[en] [1] With the extension ABS_MT_APPROACH_X and ABS_MT_APPROACH_Y, the
[en] difference between the contact position and the approaching tool position
[en] could be used to derive tilt.
[zh] [1]通過擴展的 ABS_MT_APPROACH_X 和 ABS_MT_APPROACH_Y 消息,可以傳遞 觸摸工具的座標位置信息。
[zh] 如果和 觸摸點座標 進行比較的話,可以判斷出來觸摸工具是否是傾斜的。

[en] [2] The list can of course be extended.
[en] [3] The mtdev project: http://bitmath.org/code/mtdev/.
[en] [4] See the section on event computation.
[en] [5] See the section on finger tracking.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章