From 8010c8d6b762ebed514411c0c1eeef69a2af0f1a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Wed, 12 Aug 2015 01:45:33 +0200 Subject: [PATCH] Allow to pin arbitrary data to the plugin context --- klgd_ff_plugin.c | 22 ++++++++++++---------- klgd_ff_plugin.h | 3 ++- klgd_ff_plugin_p.h | 3 ++- klgdff.c | 14 ++++++-------- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/klgd_ff_plugin.c b/klgd_ff_plugin.c index 41240f9..2023541 100644 --- a/klgd_ff_plugin.c +++ b/klgd_ff_plugin.c @@ -358,7 +358,7 @@ static int ffpl_erase_effect(struct klgd_plugin_private *priv, struct klgd_comma data.effects.cur = &eff->active; data.effects.old = NULL; - ret = priv->control(dev, s, FFPL_UPL_TO_EMP, data); + ret = priv->control(dev, s, FFPL_UPL_TO_EMP, data, priv->user); if (ret) return ret; } @@ -378,7 +378,7 @@ static int ffpl_replace_effect(struct klgd_plugin_private *priv, struct klgd_com data.effects.cur = &eff->latest; data.effects.old = &eff->active; data.effects.repeat = eff->repeat; - ret = priv->control(dev, s, cmd, data); + ret = priv->control(dev, s, cmd, data, priv->user); if (!ret) { eff->active = eff->latest; eff->state = (cmd == FFPL_OWR_TO_UPL) ? FFPL_UPLOADED : FFPL_STARTED; @@ -405,7 +405,7 @@ static int ffpl_start_effect(struct klgd_plugin_private *priv, struct klgd_comma else cmd = FFPL_EMP_TO_SRT; - ret = priv->control(dev, s, cmd, data); + ret = priv->control(dev, s, cmd, data, priv->user); if (ret) return ret; } else { @@ -418,7 +418,7 @@ static int ffpl_start_effect(struct klgd_plugin_private *priv, struct klgd_comma cmd = FFPL_UPL_TO_SRT; } - ret = priv->control(dev, s, cmd, data); + ret = priv->control(dev, s, cmd, data, priv->user); if (ret) return ret; if (cmd == FFPL_EMP_TO_SRT) @@ -444,7 +444,7 @@ static int ffpl_stop_effect(struct klgd_plugin_private *priv, struct klgd_comman else cmd = FFPL_SRT_TO_UPL; - ret = priv->control(dev, s, cmd, data); + ret = priv->control(dev, s, cmd, data, priv->user); if (ret) return ret; if (cmd == FFPL_SRT_TO_EMP) @@ -470,7 +470,7 @@ static int ffpl_update_effect(struct klgd_plugin_private *priv, struct klgd_comm data.effects.cur = &eff->latest; data.effects.old = NULL; - ret = priv->control(dev, s, FFPL_SRT_TO_UDT, data); + ret = priv->control(dev, s, FFPL_SRT_TO_UDT, data, priv->user); if (ret) return ret; eff->active = eff->latest; @@ -486,7 +486,7 @@ static int ffpl_upload_effect(struct klgd_plugin_private *priv, struct klgd_comm data.effects.cur = &eff->latest; data.effects.old = NULL; - ret = priv->control(dev, s, FFPL_EMP_TO_UPL, data); + ret = priv->control(dev, s, FFPL_EMP_TO_UPL, data, priv->user); if (ret) return ret; eff->uploaded_to_device = true; @@ -502,7 +502,7 @@ static int ffpl_set_autocenter(struct klgd_plugin_private *priv, struct klgd_com union ffpl_control_data data; data.autocenter = priv->autocenter; - return priv->control(priv->dev, s, FFPL_SET_AUTOCENTER, data); + return priv->control(priv->dev, s, FFPL_SET_AUTOCENTER, data, priv->user); } static int ffpl_set_gain(struct klgd_plugin_private *priv, struct klgd_command_stream *s) @@ -510,7 +510,7 @@ static int ffpl_set_gain(struct klgd_plugin_private *priv, struct klgd_command_s union ffpl_control_data data; data.gain = priv->gain; - return priv->control(priv->dev, s, FFPL_SET_GAIN, data); + return priv->control(priv->dev, s, FFPL_SET_GAIN, data, priv->user); } static void ffpl_calculate_trip_times(struct ffpl_effect *eff, const unsigned long now) @@ -1257,7 +1257,8 @@ static int ffpl_init(struct klgd_plugin *self) int ffpl_init_plugin(struct klgd_plugin **plugin, struct input_dev *dev, const size_t effect_count, const unsigned long supported_effects, const unsigned long flags, - int (*control)(struct input_dev *dev, struct klgd_command_stream *s, const enum ffpl_control_command cmd, const union ffpl_control_data data)) + int (*control)(struct input_dev *dev, struct klgd_command_stream *s, const enum ffpl_control_command cmd, const union ffpl_control_data data, void *user), + void *user) { struct klgd_plugin *self; struct klgd_plugin_private *priv; @@ -1293,6 +1294,7 @@ int ffpl_init_plugin(struct klgd_plugin **plugin, struct input_dev *dev, const s priv->effect_count = effect_count; priv->dev = dev; priv->control = control; + priv->user = user; priv->gain = 0xFFFF; self->private = priv; diff --git a/klgd_ff_plugin.h b/klgd_ff_plugin.h index 90aa9b5..c359879 100644 --- a/klgd_ff_plugin.h +++ b/klgd_ff_plugin.h @@ -58,4 +58,5 @@ void ffpl_lvl_dir_to_x_y(const s32 level, const u16 direction, s32 *x, s32 *y); int ffpl_init_plugin(struct klgd_plugin **plugin, struct input_dev *dev, const size_t effect_count, const unsigned long supported_effects, const unsigned long flags, - int (*control)(struct input_dev *dev, struct klgd_command_stream *s, const enum ffpl_control_command cmd, const union ffpl_control_data data)); + int (*control)(struct input_dev *dev, struct klgd_command_stream *s, const enum ffpl_control_command cmd, const union ffpl_control_data data, void *user), + void *user); diff --git a/klgd_ff_plugin_p.h b/klgd_ff_plugin_p.h index e23b649..74eaa22 100644 --- a/klgd_ff_plugin_p.h +++ b/klgd_ff_plugin_p.h @@ -51,7 +51,8 @@ struct klgd_plugin_private { unsigned long supported_effects; size_t effect_count; struct input_dev *dev; - int (*control)(struct input_dev *dev, struct klgd_command_stream *s, const enum ffpl_control_command cmd, const union ffpl_control_data data); + int (*control)(struct input_dev *dev, struct klgd_command_stream *s, const enum ffpl_control_command cmd, const union ffpl_control_data data, void *user); + void *user; u16 gain; u16 autocenter; /* Optional device capabilities */ diff --git a/klgdff.c b/klgdff.c index f6eeae3..ee4ac65 100644 --- a/klgdff.c +++ b/klgdff.c @@ -14,6 +14,7 @@ static struct klgd_main klgd; static struct klgd_plugin *ff_plugin; static u16 gain; static u16 autocenter; +static u32 test_user = 0xC001CAFE; static int klgdff_erase(struct klgd_command_stream *s, const struct ff_effect *effect) { @@ -239,7 +240,7 @@ int klgdff_callback(void *data, const struct klgd_command_stream *s) for (idx = 0; idx < s->count; idx++) { printk(KERN_NOTICE "KLGDFF-TD: EFF %s\n", s->commands[idx]->bytes); if (s->commands[idx]->user.data[0]) - printk("KLGDFF-TD: User 0x%X\n", s->commands[idx]->user.data[0]); + printk(KERN_NOTICE "KLGDFF-TD: User1 0x%X\n", s->commands[idx]->user.data[0]); } /* Simulate default USB polling rate of 125 Hz */ @@ -250,16 +251,13 @@ int klgdff_callback(void *data, const struct klgd_command_stream *s) return 0; } -int klgdff_control(struct input_dev *dev, struct klgd_command_stream *s, const enum ffpl_control_command cmd, const union ffpl_control_data data) +int klgdff_control(struct input_dev *dev, struct klgd_command_stream *s, const enum ffpl_control_command cmd, + const union ffpl_control_data data, void *user) { if (!s) return -EINVAL; - if (!data.effects.cur) { - printk(KERN_WARNING "KLGDFF-TM: NULL effect, this _cannot_ happen!\n"); - return -EINVAL; - } - + printk(KERN_NOTICE "KLGDFF-TD: User data: 0x%X\n", *(u32 *)user); switch (cmd) { case FFPL_EMP_TO_UPL: return klgdff_upload(s, data.effects.cur); @@ -359,7 +357,7 @@ static int __init klgdff_init(void) ret = ffpl_init_plugin(&ff_plugin, dev, EFFECT_COUNT, ffbits, FFPL_HAS_EMP_TO_SRT | FFPL_REPLACE_STARTED | FFPL_HAS_AUTOCENTER | FFPL_MEMLESS_MODE, - klgdff_control); + klgdff_control, &test_user); if (ret) { printk(KERN_ERR "KLGDFF-TD: Cannot init plugin\n"); goto errout_idev; -- 2.43.5