From patchwork Fri Dec 4 13:05:13 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jari Vanhala X-Patchwork-Id: 64850 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nB4D5Ngf032381 for ; Fri, 4 Dec 2009 13:05:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756297AbZLDNFR (ORCPT ); Fri, 4 Dec 2009 08:05:17 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756337AbZLDNFQ (ORCPT ); Fri, 4 Dec 2009 08:05:16 -0500 Received: from smtp.nokia.com ([192.100.122.233]:53923 "EHLO mgw-mx06.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756297AbZLDNFP (ORCPT ); Fri, 4 Dec 2009 08:05:15 -0500 Received: from vaebh105.NOE.Nokia.com (vaebh105.europe.nokia.com [10.160.244.31]) by mgw-mx06.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id nB4D5FTo001896; Fri, 4 Dec 2009 15:05:19 +0200 Received: from esebh102.NOE.Nokia.com ([172.21.138.183]) by vaebh105.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 4 Dec 2009 15:05:16 +0200 Received: from mgw-sa01.ext.nokia.com ([147.243.1.47]) by esebh102.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Fri, 4 Dec 2009 15:05:16 +0200 Received: from localhost.localdomain (trdhcp147136.ntc.nokia.com [172.22.147.136]) by mgw-sa01.ext.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id nB4D5EEn009801; Fri, 4 Dec 2009 15:05:14 +0200 From: Jari Vanhala To: Dmitry Torokhov Cc: linux-input@vger.kernel.org, ext-jari.vanhala@nokia.com Subject: [PATCH] Input: Add direction to ff-memless Date: Fri, 4 Dec 2009 15:05:13 +0200 Message-Id: <1259931914-6228-1-git-send-email-ext-jari.vanhala@nokia.com> X-Mailer: git-send-email 1.6.3.3 X-OriginalArrivalTime: 04 Dec 2009 13:05:16.0120 (UTC) FILETIME=[6C425D80:01CA74E2] X-Nokia-AV: Clean Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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 =