From patchwork Sun Oct 6 18:44:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Brune X-Patchwork-Id: 2993061 X-Patchwork-Delegate: jikos@jikos.cz 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 561F2BF924 for ; Sun, 6 Oct 2013 18:53:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 48CBD2018A for ; Sun, 6 Oct 2013 18:53:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4368720171 for ; Sun, 6 Oct 2013 18:53:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754168Ab3JFSxE (ORCPT ); Sun, 6 Oct 2013 14:53:04 -0400 Received: from tyrell.rbrune.de ([83.169.16.173]:36178 "EHLO tyrell.rbrune.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754104Ab3JFSxD (ORCPT ); Sun, 6 Oct 2013 14:53:03 -0400 X-Greylist: delayed 465 seconds by postgrey-1.27 at vger.kernel.org; Sun, 06 Oct 2013 14:53:03 EDT Received: from localhost.localdomain (gtng-4d08a392.pool.mediaWays.net [77.8.163.146]) (Authenticated sender: mail@rbrune.de) by tyrell.rbrune.de (Postfix) with ESMTPSA id 8D4F717CA0001; Sun, 6 Oct 2013 20:45:16 +0200 (CEST) From: Rafael Brune To: linux-input@vger.kernel.org Cc: Rafael Brune Subject: [PATCH 1/1] HID: wiimote: invert Y-Axis and add automatic calibration for Wii U Pro Controller Date: Sun, 6 Oct 2013 20:44:56 +0200 Message-Id: <1381085096-4511-1-git-send-email-mail@rbrune.de> X-Mailer: git-send-email 1.8.3.2 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 With these changes the Wii U Pro Controller fully complies to the gamepad-API and with the calibration is fully usable out-of-the-box without any user-space tools. This potentially breaks compatibility with software that relies on the two inverted Y-Axis but since current bluez 4.x and 5.x versions don't even support pairing with the controller yet the amount of people affected should be rather small. Signed-off-by: Rafael Brune --- drivers/hid/hid-wiimote-modules.c | 45 +++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c index 2e7d644..1422b0b 100644 --- a/drivers/hid/hid-wiimote-modules.c +++ b/drivers/hid/hid-wiimote-modules.c @@ -1640,10 +1640,41 @@ static void wiimod_pro_in_ext(struct wiimote_data *wdata, const __u8 *ext) ly = (ext[4] & 0xff) | ((ext[5] & 0x0f) << 8); ry = (ext[6] & 0xff) | ((ext[7] & 0x0f) << 8); - input_report_abs(wdata->extension.input, ABS_X, lx - 0x800); - input_report_abs(wdata->extension.input, ABS_Y, ly - 0x800); - input_report_abs(wdata->extension.input, ABS_RX, rx - 0x800); - input_report_abs(wdata->extension.input, ABS_RY, ry - 0x800); + /* Calibrating the sticks by saving the global min/max per axis */ + if (lx < wdata->state.calib_bboard[0][0]) + wdata->state.calib_bboard[0][0] = lx; + if (lx > wdata->state.calib_bboard[0][1]) + wdata->state.calib_bboard[0][1] = lx; + + if (ly < wdata->state.calib_bboard[1][0]) + wdata->state.calib_bboard[1][0] = ly; + if (ly > wdata->state.calib_bboard[1][1]) + wdata->state.calib_bboard[1][1] = ly; + + if (rx < wdata->state.calib_bboard[2][0]) + wdata->state.calib_bboard[2][0] = rx; + if (rx > wdata->state.calib_bboard[2][1]) + wdata->state.calib_bboard[2][1] = rx; + + if (ry < wdata->state.calib_bboard[3][0]) + wdata->state.calib_bboard[3][0] = ry; + if (ry > wdata->state.calib_bboard[3][1]) + wdata->state.calib_bboard[3][1] = ry; + + /* Normalize using int math to prevent conversion to/from float */ + lx = -2048 + (((__s32)(lx - wdata->state.calib_bboard[0][0]) * 4096)/ + (wdata->state.calib_bboard[0][1]-wdata->state.calib_bboard[0][0])); + ly = -2048 + (((__s32)(ly - wdata->state.calib_bboard[1][0]) * 4096)/ + (wdata->state.calib_bboard[1][1]-wdata->state.calib_bboard[1][0])); + rx = -2048 + (((__s32)(rx - wdata->state.calib_bboard[2][0]) * 4096)/ + (wdata->state.calib_bboard[2][1]-wdata->state.calib_bboard[2][0])); + ry = -2048 + (((__s32)(ry - wdata->state.calib_bboard[3][0]) * 4096)/ + (wdata->state.calib_bboard[3][1]-wdata->state.calib_bboard[3][0])); + + input_report_abs(wdata->extension.input, ABS_X, lx); + input_report_abs(wdata->extension.input, ABS_Y, -ly); + input_report_abs(wdata->extension.input, ABS_RX, rx); + input_report_abs(wdata->extension.input, ABS_RY, -ry); input_report_key(wdata->extension.input, wiimod_pro_map[WIIMOD_PRO_KEY_RIGHT], @@ -1760,6 +1791,12 @@ static int wiimod_pro_probe(const struct wiimod_ops *ops, if (!wdata->extension.input) return -ENOMEM; + /* Initialize min/max values for all Axis with reasonable values */ + for (i = 0; i < 4; ++i) { + wdata->state.calib_bboard[i][0] = 0x780; + wdata->state.calib_bboard[i][1] = 0x880; + } + set_bit(FF_RUMBLE, wdata->extension.input->ffbit); input_set_drvdata(wdata->extension.input, wdata);