diff --git a/config.h b/config.h index 6d72c58..7fc26f8 100644 --- a/config.h +++ b/config.h @@ -12,5 +12,6 @@ #define WACOM "/dev/input/event0" #define MAX_SLOTS 7 //max touch points to track -#define TWOTAP_DISTANCE 700 //distance between the fingers to enable disable -#define JITTER 20 //finger displacement to be consideded a swipe +#define TWOTAP_DISTANCE 900 //distance between the fingers to enable disable +#define JITTER 10 //finger displacement to be consideded a swipe +#define SWIPE_VELOCITY 4 //swipe speed threshold diff --git a/eventreader.c b/eventreader.c index 95b0f64..2a23531 100644 --- a/eventreader.c +++ b/eventreader.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -91,8 +92,10 @@ void process_touch(void(*process)(struct TouchEvent *)){ f = &fingers[i]; if (f->status) { + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); struct TouchEvent event; - event.time = evt.time.tv_sec; + event.time = tv.tv_sec*1000+ tv.tv_nsec /1000000; event.slot = i; //enumerating slots event.x = f->x; event.y = f->y; diff --git a/eventreader.h b/eventreader.h index f642be7..15f5e9f 100644 --- a/eventreader.h +++ b/eventreader.h @@ -8,7 +8,7 @@ struct TouchEvent{ struct Point position; struct Point raw_position; - long time; + unsigned long time; enum FingerStatus status; }; diff --git a/gestures.c b/gestures.c index 39ba49f..b358b04 100644 --- a/gestures.c +++ b/gestures.c @@ -27,6 +27,7 @@ void recognize_gestures(struct TouchEvent *f) { if(keys_down < 0) keys_down = 0; //todo: fixit segments[slot].start.x = f->x; segments[slot].start.y = f->y; + segments[slot].start.time = f->time; keys_down++; segment_count++; @@ -39,6 +40,7 @@ void recognize_gestures(struct TouchEvent *f) { keys_down--; segments[slot].end.x = x; segments[slot].end.y = y; + segments[slot].end.time = f->time; //todo: extract gesture recognition @@ -46,24 +48,27 @@ void recognize_gestures(struct TouchEvent *f) { struct Gesture gesture; struct Segment *p = segments; int dx,dy,distance=0; + unsigned long dt; switch(segment_count){ + //single tap case 1: printf("Tap x:%d, y:%d raw_x:%d, raw_y:%d\n", f->x, f->y, f->raw_position.x, f->raw_position.y); dx = p->end.x - p->start.x; dy = p->end.y - p->start.y; + dt = p->end.time - p->start.time; + printf("delta dt %lu\n", dt); + distance = (int)sqrt(dx*dx+dy*dy); - if (abs(dx) < JITTER && - abs(dy) < JITTER){ + if (distance < JITTER) { int nav_stripe = SCREEN_WIDTH /3; - if (y > 100){//disable upper stripe + if (y > 100 && x > 100){//disable upper stripe and left menus if (x < nav_stripe) { if (y > SCREEN_HEIGHT - 150 && x < 150) { printf("TOC\n"); } else { - gesture.type = TapLeft; interpret_gesture(&gesture); } @@ -75,14 +80,17 @@ void recognize_gestures(struct TouchEvent *f) { } } else { + unsigned int velo = (10*distance) / (dt == 0 ? 1 : dt); + printf("velocity %d\n", velo); + if (velo < SWIPE_VELOCITY) //ignore slow swipes + break; //swipe if (abs(dx) > abs(dy)) { //horizontal if (dx < 0) { printf("swipe left\n"); - //todo: output gestures, extract executer - gesture.type = SwipeLeft; - interpret_gesture(&gesture); + gesture.type = SwipeLeft; + interpret_gesture(&gesture); } else { printf("swipe right\n"); diff --git a/keyinjector.c b/keyinjector.c index c0408a6..fb22d2f 100644 --- a/keyinjector.c +++ b/keyinjector.c @@ -12,8 +12,8 @@ #include "config.h" enum Key {Left=105, Right=106, Home=102,Power=116}; - -static bool touch_enabled = false; +enum TouchStatus {SwipeOnly, SwipeAndTouch,Disabled}; +static enum TouchStatus touch_status = SwipeOnly; int f; int w; void injector_init() { @@ -37,18 +37,18 @@ void move_pen(int x, int y, long time); void interpret_gesture(struct Gesture *g){ if (g->type == TwoTapWide) { - if (touch_enabled){ - show("touch navigation disabled"); - if (verbose) - printf("disabling\n"); - touch_enabled = false; - } - else { - show("touch navigation enabled"); - if(verbose) - printf("enabling\n"); - touch_enabled = true; - } + touch_status = ((int)touch_status + 1) % 3; //cycle the states + switch(touch_status) { + case SwipeOnly: + show("swipe only"); + break; + case Disabled: + show("touch disabled"); + break; + case SwipeAndTouch: + show("swipe and touch"); + break; + } return; } @@ -69,16 +69,22 @@ void interpret_gesture(struct Gesture *g){ } - if (!touch_enabled) + if (touch_status == Disabled) return; //require touch enabled switch(g->type){ case TapLeft: + if(touch_status != SwipeAndTouch) + break; + // fall through case SwipeRight: press_button(Left); break; case TapRight: + if(touch_status != SwipeAndTouch) + break; + // fall through case SwipeLeft: press_button(Right); break; diff --git a/point.h b/point.h index a213543..1f2bebe 100644 --- a/point.h +++ b/point.h @@ -1,4 +1,5 @@ #pragma once struct Point { int x,y; + int time; }; diff --git a/test.sh b/test.sh index 36fdce1..e42bb79 100755 --- a/test.sh +++ b/test.sh @@ -6,6 +6,6 @@ fi make || exit 1 ssh $DEVICE killall touchinjector -arm-poky-linux-gnueabi-strip bin/touchinjector +arm-oe-linux-gnueabi-strip bin/touchinjector scp bin/touchinjector $DEVICE:~/ && ssh -tt $DEVICE '/home/root/touchinjector' diff --git a/version.h b/version.h index 5419860..91b5b2d 100644 --- a/version.h +++ b/version.h @@ -1 +1 @@ -#define VERSION "0.0.2-19-g55385c9" +#define VERSION "0.0.3-9-g847192c"