diff options
| author | Jari Vanhala <ext-jari.vanhala@nokia.com> | 2009-12-25 00:52:20 -0500 |
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2009-12-25 00:54:29 -0500 |
| commit | 94ec26c855bc675259e4f1658673f458040affd7 (patch) | |
| tree | a5af53ce488e6f0b8e5ca521ebc861a96ed1ffa8 | |
| parent | 1b11c88d3e8f55dc9d193d19de11e3f7abc1b7d7 (diff) | |
Input: ff-memless - add notion of direction to for rumble effects
This adds simple direction calculation when combining effects. It's useful
to decide motor direction for rumble (vibrator).
Signed-off-by: Jari Vanhala <ext-jari.vanhala@nokia.com>
Acked-by: Anssi Hannula <anssi.hannula@iki.fi>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
| -rw-r--r-- | 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 9667a5fd6bd7..f967008f332e 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) | |||
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | /* | 223 | /* |
| 224 | * Only left/right direction should be used (under/over 0x8000) for | ||
| 225 | * forward/reverse motor direction (to keep calculation fast & simple). | ||
| 226 | */ | ||
| 227 | static u16 ml_calculate_direction(u16 direction, u16 force, | ||
| 228 | u16 new_direction, u16 new_force) | ||
| 229 | { | ||
| 230 | if (!force) | ||
| 231 | return new_direction; | ||
| 232 | if (!new_force) | ||
| 233 | return direction; | ||
| 234 | return (((u32)(direction >> 1) * force + | ||
| 235 | (new_direction >> 1) * new_force) / | ||
| 236 | (force + new_force)) << 1; | ||
| 237 | } | ||
| 238 | |||
| 239 | /* | ||
| 224 | * Combine two effects and apply gain. | 240 | * Combine two effects and apply gain. |
| 225 | */ | 241 | */ |
| 226 | static void ml_combine_effects(struct ff_effect *effect, | 242 | static void ml_combine_effects(struct ff_effect *effect, |
| @@ -254,6 +270,19 @@ static void ml_combine_effects(struct ff_effect *effect, | |||
| 254 | case FF_RUMBLE: | 270 | case FF_RUMBLE: |
| 255 | strong = (u32)new->u.rumble.strong_magnitude * gain / 0xffff; | 271 | strong = (u32)new->u.rumble.strong_magnitude * gain / 0xffff; |
| 256 | weak = (u32)new->u.rumble.weak_magnitude * gain / 0xffff; | 272 | weak = (u32)new->u.rumble.weak_magnitude * gain / 0xffff; |
| 273 | |||
| 274 | if (effect->u.rumble.strong_magnitude + strong) | ||
| 275 | effect->direction = ml_calculate_direction( | ||
| 276 | effect->direction, | ||
| 277 | effect->u.rumble.strong_magnitude, | ||
| 278 | new->direction, strong); | ||
| 279 | else if (effect->u.rumble.weak_magnitude + weak) | ||
| 280 | effect->direction = ml_calculate_direction( | ||
| 281 | effect->direction, | ||
| 282 | effect->u.rumble.weak_magnitude, | ||
| 283 | new->direction, weak); | ||
| 284 | else | ||
| 285 | effect->direction = 0; | ||
| 257 | effect->u.rumble.strong_magnitude = | 286 | effect->u.rumble.strong_magnitude = |
| 258 | min(strong + effect->u.rumble.strong_magnitude, | 287 | min(strong + effect->u.rumble.strong_magnitude, |
| 259 | 0xffffU); | 288 | 0xffffU); |
| @@ -268,6 +297,13 @@ static void ml_combine_effects(struct ff_effect *effect, | |||
| 268 | /* here we also scale it 0x7fff => 0xffff */ | 297 | /* here we also scale it 0x7fff => 0xffff */ |
| 269 | i = i * gain / 0x7fff; | 298 | i = i * gain / 0x7fff; |
| 270 | 299 | ||
| 300 | if (effect->u.rumble.strong_magnitude + i) | ||
| 301 | effect->direction = ml_calculate_direction( | ||
| 302 | effect->direction, | ||
| 303 | effect->u.rumble.strong_magnitude, | ||
| 304 | new->direction, i); | ||
| 305 | else | ||
| 306 | effect->direction = 0; | ||
| 271 | effect->u.rumble.strong_magnitude = | 307 | effect->u.rumble.strong_magnitude = |
| 272 | min(i + effect->u.rumble.strong_magnitude, 0xffffU); | 308 | min(i + effect->u.rumble.strong_magnitude, 0xffffU); |
| 273 | effect->u.rumble.weak_magnitude = | 309 | effect->u.rumble.weak_magnitude = |
