[PATCH synaptics v2 08/21] Introduce POLL_MS for packet frequency

Daniel Stone daniel at fooishbar.org
Tue Jun 14 10:05:56 PDT 2011


We expect to be receiving a steady 80 packets/sec (which gives 40
reports/sec with more than one finger on the pad, as Advanced Gesture
Mode requires two PS/2 packets per report).  Instead of a random
scattering of magic 13 and 20ms numbers scattered throughout the driver,
introduce POLL_MS as 14ms.

Having this here allows us to call back at a steady frequency to ensure
that the finger motion remains steady.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 src/synaptics.c |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)

v2: Fairly extensive commentary added.

diff --git a/src/synaptics.c b/src/synaptics.c
index e863081..95faa42 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -92,6 +92,21 @@ typedef enum {
     LEFT_TOP_EDGE = TOP_EDGE | LEFT_EDGE
 } edge_type;
 
+/*
+ * We expect to be receiving a steady 80 packets/sec (which gives 40
+ * reports/sec with more than one finger on the pad, as Advanced Gesture Mode
+ * requires two PS/2 packets per report).  Instead of a random scattering of
+ * magic 13 and 20ms numbers scattered throughout the driver, introduce
+ * POLL_MS as 14ms, which is slightly less than 80Hz.  13ms is closer to
+ * 80Hz, but if the kernel event reporting was even slightly delayed,
+ * we would produce synthetic motion followed immediately by genuine
+ * motion, so use 14.
+ *
+ * We use this to call back at a constant rate to at least produce the
+ * illusion of smooth motion.  It works a lot better than you'd expect.
+*/
+#define POLL_MS 14
+
 #define MAX(a, b) (((a)>(b))?(a):(b))
 #define MIN(a, b) (((a)<(b))?(a):(b))
 #define TIME_DIFF(a, b) ((int)((a)-(b)))
@@ -1858,9 +1873,10 @@ ComputeDeltas(SynapticsPrivate *priv, const struct SynapticsHwState *hw,
         goto out;
     }
 
-    /* to create fluid edge motion, call back 'soon'
-     * even in the absence of new hardware events */
-    delay = MIN(delay, 13);
+    /* To create the illusion of fluid motion, call back at roughly the report
+     * rate, even in the absence of new hardware events; see comment above
+     * POLL_MS declaration. */
+    delay = MIN(delay, POLL_MS);
 
     if (priv->count_packet_finger <= 3) /* min. 3 packets, see get_delta() */
         goto skip; /* skip the lot */
@@ -2202,7 +2218,7 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 	double dtime = (hw->millis - HIST(0).millis) / 1000.0;
 	double ddy = para->coasting_friction * dtime;
 	priv->autoscroll_y += priv->autoscroll_yspd * dtime;
-	delay = MIN(delay, 20);
+	delay = MIN(delay, POLL_MS);
 	while (priv->autoscroll_y > 1.0) {
 	    sd->down++;
 	    priv->autoscroll_y -= 1.0;
@@ -2223,7 +2239,7 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 	double dtime = (hw->millis - HIST(0).millis) / 1000.0;
 	double ddx = para->coasting_friction * dtime;
 	priv->autoscroll_x += priv->autoscroll_xspd * dtime;
-	delay = MIN(delay, 20);
+	delay = MIN(delay, POLL_MS);
 	while (priv->autoscroll_x > 1.0) {
 	    sd->right++;
 	    priv->autoscroll_x -= 1.0;
-- 
1.7.5.3



More information about the xorg-devel mailing list