From: Jari Vanhala <ext-jari.vanhala@nokia.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, Anssi Hannula <anssi.hannula@iki.fi>,
ext-jari.vanhala@nokia.com
Subject: [PATCH v2] Input: Add direction to ff-memless
Date: Wed, 23 Dec 2009 14:58:14 +0200 [thread overview]
Message-ID: <1261573094-26837-1-git-send-email-ext-jari.vanhala@nokia.com> (raw)
In-Reply-To: <1259931914-6228-1-git-send-email-ext-jari.vanhala@nokia.com>
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 | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c
index b483b29..5914a7d 100644
--- a/drivers/input/ff-memless.c
+++ b/drivers/input/ff-memless.c
@@ -221,6 +221,22 @@ static int get_compatible_type(struct ff_device *ff, int effect_type)
}
/*
+ * Only left/right direction should be used (under/over 0x8000) for
+ * forward/reverse motor direction (to keep calculation fast & simple).
+ */
+static u16 ml_calculate_direction(u16 direction, u16 force,
+ u16 new_direction, u16 new_force)
+{
+ if (!force)
+ return new_direction;
+ if (!new_force)
+ return direction;
+ return (((u32)(direction >> 1) * force +
+ (new_direction >> 1) * new_force) /
+ (force + new_force)) << 1;
+}
+
+/*
* Combine two effects and apply gain.
*/
static void ml_combine_effects(struct ff_effect *effect,
@@ -254,6 +270,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);
@@ -268,6 +297,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
next prev parent reply other threads:[~2009-12-23 13:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Jari Vanhala [this message]
2009-12-24 23:37 ` [PATCH v2] " Anssi Hannula
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=1261573094-26837-1-git-send-email-ext-jari.vanhala@nokia.com \
--to=ext-jari.vanhala@nokia.com \
--cc=anssi.hannula@iki.fi \
--cc=dmitry.torokhov@gmail.com \
--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).