]> Devoid-pointer.net GitWeb - KLGD_FF_plugin.git/commitdiff
- Preliminary gain adjustment support
authorMichal Malý <madcatxster@devoid-pointer.net>
Mon, 25 Aug 2014 14:15:33 +0000 (16:15 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Mon, 25 Aug 2014 14:15:33 +0000 (16:15 +0200)
- Expose struct input_dev to command building callbacks

klgd_ff_plugin.c
klgd_ff_plugin.h
klgd_ff_plugin_p.h
klgdff.c

index a6e9366318c62394919aa39b84a7d2e4e63a25af..3434e2731d45bd5c502c3014b077d62b8cd0afc9 100644 (file)
@@ -2,6 +2,7 @@
 #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 */
@@ -90,15 +91,23 @@ static int ffpl_upload_rq(struct input_dev *dev, struct ff_effect *effect, struc
        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);
 }
@@ -111,6 +120,7 @@ static void ffpl_deinit(struct klgd_plugin *self)
 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;
 
@@ -130,9 +140,9 @@ static struct klgd_command_stream * ffpl_get_commands(struct klgd_plugin *self,
                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;
@@ -153,14 +163,14 @@ static struct klgd_command_stream * ffpl_get_commands(struct klgd_plugin *self,
                        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:
@@ -170,11 +180,11 @@ static struct klgd_command_stream * ffpl_get_commands(struct klgd_plugin *self,
                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);
@@ -183,7 +193,7 @@ static struct klgd_command_stream * ffpl_get_commands(struct klgd_plugin *self,
                                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:
@@ -193,12 +203,12 @@ static struct klgd_command_stream * ffpl_get_commands(struct klgd_plugin *self,
                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);
@@ -207,7 +217,7 @@ static struct klgd_command_stream * ffpl_get_commands(struct klgd_plugin *self,
                                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;
@@ -238,6 +248,19 @@ static bool ffpl_get_update_time(struct klgd_plugin *self, const unsigned long n
        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;
@@ -262,10 +285,10 @@ static int ffpl_init(struct klgd_plugin *self)
 /* 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;
index f6eaf527e6043bc542d2914438d99e415bb3eb0c..0ad1e33e140bf49700bc8d545157ae7929f8c954 100644 (file)
@@ -5,7 +5,7 @@
 
 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));
index 6b4c5ffcc00b354d5e54d9144f33c726bf690780..6823991415e93da21453632d5333010043feed52 100644 (file)
@@ -28,9 +28,10 @@ struct klgd_plugin_private {
        struct ffpl_effect *effects;
        unsigned long supported_effects;
        size_t effect_count;
+       u16 gain;
        struct input_dev *dev;
-       struct klgd_command * (*upload_effect)(const struct ff_effect *effect, const int id);
-       struct klgd_command * (*start_effect)(const struct ff_effect *effect, const int id);
-       struct klgd_command * (*stop_effect)(const struct ff_effect *effect, const int id);
-       struct klgd_command * (*erase_effect)(const struct ff_effect *effect, const int id);
+       struct klgd_command * (*upload_effect)(struct input_dev *dev, const struct ff_effect *effect, const int id);
+       struct klgd_command * (*start_effect)(struct input_dev *dev, const struct ff_effect *effect, const int id);
+       struct klgd_command * (*stop_effect)(struct input_dev *dev, const struct ff_effect *effect, const int id);
+       struct klgd_command * (*erase_effect)(struct input_dev *dev, const struct ff_effect *effect, const int id);
 };
index a5e31ebd672de103275e169120ae2fd300b095e3..c0fae08ae553309a8aba4a4c878958d4b1b96608 100644 (file)
--- a/klgdff.c
+++ b/klgdff.c
@@ -13,7 +13,7 @@ static struct input_dev *dev;
 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);
@@ -21,7 +21,7 @@ static struct klgd_command * klgdff_erase(const struct ff_effect *effect, const
        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);
@@ -29,7 +29,7 @@ static struct klgd_command * klgdff_start(const struct ff_effect *effect, const
        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);
@@ -37,7 +37,7 @@ static struct klgd_command * klgdff_stop(const struct ff_effect *effect, const i
        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);