From patchwork Wed Mar 16 16:59:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyan Ogilvie X-Patchwork-Id: 8602621 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9C967C0553 for ; Wed, 16 Mar 2016 17:00:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B0B26202F2 for ; Wed, 16 Mar 2016 17:00:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D3B3F202F0 for ; Wed, 16 Mar 2016 17:00:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753389AbcCPRAI (ORCPT ); Wed, 16 Mar 2016 13:00:08 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:37816 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752373AbcCPRAH (ORCPT ); Wed, 16 Mar 2016 13:00:07 -0400 Received: by mail-wm0-f52.google.com with SMTP id p65so81714312wmp.0; Wed, 16 Mar 2016 10:00:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=4WKNempUZZIrod/UOrfzC/m7qFnt5aCob0aNRoKPfXA=; b=lZoJc2QpLFpYOur9JSZtDfwrzs2Sa1raQ88EWzh9sme1rKZ33a24M6zOZ69YcOzFuz eOn7N/ahp2LNqtIcEc6WEV7zqNEVVeRQF0lhy2C+AOjjk5VVuor2r5cETSp2zRNrpsdT sd11iG3ZDtV2GtAyv1dhe2kwEZjs56CYs6azRzSBjEOELLkv3hJ6SypZo4gUbymqGwIh fbvsMsS+IjAG6dA2dl5/7GiYnzOcquslgFyI/oA3yKBt4wjTAMVKUZDnfEAGf1w+/r7D kTrSOwYpWi8uoexSB/7g0iDyIxv2tz7tkYUGjkTchihBTrclkXoul4YtJCCYYPlfuC0K tfgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4WKNempUZZIrod/UOrfzC/m7qFnt5aCob0aNRoKPfXA=; b=ewhicTNRv03kkrmWJlwZzPUji8o0AS9Fo23dMa6W+Q1r8/fbO7ZZtdAjNpED/DVSxd zK9sb+V6Su7rFeU4m/WCFK7eaOBPlQLNjvTvCxvWwHJ+jUks+IDkhjZz0cF7FrBEljrD eyZFTL6iT5s3Q4PZMVQZ/rakOTEKhue71DbCS1kWXqQkpZOCJUNsfHxA0b0J7bU8yAuH oji1P9spI3otxiyUKWCcSpUj52yhImqhtgV4vOtLaGWTEWutWQzDk6pDtkfF3Niu96Q1 7TkLgGMPrEdwL2ArtAoWC3S1JYdEHPnKFei+6aj1NHTbfPJvJPx4NlbyP75M/0D5AVmD MtTg== X-Gm-Message-State: AD7BkJJvtwL1aHdFZE4GvdpNiAsTFJecVIwgN00aC5KgSbx5rXE6tLxnYMV2XchXJMB/Og== X-Received: by 10.28.63.68 with SMTP id m65mr5706859wma.95.1458147605217; Wed, 16 Mar 2016 10:00:05 -0700 (PDT) Received: from ebony.rubylane.com (169-0-103-28.ip.afrihost.co.za. [169.0.103.28]) by smtp.gmail.com with ESMTPSA id gt7sm3884091wjc.1.2016.03.16.10.00.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Mar 2016 10:00:04 -0700 (PDT) From: Cyan Ogilvie To: David Herrmann , Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Cyan Ogilvie Subject: [PATCH] HID: wiimote: Fix wiimote mp scale linearization Date: Wed, 16 Mar 2016 18:59:41 +0200 Message-Id: <1458147581-4126-1-git-send-email-cyan.ogilvie@gmail.com> X-Mailer: git-send-email 2.1.4 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The wiimote motion plus gyros use two scales to report fast and slow rotation - below 440 deg/s uses 8192/440 units / deg/s, and above uses 8192/2000 units / deg/s. Previously this driver attempted to linearize the two by scaling the fast rate by 18 and the slow by 9, but this results in a scale of 8192*9/440 = ~167.564 for slow and 8192*18/2000 = 73.728 for fast. Correct the fast motion scale factor so that both report ~167.564 units / deg/s Signed-off-by: Cyan Ogilvie Reviewed-by: David Herrmann --- drivers/hid/hid-wiimote-modules.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c index 4390eee..c830ed3 100644 --- a/drivers/hid/hid-wiimote-modules.c +++ b/drivers/hid/hid-wiimote-modules.c @@ -2049,9 +2049,11 @@ static void wiimod_mp_in_mp(struct wiimote_data *wdata, const __u8 *ext) * -----+------------------------------+-----+-----+ * The single bits Yaw, Roll, Pitch in the lower right corner specify * whether the wiimote is rotating fast (0) or slow (1). Speed for slow - * roation is 440 deg/s and for fast rotation 2000 deg/s. To get a - * linear scale we multiply by 2000/440 = ~4.5454 which is 18 for fast - * and 9 for slow. + * roation is 8192/440 units / deg/s and for fast rotation 8192/2000 + * units / deg/s. To get a linear scale for fast rotation we multiply + * by 2000/440 = ~4.5454 and scale both fast and slow by 9 to match the + * previous scale reported by this driver. + * This leaves a linear scale with 8192*9/440 (~167.564) units / deg/s. * If the wiimote is not rotating the sensor reports 2^13 = 8192. * Ext specifies whether an extension is connected to the motionp. * which is parsed by wiimote-core. @@ -2070,15 +2072,15 @@ static void wiimod_mp_in_mp(struct wiimote_data *wdata, const __u8 *ext) z -= 8192; if (!(ext[3] & 0x02)) - x *= 18; + x = (x * 2000 * 9) / 440; else x *= 9; if (!(ext[4] & 0x02)) - y *= 18; + y = (y * 2000 * 9) / 440; else y *= 9; if (!(ext[3] & 0x01)) - z *= 18; + z = (z * 2000 * 9) / 440; else z *= 9;