linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michal Malý" <madcatxster@gmail.com>
To: jkosina@suse.cz
Cc: linux-input@vger.kernel.org
Subject: [PATCH] Fix autocentering command in hid-lgff driver
Date: Tue, 14 Jun 2011 22:42:30 +0200	[thread overview]
Message-ID: <2502891.N5kVV5at6b@qosmio-x300> (raw)

Hello,

this patch fixes two issues with autocentering in lgff driver. Current implementation incorrectly assumes that the saturation force is always 0x80 which is 
inconsistent with behavior of the official driver. It also makes it impossible to disable autocentering on some wheels - at least Logitech Formula Force RX is 
the case. Values of stiffness coefficient were also calculated incorrectly. Formula used in this patch appears to generate the same commands as the official 
Logitech drivers. The patch also fixes two minor coding style issues.

Regards, Michal.


Signed-off-by: Michal Malý <madcatxster@gmail.com>
---
 drivers/hid/hid-lgff.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/hid/hid-lgff.c b/drivers/hid/hid-lgff.c
index 088f850..3d30a8e 100644
--- a/drivers/hid/hid-lgff.c
+++ b/drivers/hid/hid-lgff.c
@@ -129,18 +129,24 @@ static void hid_lgff_set_autocenter(struct input_dev *dev, u16 magnitude)
 	struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
 	struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
 	__s32 *value = report->field[0]->value;
-	magnitude = (magnitude >> 12) & 0xf;
+	u8 saturation_force = magnitude >> 8;
+	u8 stiffness_coeff;
+	if (magnitude <= 32768)
+		stiffness_coeff = saturation_force / 10;
+	else
+		stiffness_coeff = (saturation_force / 62) + 11;
+
 	*value++ = 0xfe;
 	*value++ = 0x0d;
-	*value++ = magnitude;   /* clockwise strength */
-	*value++ = magnitude;   /* counter-clockwise strength */
-	*value++ = 0x80;
+	*value++ = stiffness_coeff;   /* clockwise strength */
+	*value++ = stiffness_coeff;   /* counter-clockwise strength */
+	*value++ = saturation_force;
 	*value++ = 0x00;
 	*value = 0x00;
 	usbhid_submit_report(hid, report, USB_DIR_OUT);
 }
 
-int lgff_init(struct hid_device* hid)
+int lgff_init(struct hid_device *hid)
 {
 	struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
 	struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
@@ -180,7 +186,7 @@ int lgff_init(struct hid_device* hid)
 	if (error)
 		return error;
 
-	if ( test_bit(FF_AUTOCENTER, dev->ffbit) )
+	if (test_bit(FF_AUTOCENTER, dev->ffbit))
 		dev->ff->set_autocenter = hid_lgff_set_autocenter;
 
 	pr_info("Force feedback for Logitech force feedback devices by Johann Deneux <johann.deneux@it.uu.se>\n");
-- 
1.7.5.4


--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2011-06-14 20:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-14 20:42 Michal Malý [this message]
2011-06-14 21:20 ` [PATCH] Fix autocentering command in hid-lgff driver simon
2011-06-14 22:26   ` Michal Malý
2011-06-14 23:16     ` simon
2011-06-15  0:03       ` Michal Malý
     [not found]       ` <4429494.nOUqc25rPl@qosmio-x300>
2011-06-15 21:56         ` Michal Malý
     [not found] ` <1908821.jaYXT1Nn2e@qosmio-x300>
     [not found]   ` <da2b7e45ed001b587d49824944b802b8.squirrel@host171.canaca.com>
     [not found]     ` <201106262207.23918.michael@m-bauer.org>
2011-06-27 16:15       ` simon
2011-06-27 20:58         ` Michal Malý
2011-06-29  9:28           ` Michael Bauer
2011-06-29 15:23             ` Michael Bauer
2011-06-29 15:50             ` simon
2011-06-29 21:37               ` Michal Malý
2011-07-05 23:04               ` Michal Malý

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2502891.N5kVV5at6b@qosmio-x300 \
    --to=madcatxster@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).