]> Devoid-pointer.net GitWeb - KLGD_FF_plugin.git/commitdiff
- Add an option to have KLGD-FF control timing of condition effects
authorMichal Malý <madcatxster@devoid-pointer.net>
Sun, 16 Aug 2015 10:19:26 +0000 (12:19 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Sun, 16 Aug 2015 10:19:26 +0000 (12:19 +0200)
- Fix delay handling with memless effects

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

index 5b2f4cf9686b456fe06833283c0bad8acf5941b1..001d62b95baa85dbb3fb64ac7fc9c4a9198e8776 100644 (file)
@@ -20,7 +20,7 @@ void ffpl_lvl_dir_to_x_y(const s32 level, const u16 direction, s32 *x, s32 *y)
        *y = (level * fixp_sin16(degrees)) >> FRAC_16;
 }
 
-static bool ffpl_process_memless(const struct klgd_plugin_private *priv, const struct ff_effect *eff)
+inline static bool ffpl_process_memless(const struct klgd_plugin_private *priv, const struct ff_effect *eff)
 {
        switch (eff->type) {
        case FF_CONSTANT:
@@ -34,6 +34,23 @@ static bool ffpl_process_memless(const struct klgd_plugin_private *priv, const s
        }
 }
 
+inline static bool ffpl_handle_timing(const struct klgd_plugin_private *priv, const struct ff_effect *eff)
+{
+       if (priv->timing_condition) {
+               switch (eff->type) {
+               case FF_DAMPER:
+               case FF_FRICTION:
+               case FF_INERTIA:
+               case FF_SPRING:
+                       return true;
+               default:
+                       return false;
+               }
+       }
+
+       return ffpl_process_memless(priv, eff);
+}
+
 static const struct ff_envelope * ffpl_get_envelope(const struct ff_effect *ueff)
 {
        switch (ueff->type) {
@@ -570,7 +587,7 @@ static int ffpl_playback_rq(struct input_dev *dev, int effect_id, int value)
 
        eff->repeat = value;
        if (value > 0) {
-               if (ffpl_process_memless(priv, &eff->latest))
+               if (ffpl_handle_timing(priv, &eff->latest))
                        ffpl_calculate_trip_times(eff, now);
                else
                        eff->start_at = now; /* Start the effect right away and let the device deal with the timing */
@@ -864,6 +881,11 @@ static bool ffpl_needs_recalculation(const struct klgd_plugin_private *priv, con
        const struct ff_envelope *env = ffpl_get_envelope(ueff);
        bool ticks = ueff->type == FF_PERIODIC || ueff->type == FF_RAMP;
 
+       if (time_before(now, start_at)) {
+               printk(KERN_NOTICE "KLGDFF: Effect has not started yet\n");
+               return false;
+       }
+
        /* Only effects handled by memless mode can be periodically reprocessed */
        if (!ffpl_process_memless(priv, ueff)) {
                printk(KERN_NOTICE "KLGDFF: Effect not combinable, won't recalculate\n");
@@ -904,7 +926,7 @@ static void ffpl_advance_trigger(const struct klgd_plugin_private *priv, struct
                        eff->trigger = FFPL_TRIG_RECALC;
                        break;
                }
-               if (eff->latest.replay.length && ffpl_process_memless(priv, &eff->latest))
+               if (eff->latest.replay.length && ffpl_handle_timing(priv, &eff->latest))
                        eff->trigger = FFPL_TRIG_STOP;
                else
                        eff->trigger = FFPL_TRIG_NONE;
@@ -922,7 +944,7 @@ static void ffpl_advance_trigger(const struct klgd_plugin_private *priv, struct
                eff->trigger = FFPL_TRIG_NONE;
                break;
        case FFPL_TRIG_STOP:
-               if (eff->repeat > 0 && ffpl_process_memless(priv, &eff->active)) {
+               if (eff->repeat > 0 && ffpl_handle_timing(priv, &eff->active)) {
                        eff->trigger = FFPL_TRIG_RESTART;
                        break;
                }
@@ -1343,6 +1365,8 @@ int ffpl_init_plugin(struct klgd_plugin **plugin, struct input_dev *dev, const s
                priv->memless_periodic = true;
        if (FFPL_MEMLESS_RAMP & flags)
                priv->memless_ramp = true;
+       if (FFPL_TIMING_CONDITION & flags)
+               priv->timing_condition = true;
 
        if (FFPL_HAS_NATIVE_GAIN & flags) {
                priv->has_native_gain = true;
index ea96c7dd2612488358442058de314f71b2ef8125..e7c7e4c1f707879e8b8fde2f27f2dd35b47ff0d8 100644 (file)
 
 #define FFPL_MEMLESS_CONSTANT BIT(6)     /* Device cannot process FF_CONSTANT by itself and requires KLGD-FF to calculate overall force.
                                            Device must support FF_CONSTANT for this to work. */
-#define FFPL_MEMLESS_PERIODIC BIT(7) /* Device cannot process FF_PERIODIC by itself and requires KLGD-FF to calculate the overall force.
-                                       Device must support FF_CONSTANT for this to work. */
-#define FFPL_MEMLESS_RAMP BIT(8)     /* Device cannot process FF_RAMP by itself and requires KLGD-FF to calculate the overall force.
-                                       Device must support FF_CONSTANT for this to work. */
+#define FFPL_MEMLESS_PERIODIC BIT(7)    /* Device cannot process FF_PERIODIC by itself and requires KLGD-FF to calculate the overall force.
+                                           Device must support FF_CONSTANT for this to work. */
+#define FFPL_MEMLESS_RAMP BIT(8)        /* Device cannot process FF_RAMP by itself and requires KLGD-FF to calculate the overall force.
+                                           Device must support FF_CONSTANT for this to work. */
+#define FFPL_TIMING_CONDITION BIT(9)    /* Let the plugin take care of starting and stopping of condition effects */
 
 #define FFPL_HAS_NATIVE_GAIN BIT(15)  /* Device can adjust the gain by itself */
 #define FFPL_HAS_AUTOCENTER BIT(16) /* Device supports autocentering */
index a18d8cb2a8c0127cc852c375a07f85b97289d0e7..25f8dd76c7a5bb4c3e430480f8ff745b3045b270 100644 (file)
@@ -67,7 +67,8 @@ struct klgd_plugin_private {
        bool memless_constant;
        bool memless_periodic;
        bool memless_ramp;
-       u32 padding_caps:21;
+       bool timing_condition;
+       u32 padding_caps:20;
        /* Device-wide state changes */
        bool change_gain;
        bool change_autocenter;
index d988eeaee0b20ab793a45d40a1ec74461c8c09f2..83fe1606a367c1fc7bf1279aadacb8f9d1596833 100644 (file)
--- a/klgdff.c
+++ b/klgdff.c
@@ -356,7 +356,7 @@ static int __init klgdff_init(void)
        input_set_abs_params(dev, ABS_Y, -0x7fff, 0x7fff, 0, 0);
 
        ret = ffpl_init_plugin(&ff_plugin, dev, EFFECT_COUNT, ffbits,
-                              FFPL_HAS_EMP_TO_SRT | FFPL_REPLACE_STARTED | FFPL_HAS_AUTOCENTER | FFPL_MEMLESS_RAMP,
+                              FFPL_HAS_EMP_TO_SRT | FFPL_REPLACE_STARTED | FFPL_HAS_AUTOCENTER | FFPL_MEMLESS_RAMP | FFPL_TIMING_CONDITION,
                               klgdff_control, &test_user);
        if (ret) {
                printk(KERN_ERR "KLGDFF-TD: Cannot init plugin\n");