From patchwork Thu Aug 18 14:22:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Ospite X-Patchwork-Id: 1076672 X-Patchwork-Delegate: jikos@jikos.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7IEMtRK013957 for ; Thu, 18 Aug 2011 14:22:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755198Ab1HROWx (ORCPT ); Thu, 18 Aug 2011 10:22:53 -0400 Received: from smtp206.alice.it ([82.57.200.102]:40934 "EHLO smtp206.alice.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755231Ab1HROWw (ORCPT ); Thu, 18 Aug 2011 10:22:52 -0400 Received: from jcn (87.10.137.120) by smtp206.alice.it (8.5.124.08) id 4E4BBF770012FB9D; Thu, 18 Aug 2011 16:22:46 +0200 Received: from ao2 by jcn with local (Exim 4.76) (envelope-from ) id 1Qu3UY-0001AD-NV; Thu, 18 Aug 2011 16:22:42 +0200 From: Antonio Ospite To: Alan Ott Cc: Antonio Ospite , linux-bluetooth@vger.kernel.org, Bastien Nocera , linux-input@vger.kernel.org, Jim Paris , Ranulf Doswell , "Pascal A . Brisset" , Marcin Tolysz , Christian Birchinger , Filipe Lopes , Mikko Virkkila , Simon Wood , Arc Riley Subject: [PATCH 2/2] Match controllers using vendor_id and product_id instead of HID_NAME Date: Thu, 18 Aug 2011 16:22:20 +0200 Message-Id: <1313677340-4441-2-git-send-email-ospite@studenti.unina.it> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <20110818161357.8084ab94bff57391e7ec3284@studenti.unina.it> References: <20110818161357.8084ab94bff57391e7ec3284@studenti.unina.it> X-Face: z*RaLf`X<@C75u6Ig9}{oW$H; 1_\2t5)({*|jhM/Vb; ]yA5\I~93>J<_`<4)A{':UrE 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.6 (demeter2.kernel.org [140.211.167.43]); Thu, 18 Aug 2011 14:22:55 +0000 (UTC) Maybe controller->name can be filled in from HID_NAME, but for now having it hardcoded doesn't hurt. --- plugins/sixaxis.c | 42 ++++++++++++++++++++++++++++++------------ 1 files changed, 30 insertions(+), 12 deletions(-) diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c index 608474f..fc1cd52 100644 --- a/plugins/sixaxis.c +++ b/plugins/sixaxis.c @@ -426,12 +426,29 @@ static int set_controller_number(int fd, unsigned int n) return set_leds(fd, leds_status); } - -static inline gboolean is_sixaxis(const char *hid_name) +static inline struct sony_controller *find_sony_controller(const char *hid_id) { - return g_str_has_suffix(hid_name, "PLAYSTATION(R)3 Controller") || - g_str_has_suffix(hid_name, - "Sony Computer Entertainment Wireless Controller"); + unsigned int array_size = sizeof(controllers)/sizeof(controllers[0]); + unsigned int i; + int ret; + uint16_t protocol; + uint16_t vendor_id; + uint16_t product_id; + + ret = sscanf(hid_id, "%hx:%hx:%hx", &protocol, &vendor_id, &product_id); + if (ret != 3) { + error("%s:%s() Parsing HID_ID failed", + __FILE__, __func__); + return NULL; + } + + for (i = 0; i < array_size; i++) { + if (controllers[i].vendor_id == vendor_id && + controllers[i].product_id == product_id) + return &controllers[i]; + } + + return NULL; } static void handle_device_plug(struct udev_device *udevice) @@ -439,7 +456,7 @@ static void handle_device_plug(struct udev_device *udevice) struct udev_device *hid_parent; struct udev_enumerate *enumerate; struct udev_list_entry *devices, *dev_list_entry; - const char *hid_name; + const char *hid_id; const char *hid_phys; const char *hidraw_node; unsigned char is_usb = FALSE; @@ -455,15 +472,16 @@ static void handle_device_plug(struct udev_device *udevice) return; } - hid_name = udev_device_get_property_value(hid_parent, "HID_NAME"); - DBG("name: %s", hid_name); + hid_id = udev_device_get_property_value(hid_parent, "HID_ID"); + DBG("HID_ID: %s", hid_id); - if (!is_sixaxis(hid_name)) + controller = find_sony_controller(hid_id); + if (!controller) { + DBG("No supported controller found"); return; + } - controller = &controllers[0]; - - DBG("Found a Sixaxis device"); + DBG("Found a Sony controller: %s", controller->name); hidraw_node = udev_device_get_devnode(udevice);