linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix autocentering command in hid-lgff driver
@ 2011-06-14 20:42 Michal Malý
  2011-06-14 21:20 ` simon
       [not found] ` <1908821.jaYXT1Nn2e@qosmio-x300>
  0 siblings, 2 replies; 13+ messages in thread
From: Michal Malý @ 2011-06-14 20:42 UTC (permalink / raw)
  To: jkosina; +Cc: linux-input

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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-07-05 23:04 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-14 20:42 [PATCH] Fix autocentering command in hid-lgff driver Michal Malý
2011-06-14 21:20 ` 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ý

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).