linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: Add direction to ff-memless
@ 2009-12-04 13:05 Jari Vanhala
  2009-12-04 13:05 ` [PATCH] Input: Force Feedback core memory leak Jari Vanhala
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jari Vanhala @ 2009-12-04 13:05 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, ext-jari.vanhala

This adds simple direction calculation to effect
combine. It's useful to decide motor direction for
rumble (vibrator).

Signed-off-by: Jari Vanhala <ext-jari.vanhala@nokia.com>
---
 drivers/input/ff-memless.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c
index 2d1415e..9af009a 100644
--- a/drivers/input/ff-memless.c
+++ b/drivers/input/ff-memless.c
@@ -221,6 +221,14 @@ static int get_compatible_type(struct ff_device *ff, int effect_type)
 	return 0;
 }
 
+static unsigned int ml_calculate_direction(
+	unsigned int direction, unsigned int force,
+	unsigned int new_direction, unsigned int new_force)
+{
+	return ((u32)direction * force + new_direction * new_force) /
+		(force + new_force);
+}
+
 /*
  * Combine two effects and apply gain.
  */
@@ -255,6 +263,19 @@ static void ml_combine_effects(struct ff_effect *effect,
 	case FF_RUMBLE:
 		strong = new->u.rumble.strong_magnitude * gain / 0xffff;
 		weak = new->u.rumble.weak_magnitude * gain / 0xffff;
+
+		if (effect->u.rumble.strong_magnitude + strong)
+			effect->direction = ml_calculate_direction(
+				effect->direction,
+				effect->u.rumble.strong_magnitude,
+				new->direction, strong);
+		else if (effect->u.rumble.weak_magnitude + weak)
+			effect->direction = ml_calculate_direction(
+				effect->direction,
+				effect->u.rumble.weak_magnitude,
+				new->direction, weak);
+		else
+			effect->direction = 0;
 		effect->u.rumble.strong_magnitude =
 			min(strong + effect->u.rumble.strong_magnitude,
 			    0xffffU);
@@ -269,6 +290,13 @@ static void ml_combine_effects(struct ff_effect *effect,
 		/* here we also scale it 0x7fff => 0xffff */
 		i = i * gain / 0x7fff;
 
+		if (effect->u.rumble.strong_magnitude + i)
+			effect->direction = ml_calculate_direction(
+				effect->direction,
+				effect->u.rumble.strong_magnitude,
+				new->direction, i);
+		else
+			effect->direction = 0;
 		effect->u.rumble.strong_magnitude =
 			min(i + effect->u.rumble.strong_magnitude, 0xffffU);
 		effect->u.rumble.weak_magnitude =
-- 
1.6.3.3


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

end of thread, other threads:[~2009-12-24 23:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-04 13:05 [PATCH] Input: Add direction to ff-memless Jari Vanhala
2009-12-04 13:05 ` [PATCH] Input: Force Feedback core memory leak Jari Vanhala
2009-12-07  6:26   ` Dmitry Torokhov
2009-12-07 21:16 ` [PATCH] Input: Add direction to ff-memless Anssi Hannula
2009-12-08  9:08   ` Jari Vanhala
2009-12-09  1:15     ` Anssi Hannula
2009-12-23 12:58 ` [PATCH v2] " Jari Vanhala
2009-12-24 23:37   ` Anssi Hannula

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