From b76660d71e2ea77752025089bd71deffad64e325 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Mon, 26 Jul 2010 13:51:34 +0200 Subject: Test implementation of grail api This patch introduces the grail API, and a program to test it (evlink). Signed-off-by: Henrik Rydberg --- src/Makefile.am | 4 +- src/gesture-client.c | 2 +- src/gesture-dev.c | 2 +- src/grail-api.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/touch-dev.c | 6 +- src/touch-engine.c | 9 ++- 6 files changed, 165 insertions(+), 9 deletions(-) create mode 100644 src/grail-api.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 7ccacae..50a5afd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,7 +8,8 @@ libgrail_la_SOURCES = \ touch-dev.c \ touch-engine.c \ gesture-client.c \ - gesture-dev.c + gesture-dev.c \ + grail-api.c AM_CFLAGS = $(CWARNFLAGS) -std=c99 @@ -17,4 +18,5 @@ INCLUDES = -I$(top_srcdir)/include/ libgrailincludedir = $(includedir) libgrailinclude_HEADERS = \ $(top_srcdir)/include/grail-touch.h \ + $(top_srcdir)/include/grail-gesture.h \ $(top_srcdir)/include/grail.h diff --git a/src/gesture-client.c b/src/gesture-client.c index 78328b7..91f1530 100644 --- a/src/gesture-client.c +++ b/src/gesture-client.c @@ -22,7 +22,7 @@ * ****************************************************************************/ -#include +#include #include #include #include diff --git a/src/gesture-dev.c b/src/gesture-dev.c index 8dd11a9..46c77d7 100644 --- a/src/gesture-dev.c +++ b/src/gesture-dev.c @@ -22,7 +22,7 @@ * ****************************************************************************/ -#include +#include #include #include #include diff --git a/src/grail-api.c b/src/grail-api.c new file mode 100644 index 0000000..dbe4977 --- /dev/null +++ b/src/grail-api.c @@ -0,0 +1,151 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +struct grail_impl { + struct touch_dev dev; + struct touch_engine engine; + struct touch_frame frame; + struct gesture_dev gedev; + struct gesture_client client; + touch_time_t last_scroll; +}; + +static void gh_handle(struct grail_impl *gh, + const struct touch_frame *frame, + touch_time_t time) +{ +#if 0 + struct gesture_flag flag; + struct grail_event ev; + if (frame->ntouch == 1 || frame->ntouch == 2) { + flag.type = GE_MOVE; + flag.time = time; + flag.state = GS_BEGIN; + gedev_flag(&gh->dev, &flag); + + ev.type = GE_MOVE; + ev.time = time; + ev.prop[0] = + frame->touch[0].prop[TP_POS_X] - + gh->frame.touch[0].prop[TP_POS_X]; + ev.prop[1] = + frame->touch[0].prop[TP_POS_Y] - + gh->frame.touch[0].prop[TP_POS_Y]; + if (ev.prop[0] || ev.prop[1]) + gedev_event(&gh->dev, &ev); + + flag.time = time + 1; + flag.state = GS_END; + gedev_flag(&gh->dev, &flag); + } + if (frame->ntouch == 2) { + flag.type = GE_VSCROLL; + flag.time = time; + flag.state = GS_BEGIN; + gedev_flag(&gh->dev, &flag); + + ev.type = GE_VSCROLL; + ev.time = time; + ev.prop[0] = + frame->touch[0].prop[TP_POS_Y] - + gh->frame.touch[0].prop[TP_POS_Y]; + + if (ev.prop[0]) + gedev_event(&gh->dev, &ev); + + if (time > gh->last_scroll + 100) { + flag.time = time + 1; + flag.state = GS_END; + gedev_flag(&gh->dev, &flag); + gh->last_scroll = time; + } + } else { + flag.type = GE_VSCROLL; + flag.time = time; + flag.state = GS_CANCEL; + gedev_flag(&gh->dev, &flag); + } + gedev_sync(&gh->dev); + gh->frame = *frame; +#endif +} + +static void tp_event(struct touch_engine *engine, + const struct input_event *ev) +{ + struct grail *ge = engine->priv; + if (ge->event) + ge->event(ge, ev); +} + +static void tp_sync(struct touch_engine *engine, + const struct input_event *syn) +{ + struct grail *ge = engine->priv; +#if 0 + struct touch_frame *frame = &engine->frame; + gh_handle(ge, frame, frame->time); +#endif + if (ge->event) + ge->event(ge, syn); +} + +int grail_open(struct grail *ge, int fd) +{ + struct grail_impl *x; + int ret; + x = calloc(1, sizeof(*x)); + if (!x) + return -ENOMEM; + ret = touch_dev_open(&x->dev, fd); + if (ret) + goto error; + touch_engine_init(&x->engine, tp_event, tp_sync, ge); + touch_engine_attach(&x->engine, &x->dev); + ge->impl = x; + return 0; + error: + free(x); + return ret; +} + +int grail_idle(struct grail *ge, int fd, int ms) +{ + struct grail_impl *x = ge->impl; + return touch_dev_idle(&x->dev, fd, ms); +} + +int grail_pull(struct grail *ge, int fd) +{ + struct grail_impl *x = ge->impl; + return touch_dev_pull(&x->dev, fd); +} + +void grail_close(struct grail *ge, int fd) +{ + struct grail_impl *x = ge->impl; + touch_engine_detach(&x->engine, &x->dev); + touch_dev_close(&x->dev, fd); + free(ge->impl); + ge->impl = 0; +} + +void grail_add_client(struct grail *ge, grail_clientid_t id, + const int *types, const int *priority, int ntypes) +{ + struct grail_impl *x = ge->impl; + //gedev_attach_client(&x->dev, &x->client); +} + +void grail_remove_client(struct grail *ge, grail_clientid_t id) +{ + struct grail_impl *x = ge->impl; + //gedev_detach_client(&x->dev, &x->client); +} + diff --git a/src/touch-dev.c b/src/touch-dev.c index 80cc82f..dc23baa 100644 --- a/src/touch-dev.c +++ b/src/touch-dev.c @@ -65,11 +65,9 @@ static void finish_touch(struct touch_dev *dev, static void finish_packet(struct touch_dev *dev, const struct input_event *syn) { - static const touch_time_t ms = 1000; - touch_time_t time = syn->time.tv_usec / ms + syn->time.tv_sec * ms; finish_touch(dev, dev->impl); if (dev->sync) - dev->sync(dev, time); + dev->sync(dev, syn); } static int handle_abs_event(struct touch_dev *dev, @@ -133,6 +131,8 @@ int touch_dev_open(struct touch_dev *dev, int fd) if (!x) return -ENOMEM; ret = mtdev_open(&x->mtdev, fd); + if (!ret && !x->mtdev.caps.has_mtdata) + ret = -ENODEV; if (ret) goto error; for (i = 0; i < DIM_TOUCH; i++) diff --git a/src/touch-engine.c b/src/touch-engine.c index 6174e0d..8e43faf 100644 --- a/src/touch-engine.c +++ b/src/touch-engine.c @@ -94,13 +94,15 @@ static void tp_destroy(struct touch_dev *dev, int slot) } } -static void tp_sync(struct touch_dev *dev, touch_time_t time) +static void tp_sync(struct touch_dev *dev, const struct input_event *syn) { + static const touch_time_t ms = 1000; struct touch_engine *engine = dev->priv; + touch_time_t time = syn->time.tv_usec / ms + syn->time.tv_sec * ms; if (engine) { finalize_frame(&engine->frame, time); if (engine->sync) - engine->sync(engine); + engine->sync(engine, syn); engine->frame.ncreate = 0; engine->frame.nmodify = 0; engine->frame.ndestroy = 0; @@ -110,7 +112,8 @@ static void tp_sync(struct touch_dev *dev, touch_time_t time) void touch_engine_init(struct touch_engine *engine, void (*event)(struct touch_engine *engine, const struct input_event *ev), - void (*sync)(struct touch_engine *engine), + void (*sync)(struct touch_engine *engine, + const struct input_event *ev), void *priv) { memset(engine, 0, sizeof(*engine)); -- cgit v1.2.3