From: Joe Perches <joe@perches.com>
To: "Michal Malý" <madcatxster@prifuk.cz>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org, anssi.hannula@iki.fi,
elias.vds@gmail.com
Subject: Re: [RFC v2] ff-memless-next driver
Date: Sat, 21 Dec 2013 15:05:01 -0800 [thread overview]
Message-ID: <1387667101.22671.6.camel@joe-AO722> (raw)
In-Reply-To: <2287724.uNI0tVeDgp@geidi-prime>
Refactoring can help reduce the line lengths.
For example:
Move the get_envelope function.
Use get_envelope in set_envelope_times.
---
drivers/input/ff-memless-next.c | 58 +++++++++++++++++++----------------------
1 file changed, 27 insertions(+), 31 deletions(-)
diff --git a/drivers/input/ff-memless-next.c b/drivers/input/ff-memless-next.c
index 722601a..73e1127 100644
--- a/drivers/input/ff-memless-next.c
+++ b/drivers/input/ff-memless-next.c
@@ -104,34 +104,46 @@ static int mlnx_upload_conditional(struct mlnx_device *mlnxdev,
return mlnxdev->control_effect(mlnxdev->dev, mlnxdev->private, &ecmd);
}
+static const struct ff_envelope *mlnx_get_envelope(const struct ff_effect *effect)
+{
+ static const struct ff_envelope empty;
+
+ switch (effect->type) {
+ case FF_CONSTANT:
+ return &effect->u.constant.envelope;
+ case FF_PERIODIC:
+ return &effect->u.periodic.envelope;
+ case FF_RAMP:
+ return &effect->u.ramp.envelope;
+ default:
+ return ∅
+ }
+}
+
static void mlnx_set_envelope_times(struct mlnx_effect *mlnxeff)
{
const struct ff_effect *effect = &mlnxeff->effect;
+ const struct ff_envelope *env;
switch (effect->type) {
- case FF_CONSTANT:
- if (effect->u.constant.envelope.attack_length)
- mlnxeff->attack_stop = mlnxeff->begin_at + msecs_to_jiffies(effect->u.constant.envelope.attack_length);
- if (effect->replay.length && effect->u.constant.envelope.fade_length)
- mlnxeff->fade_begin = mlnxeff->stop_at - msecs_to_jiffies(effect->u.constant.envelope.fade_length);
- break;
case FF_PERIODIC:
pr_debug("Phase: %u, Offset: %d\n",
effect->u.periodic.phase, effect->u.periodic.offset);
- if (effect->u.periodic.envelope.attack_length)
- mlnxeff->attack_stop = mlnxeff->begin_at + msecs_to_jiffies(effect->u.periodic.envelope.attack_length);
- if (effect->replay.length && effect->u.periodic.envelope.fade_length)
- mlnxeff->fade_begin = mlnxeff->stop_at - msecs_to_jiffies(effect->u.periodic.envelope.fade_length);
break;
+ case FF_CONSTANT:
case FF_RAMP:
- if (effect->u.ramp.envelope.attack_length)
- mlnxeff->attack_stop = mlnxeff->begin_at + msecs_to_jiffies(effect->u.ramp.envelope.attack_length);
- if (effect->replay.length && effect->u.ramp.envelope.fade_length)
- mlnxeff->fade_begin = mlnxeff->stop_at - msecs_to_jiffies(effect->u.ramp.envelope.fade_length);
break;
default:
- break;
+ return;
}
+
+ env = mlnx_get_envelope(effect);
+ if (env->attack_length)
+ mlnxeff->attack_stop = mlnxeff->begin_at +
+ msecs_to_jiffies(env->attack_length);
+ if (effect->replay.length && env->fade_length)
+ mlnxeff->fade_begin = mlnxeff->stop_at -
+ msecs_to_jiffies(env->fade_length);
}
static void mlnx_set_trip_times(struct mlnx_effect *mlnxeff,
@@ -185,22 +197,6 @@ static void mlnx_stop_effect(struct mlnx_device *mlnxdev,
}
}
-static const struct ff_envelope *mlnx_get_envelope(const struct ff_effect *effect)
-{
- static const struct ff_envelope empty;
-
- switch (effect->type) {
- case FF_CONSTANT:
- return &effect->u.constant.envelope;
- case FF_PERIODIC:
- return &effect->u.periodic.envelope;
- case FF_RAMP:
- return &effect->u.ramp.envelope;
- default:
- return ∅
- }
-}
-
static s32 mlnx_apply_envelope(const struct mlnx_effect *mlnxeff,
const s32 level)
{
prev parent reply other threads:[~2013-12-21 23:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-21 22:10 [RFC v2] ff-memless-next driver Michal Malý
2013-12-21 23:05 ` Joe Perches [this message]
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=1387667101.22671.6.camel@joe-AO722 \
--to=joe@perches.com \
--cc=anssi.hannula@iki.fi \
--cc=dmitry.torokhov@gmail.com \
--cc=elias.vds@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=madcatxster@prifuk.cz \
/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).