experimental new acceleration curve, start of look ahead, timer test

Change-Id: Ic716633565d9c4f88ae962fdfe80e4209bdcf88b
diff --git a/driver/multitouch.c b/driver/multitouch.c
old mode 100644
new mode 100755
index d1b744d..4ecac78
--- a/driver/multitouch.c
+++ b/driver/multitouch.c
@@ -27,8 +27,8 @@
 #endif
 
 /* these should be user-configurable at some point */
-static const float vscroll_fraction = 0.0017;
-static const float hscroll_fraction = 0.0017;
+static const float vscroll_fraction = 0.005;
+static const float hscroll_fraction = 0.005;
 static const float vswipe_fraction = 0.25;
 static const float hswipe_fraction = 0.25;
 static const float scale_fraction = 0.05;
@@ -84,7 +84,8 @@
 
 static int device_init(DeviceIntPtr dev, LocalDevicePtr local)
 {
-	struct MTouch *mt = local->private;
+	struct MTouchQueue *mq = local->private;
+	struct MTouch *mt = &mq->mt[0];
 	unsigned char btmap[DIM_BUTTON + 1] = {
 		0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
 	};
@@ -168,7 +169,8 @@
 
 static int device_off(LocalDevicePtr local)
 {
-	struct MTouch *mt = local->private;
+	struct MTouchQueue *mq = local->private;
+	struct MTouch *mt = &mq->mt[0];
 	xf86RemoveEnabledDevice(local);
 	if (close_mtouch(mt, local->fd))
 		xf86Msg(X_WARNING, "multitouch: cannot ungrab device\n");
@@ -286,7 +288,8 @@
 static void read_input(LocalDevicePtr local)
 {
 	struct Gestures gs;
-	struct MTouch *mt = local->private;
+	struct MTouchQueue *mq = local->private;
+	struct MTouch *mt = &mq->mt[0];
 	while (read_packet(mt, local->fd) > 0) {
 		extract_gestures(&gs, mt);
 		handle_gestures(local, &gs, &mt->caps);
@@ -322,19 +325,19 @@
 
 static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags)
 {
-	struct MTouch *mt;
+	struct MTouchQueue *mq;
 	InputInfoPtr local = xf86AllocateInput(drv, 0);
 	if (!local)
 		goto error;
-	mt = calloc(1, sizeof(struct MTouch));
-	if (!mt)
+	mq = calloc(1, sizeof(struct MTouchQueue));
+	if (!mq)
 		goto error;
 
 	local->name = dev->identifier;
 	local->type_name = XI_TOUCHPAD;
 	local->device_control = device_control;
 	local->read_input = read_input;
-	local->private = mt;
+	local->private = mq;
 	local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
 	local->conf_idev = dev;
 
diff --git a/include/gestures.h b/include/gestures.h
old mode 100644
new mode 100755
index dacb0ec..839af20
--- a/include/gestures.h
+++ b/include/gestures.h
@@ -43,6 +43,13 @@
 	mstime_t timedelta;
 };
 
+#define MTQ_LEN 3
+
+struct MTouchQueue {
+  struct MTouch mt[MTQ_LEN];
+  struct Gestures gs[MTQ_LEN];
+};
+
 void extract_gestures(struct Gestures *gs, struct MTouch* mt);
 void extract_delayed_gestures(struct Gestures *gs, struct MTouch* mt);
 void output_gesture(const struct Gestures *gs);
diff --git a/include/mtouch.h b/include/mtouch.h
old mode 100644
new mode 100755
diff --git a/src/gestures.c b/src/gestures.c
old mode 100644
new mode 100755
index c1163ac..8011060
--- a/src/gestures.c
+++ b/src/gestures.c
@@ -111,7 +111,7 @@
 	int two_pointers_close;
 	int npoint = bitcount(mt->mem.pointing);
 	if (mt->mem.tripletap) {
-		// fprintf(stderr, "tripletap scrolling mode\n");
+		fprintf(stderr, "tripletap scrolling mode\n");
 		mt->mem.state = kGsStateScrolling;
 	} else if (npoint == 1) {
 		int idx = firstbit(mt->mem.pointing);
@@ -143,7 +143,7 @@
 		if (two_pointers_close/* && mt->mem.state == kGsStateUnknown*/) {
 			// Should we switch to scrolling or pointing?
 			int newstate = is_two_finger_scroll(mt);
-			// fprintf(stderr, "2 finger scroll: %d\n", newstate);
+			fprintf(stderr, "2 finger scroll: %d\n", newstate);
 			if (newstate >= 0) {
 				mt->mem.state = (enum gs_state_t)newstate;
 			}
@@ -318,8 +318,14 @@
 	for (idx = 0; mag > boundary[idx]; idx++) {}
 	
 	newmag = mag * multiplier[idx] + intercept[idx];
+	if (mag < 5) {
+		newmag = 0.5 * mag * mag;
+	} else {
+		newmag = 5 * mag - 12.5;
+	}
 	float ratio = newmag / mag;
-	// fprintf(stderr, "mag: %f newmag: %f idx: %d ratio: %f\n", (double)mag, (double)newmag, idx, ratio);
+	
+	fprintf(stderr, "mag: %f newmag: %f idx: %d ratio: %f\n", (double)mag, (double)newmag, idx, ratio);
 
 	*x = xin * ratio / kOutDpi;
 	*y = yin * ratio / kOutDpi;
@@ -503,8 +509,8 @@
 	float xm[DIM_FINGER], ym[DIM_FINGER];
 	float xpos = 0, ypos = 0;  // mean x position, y position
 	int two_pointers_close = 0;  // if two fingers are near each other
-	// fprintf(stderr, "extract_movement: finger cnt: %d, mv cnd %d\n",
-	//   npoint, nmove);
+	fprintf(stderr, "extract_movement: finger cnt: %d, mv cnd %d, st %d\n",
+	  npoint, nmove, mt->mem.state);
 	
 	// xmove, ymove are the mean deltas from previous frame (movement).
 	// move is the magnitude of xmove and ymove vectors added
diff --git a/src/mtouch.c b/src/mtouch.c
old mode 100644
new mode 100755
index ba48994..614477a
--- a/src/mtouch.c
+++ b/src/mtouch.c
@@ -68,11 +68,22 @@
 	return 0;
 }
 
+CARD32 TimerCallback(OsTimerPtr timer, CARD32 now, pointer localdata) {
+	fprintf(stderr, "Timer callback! now %d, data %d\n", now, (int)localdata);
+	return 0;
+}
+
 int read_packet(struct MTouch *mt, int fd)
 {
 	int i;
 	int ret = modify_hwstate(&mt->hs, &mt->dev, fd, &mt->caps);
 	//fprintf(stderr, "modify_hwstate returned %d\n", ret);
+	static int did_timer_test = 0;
+	if (!did_timer_test) {
+		static OsTimerPtr timer;
+		timer = TimerSet(timer, 0, 4000, TimerCallback, 1);
+		did_timer_test = 1;
+	}
 	if (ret <= 0)
 		return ret;