#include "klgd_ff_plugin_p.h"
#include <linux/slab.h>
+static bool ffpl_has_gain(const struct ff_effect *eff);
static bool ffpl_replace_effect(const struct ff_effect *ac_eff, const struct ff_effect *la_eff);
/* Destroy request - input device is being destroyed */
return 0;
}
+
static void ffpl_set_gain_rq(struct input_dev *dev, u16 gain)
{
struct klgd_plugin *self = dev->ff->private;
+ struct klgd_plugin_private *priv = self->private;
+ size_t idx;
klgd_lock_plugins(self->plugins_lock);
- //TODO
printk(KERN_DEBUG "KLGDFF: Gain set, %u\n", gain);
- //
+ for (idx = 0; idx < priv->effect_count; idx++) {
+ struct ffpl_effect *eff = &priv->effects[idx];
+
+ if (ffpl_has_gain(eff->active))
+ eff->change = FFPL_TO_UPDATE;
+ }
+ priv->gain = gain;
klgd_unlock_plugins_sched(self->plugins_lock);
}
static struct klgd_command_stream * ffpl_get_commands(struct klgd_plugin *self, const unsigned long now)
{
struct klgd_plugin_private *priv = self->private;
+ struct input_dev *const dev = priv->dev;
struct klgd_command_stream *s;
size_t idx;
if (eff->replace) {
switch (eff->state) {
case FFPL_STARTED:
- klgd_append_cmd(s, priv->stop_effect(eff->active, idx));
+ klgd_append_cmd(s, priv->stop_effect(dev, eff->active, idx));
default:
- klgd_append_cmd(s, priv->erase_effect(eff->active, idx));
+ klgd_append_cmd(s, priv->erase_effect(dev, eff->active, idx));
kfree(eff->active);
eff->active = NULL;
break;
switch (eff->change) {
case FFPL_TO_UPLOAD:
case FFPL_TO_STOP:
- klgd_append_cmd(s, priv->upload_effect(eff->latest, idx));
+ klgd_append_cmd(s, priv->upload_effect(dev, eff->latest, idx));
eff->active = eff->latest;
eff->state = FFPL_UPLOADED;
break;
case FFPL_TO_START:
- klgd_append_cmd(s, priv->upload_effect(eff->latest, idx));
+ klgd_append_cmd(s, priv->upload_effect(dev, eff->latest, idx));
eff->active = eff->latest;
- klgd_append_cmd(s, priv->start_effect(eff->active, idx));
+ klgd_append_cmd(s, priv->start_effect(dev, eff->active, idx));
eff->state = FFPL_STARTED;
break;
default:
case FFPL_UPLOADED:
switch (eff->change) {
case FFPL_TO_START:
- klgd_append_cmd(s, priv->start_effect(eff->active, idx));
+ klgd_append_cmd(s, priv->start_effect(dev, eff->active, idx));
eff->state = FFPL_STARTED;
break;
case FFPL_TO_ERASE:
- klgd_append_cmd(s, priv->erase_effect(eff->active, idx));
+ klgd_append_cmd(s, priv->erase_effect(dev, eff->active, idx));
kfree(eff->active);
if (eff->active != eff->latest)
kfree(eff->latest);
eff->state = FFPL_EMPTY;
break;
case FFPL_TO_UPDATE:
- klgd_append_cmd(s, priv->upload_effect(eff->latest, idx));
+ klgd_append_cmd(s, priv->upload_effect(dev, eff->latest, idx));
eff->active = eff->latest;
break;
default:
case FFPL_STARTED:
switch (eff->change) {
case FFPL_TO_STOP:
- klgd_append_cmd(s, priv->stop_effect(eff->active, idx));
+ klgd_append_cmd(s, priv->stop_effect(dev, eff->active, idx));
eff->state = FFPL_UPLOADED;
break;
case FFPL_TO_ERASE:
- klgd_append_cmd(s, priv->stop_effect(eff->active, idx));
- klgd_append_cmd(s, priv->erase_effect(eff->active, idx));
+ klgd_append_cmd(s, priv->stop_effect(dev, eff->active, idx));
+ klgd_append_cmd(s, priv->erase_effect(dev, eff->active, idx));
kfree(eff->active);
if (eff->active != eff->latest)
kfree(eff->latest);
eff->state = FFPL_EMPTY;
break;
case FFPL_TO_UPDATE:
- klgd_append_cmd(s, priv->upload_effect(eff->latest, idx));
+ klgd_append_cmd(s, priv->upload_effect(dev, eff->latest, idx));
eff->active = eff->latest;
default:
break;
return events ? true : false;
}
+static bool ffpl_has_gain(const struct ff_effect *eff)
+{
+ switch (eff->type) {
+ case FF_CONSTANT:
+ case FF_PERIODIC:
+ case FF_RAMP:
+ case FF_RUMBLE:
+ return true;
+ default:
+ return false;
+ }
+}
+
static int ffpl_init(struct klgd_plugin *self)
{
struct klgd_plugin_private *priv = self->private;
/* Initialize the plugin */
int ffpl_init_plugin(struct klgd_plugin **plugin, struct input_dev *dev, const size_t effect_count,
const unsigned long supported_effects,
- struct klgd_command * (*upload)(const struct ff_effect *effect, const int id),
- struct klgd_command * (*start)(const struct ff_effect *effect, const int id),
- struct klgd_command * (*stop)(const struct ff_effect *effect, const int id),
- struct klgd_command * (*erase)(const struct ff_effect *effect, const int id))
+ struct klgd_command * (*upload)(struct input_dev *dev, const struct ff_effect *effect, const int id),
+ struct klgd_command * (*start)(struct input_dev *dev, const struct ff_effect *effect, const int id),
+ struct klgd_command * (*stop)(struct input_dev *dev, const struct ff_effect *effect, const int id),
+ struct klgd_command * (*erase)(struct input_dev *dev, const struct ff_effect *effect, const int id))
{
struct klgd_plugin *self;
struct klgd_plugin_private *priv;
int ffpl_init_plugin(struct klgd_plugin **plugin, struct input_dev *dev, const size_t effect_count,
const unsigned long supported_effects,
- struct klgd_command * (*upload)(const struct ff_effect *effect, const int id),
- struct klgd_command * (*play)(const struct ff_effect *effect, const int id),
- struct klgd_command * (*stop)(const struct ff_effect *effect, const int id),
- struct klgd_command * (*erase)(const struct ff_effect *effect, const int id));
+ struct klgd_command * (*upload)(struct input_dev *dev, const struct ff_effect *effect, const int id),
+ struct klgd_command * (*play)(struct input_dev *dev, const struct ff_effect *effect, const int id),
+ struct klgd_command * (*stop)(struct input_dev *dev, const struct ff_effect *effect, const int id),
+ struct klgd_command * (*erase)(struct input_dev *dev, const struct ff_effect *effect, const int id));
static struct klgd_main klgd;
static struct klgd_plugin *ff_plugin;
-static struct klgd_command * klgdff_erase(const struct ff_effect *effect, const int id)
+static struct klgd_command * klgdff_erase(struct input_dev *dev, const struct ff_effect *effect, const int id)
{
char *text = kasprintf(GFP_KERNEL, "Erasing effect, type %d, id %d", effect->type, id);
struct klgd_command *c = klgd_alloc_cmd(strlen(text) + 1);
return c;
}
-static struct klgd_command * klgdff_start(const struct ff_effect *effect, const int id)
+static struct klgd_command * klgdff_start(struct input_dev *de, const struct ff_effect *effect, const int id)
{
char *text = kasprintf(GFP_KERNEL, "Playing effect, type %d, id %d", effect->type, id);
struct klgd_command *c = klgd_alloc_cmd(strlen(text) + 1);
return c;
}
-static struct klgd_command * klgdff_stop(const struct ff_effect *effect, const int id)
+static struct klgd_command * klgdff_stop(struct input_dev *dev, const struct ff_effect *effect, const int id)
{
char *text = kasprintf(GFP_KERNEL, "Stopping effect, type %d, id %d", effect->type, id);
struct klgd_command *c = klgd_alloc_cmd(strlen(text) + 1);
return c;
}
-static struct klgd_command * klgdff_upload(const struct ff_effect *effect, const int id)
+static struct klgd_command * klgdff_upload(struct input_dev *dev, const struct ff_effect *effect, const int id)
{
char *text = kasprintf(GFP_KERNEL, "Uploading effect, type %d, id %d", effect->type, id);
struct klgd_command *c = klgd_alloc_cmd(strlen(text) + 1);