From patchwork Sat Jan 28 19:01:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9543431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 980BC6046A for ; Sat, 28 Jan 2017 19:01:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DFF027FBC for ; Sat, 28 Jan 2017 19:01:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FB4F28319; Sat, 28 Jan 2017 19:01:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B26827FBC for ; Sat, 28 Jan 2017 19:01:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751723AbdA1TBF (ORCPT ); Sat, 28 Jan 2017 14:01:05 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35101 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751684AbdA1TBF (ORCPT ); Sat, 28 Jan 2017 14:01:05 -0500 Received: by mail-pg0-f66.google.com with SMTP id 204so27754477pge.2 for ; Sat, 28 Jan 2017 11:01:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=bkoKNcdpWZnfvcJbpl8pbqHRv31jz2LSWnQiQWVCGhc=; b=SQtgIQZ14JFhqcu4UzIeBe8O4lPvMFFHKtcOyl69DnQgfnmj5BYfpNnmWPDU0qtNyz kFD2GKkiwFcwWSn6qimwd+uhTXI8eOKW1N9AjB/O1jjh89t2qbEeuoPC2xJaZjHhLPVm TG4K8dVg54vURWOK2MfVVaFEOhIO8TORTJERILlZxRvRxpix6B/N5uMLZPWxsllKTS7K qh9oxt9NVRF0o9Kt/wqNg6JNoTrfv52FAzUo6B1Ap7/3de2KzJXCidlhHA/XCS1cjiuW BMLC0gQmPJzpiKwWiA1CaP61i26DcUi98dsdBPO5hsd6mDVnjbEXS8I7kuwpqW3Rmsxk PRPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=bkoKNcdpWZnfvcJbpl8pbqHRv31jz2LSWnQiQWVCGhc=; b=QpLjxtV0LnD7lt5utmwY1hmVju7v8uP+0L+OGWKQTKRIbGjobiMi7Fm6zaEvtrbqft FHJrxf0tCvWD7s5NWd8EaqUQjTtz8lBWrhwccQv6cOFQSNA5SAlxblJj+n95l0mY3ZCb ZNNKDYG/UeR1tr9QgxYZXkNAC4wtWxfIDpimRitO60WWeIQ16fG03NCRBLdw0+Ji0TBz 1XB/PccQRgc/eAqTuWkFTTdVnYOUkNCVwkmjrI61jikiGhKYGT9tKUedh6FNUQzCWjwF gkK7fZs6xtZjZA+TE/LDJ7HBgwNB4V2FM3yocMYyVfPzRAIoI8AoA0nSuRY7T/bZeFfv +XMw== X-Gm-Message-State: AIkVDXLFNyuP1YUh4w1dE+jvhQJad+6+XuOPIXXqvtX9jLRGQpwLRM1d3hXAi1y3efmOQQ== X-Received: by 10.84.162.204 with SMTP id o12mr20995335plg.132.1485630064453; Sat, 28 Jan 2017 11:01:04 -0800 (PST) Received: from dtor-ws ([2620:0:1000:1311:90eb:8a67:9b0e:4ecf]) by smtp.gmail.com with ESMTPSA id n79sm20648152pfj.31.2017.01.28.11.01.02 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sat, 28 Jan 2017 11:01:03 -0800 (PST) Date: Sat, 28 Jan 2017 11:01:00 -0800 From: Dmitry Torokhov To: Raphael Assenat Cc: linux-input@vger.kernel.org Subject: Re: [PATCH RESEND] Initialize axis values in joydev_open_device() Message-ID: <20170128190100.GA32332@dtor-ws> References: <20161218202050.GX10002@yggdrasil2.lan.raphnet.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161218202050.GX10002@yggdrasil2.lan.raphnet.net> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Raphael, On Sun, Dec 18, 2016 at 03:20:50PM -0500, Raphael Assenat wrote: > Postpone axis initialization to the first open instead of doing it once > in joydev_connect. This is to make sure the generated startup events > are representative of the current joystick state rather than what > it was when joydev_connect() was called, potentially much earlier. > > This solves issues with joystick driven menus that start scrolling > up each time they are started, until the user moves the joystick to > generate events. In emulator menu setups where the menu program is > restarted every time the game exits, the repeated need to move the > joystick to stop the unintended scrolling gets old rather quickly... > > Unless I misunderstood the intent of JS_EVENT_INIT, I think the startup > events should reflect the current state of the joystick. Please consider > applying if it makes sense. Sorry for the delay and what you are saying certainly makes sense. Unfortunately with the patch as is we end up re-initializing calibration coefficients every time user opens device (assuming that there is only one user of joystick device at a time), whereas before one could have a small utility calibrating the joystick, and then go on to using it with some other application (game). How about we keep most of the initialization in connect() and only populate axis data in open(), like below? diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c index abd18f31b24f..db5e290e897e 100644 --- a/drivers/input/joydev.c +++ b/drivers/input/joydev.c @@ -187,6 +187,17 @@ static void joydev_detach_client(struct joydev *joydev, synchronize_rcu(); } +static void joydev_refresh_state(struct joydev *joydev) +{ + struct input_dev *dev = joydev->handle.dev; + int i, val; + + for (i = 0; i < joydev->nabs; i++) { + val = input_abs_get_val(dev, joydev->abspam[i]); + joydev->abs[i] = joydev_correct(val, &joydev->corr[i]); + } +} + static int joydev_open_device(struct joydev *joydev) { int retval; @@ -201,6 +212,8 @@ static int joydev_open_device(struct joydev *joydev) retval = input_open_device(&joydev->handle); if (retval) joydev->open--; + else + joydev_refresh_state(joydev); } mutex_unlock(&joydev->mutex); @@ -872,7 +885,6 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev, j = joydev->abspam[i]; if (input_abs_get_max(dev, j) == input_abs_get_min(dev, j)) { joydev->corr[i].type = JS_CORR_NONE; - joydev->abs[i] = input_abs_get_val(dev, j); continue; } joydev->corr[i].type = JS_CORR_BROKEN; @@ -887,10 +899,6 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev, if (t) { joydev->corr[i].coef[2] = (1 << 29) / t; joydev->corr[i].coef[3] = (1 << 29) / t; - - joydev->abs[i] = - joydev_correct(input_abs_get_val(dev, j), - joydev->corr + i); } }