From patchwork Sun Nov 7 22:14:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafi Rubin X-Patchwork-Id: 307412 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oA7MEgeM000329 for ; Sun, 7 Nov 2010 22:14:43 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751158Ab0KGWOl (ORCPT ); Sun, 7 Nov 2010 17:14:41 -0500 Received: from fox.seas.upenn.edu ([158.130.68.12]:49201 "EHLO fox.seas.upenn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751146Ab0KGWOk (ORCPT ); Sun, 7 Nov 2010 17:14:40 -0500 Received: from [192.168.1.80] (pool-108-16-8-160.phlapa.fios.verizon.net [108.16.8.160]) (authenticated bits=0) by fox.seas.upenn.edu (8.14.3/8.14.3) with ESMTP id oA7MEQKC032207 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NOT); Sun, 7 Nov 2010 17:14:27 -0500 Message-ID: <4CD724BC.8020702@seas.upenn.edu> Date: Sun, 07 Nov 2010 17:14:20 -0500 From: Rafi Rubin User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 MIME-Version: 1.0 To: Henrik Rydberg CC: Dmitry Torokhov , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Bagwell , Chase Douglas , Takashi Iwai , =?ISO-8859-1?Q?St=E9phane_Chatty?= Subject: Re: [PATCH] input: Introduce light-weight contact tracking References: <1289161108-32309-1-git-send-email-rydberg@euromail.se> In-Reply-To: <1289161108-32309-1-git-send-email-rydberg@euromail.se> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.2.15, 1.0.148, 0.0.0000 definitions=2010-11-07_07:2010-11-05, 2010-11-07, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=2 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx engine=5.0.0-1005130000 definitions=main-1011070126 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Sun, 07 Nov 2010 22:14:43 +0000 (UTC) different. - efficient for the common case where contact ordering stays consistent - arbitrary number of contacts - motion estimation to improve tracking - leveraging tracking for error filtering Also for fun, I was playing with smoothing in this particular version of the code. For now, I'm sending this just for review and discussion. Rafi --- diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c index 69169ef..d163b9b 100644 --- a/drivers/hid/hid-ntrig.c +++ b/drivers/hid/hid-ntrig.c @@ -19,10 +19,25 @@ #include "usbhid/usbhid.h" #include #include +#include #include "hid-ids.h" #define NTRIG_DUPLICATE_USAGES 0x001 +/** + * list_rotate_left - rotate the list to the left + * @head: the head of the list + */ +static inline void list_rotate_right(struct list_head *head) +{ + struct list_head *last; + + if (!list_empty(head)) { + last = head->prev; + list_move(last, head); + } +} + static unsigned int min_width; module_param(min_width, uint, 0644); @@ -52,10 +67,45 @@ module_param(activation_height, uint, 0644); MODULE_PARM_DESC(activation_height, "Height threshold to immediately start " "processing touch events."); +struct ntrig_slot { + __u16 id; + struct list_head list; +}; + +struct ntrig_contact { + __u16 x, y, w, h; + __s16 est_x_min, est_x_max, est_y_min, est_y_max; + __s16 dx, dy; + __s16 id; + + /* An age factor for counting frames since a track was last seen. + * This enables drop compensation and delayed termination. */ + __u8 inactive; + + struct ntrig_slot *slot; + + struct list_head list; + + /* List of tracks sorted by first seen order */ + struct list_head active_tracks; +}; + +struct ntrig_frame { + + /* Items that represent physical contacts which have been mapped + * to contacts from previous frames. */ + struct list_head tracked; + + /* Contacts that have yet to be matched and might be ghosts. */ + struct list_head pending; + struct list_head list; +}; + struct ntrig_data { /* Incoming raw values for a single contact */ __u16 x, y, w, h; __u16 id; + int slots; bool tipswitch; bool confidence; @@ -63,6 +113,8 @@ struct ntrig_data { bool reading_mt; + __u8 max_contacts; + __u8 mt_footer[4]; __u8 mt_foot_count; @@ -87,8 +139,24 @@ struct ntrig_data { __u16 sensor_logical_height; __u16 sensor_physical_width; __u16 sensor_physical_height; -}; + __u16 r_y; + __u16 r_x; + + /* Circular list of frames used to maintain state of contacts */ + struct list_head frames; + + /* Contacts representing the last input from lost tracks and + * old contacts to be recycled */ + struct list_head old_contacts; + + struct list_head available_slots; + struct list_head active_tracks; + + struct ntrig_frame *first_frame; + struct ntrig_slot *first_slot; + struct ntrig_contact *first_contact; +}; /* * This function converts the 4 byte raw firmware code into @@ -439,6 +507,7 @@ static int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi, case HID_UP_GENDESK: switch (usage->hid) { case HID_GD_X: + nd->max_contacts++; hid_map_usage(hi, usage, bit, max, EV_ABS, ABS_MT_POSITION_X);