diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2010-08-06 21:11:17 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-08-06 21:11:17 +0200 |
| commit | 7db9d8d76ff61c4802ac15559dcea6fa54ff567a (patch) | |
| tree | b67e040c0abeb0ab1fca72754a767dc9ab851461 /src/grail-api.c | |
initial bzr repo at rev 27
Diffstat (limited to 'src/grail-api.c')
| -rw-r--r-- | src/grail-api.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/grail-api.c b/src/grail-api.c new file mode 100644 index 0000000..9ceb1e7 --- /dev/null +++ b/src/grail-api.c | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | #include "grail-inserter.h" | ||
| 2 | #include "grail-recognizer.h" | ||
| 3 | #include <grail.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <unistd.h> | ||
| 7 | #include <fcntl.h> | ||
| 8 | #include <malloc.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include "evbuf.h" | ||
| 11 | |||
| 12 | struct grail_impl { | ||
| 13 | struct touch_dev dev; | ||
| 14 | struct touch_engine engine; | ||
| 15 | struct evbuf evbuf; | ||
| 16 | }; | ||
| 17 | |||
| 18 | static void tp_event(struct touch_engine *engine, | ||
| 19 | const struct input_event *ev) | ||
| 20 | { | ||
| 21 | struct grail *ge = engine->priv; | ||
| 22 | struct grail_impl *x = ge->impl; | ||
| 23 | evbuf_put(&x->evbuf, ev); | ||
| 24 | } | ||
| 25 | |||
| 26 | static void tp_sync(struct touch_engine *engine, | ||
| 27 | const struct input_event *syn) | ||
| 28 | { | ||
| 29 | struct input_event ev; | ||
| 30 | struct grail *ge = engine->priv; | ||
| 31 | struct grail_impl *x = ge->impl; | ||
| 32 | struct touch_frame *frame = &engine->frame; | ||
| 33 | grail_mask_t filtered[DIM_EV_TYPE_BYTES]; | ||
| 34 | int nevent = 0; | ||
| 35 | gin_frame_begin(ge, frame); | ||
| 36 | gru_recognize(ge, frame); | ||
| 37 | gin_frame_end(ge, filtered, sizeof(filtered), frame); | ||
| 38 | if (!ge->event) { | ||
| 39 | evbuf_clear(&x->evbuf); | ||
| 40 | return; | ||
| 41 | } | ||
| 42 | while (!evbuf_empty(&x->evbuf)) { | ||
| 43 | evbuf_get(&x->evbuf, &ev); | ||
| 44 | if (grail_mask_get(filtered, ev.type)) | ||
| 45 | continue; | ||
| 46 | ge->event(ge, &ev); | ||
| 47 | nevent++; | ||
| 48 | } | ||
| 49 | if (nevent) | ||
| 50 | ge->event(ge, syn); | ||
| 51 | } | ||
| 52 | |||
| 53 | int grail_open(struct grail *ge, int fd) | ||
| 54 | { | ||
| 55 | struct grail_impl *x; | ||
| 56 | int ret; | ||
| 57 | x = calloc(1, sizeof(*x)); | ||
| 58 | if (!x) | ||
| 59 | return -ENOMEM; | ||
| 60 | ge->impl = x; | ||
| 61 | ret = gin_init(ge); | ||
| 62 | if (ret) | ||
| 63 | goto freemem; | ||
| 64 | ret = touch_dev_open(&x->dev, fd); | ||
| 65 | if (ret) | ||
| 66 | goto freegin; | ||
| 67 | ret = gru_init(ge); | ||
| 68 | if (ret) | ||
| 69 | goto freedev; | ||
| 70 | touch_engine_init(&x->engine, tp_event, tp_sync, ge); | ||
| 71 | touch_engine_attach(&x->engine, &x->dev); | ||
| 72 | return 0; | ||
| 73 | freedev: | ||
| 74 | touch_dev_close(&x->dev, fd); | ||
| 75 | freegin: | ||
| 76 | gin_destroy(ge); | ||
| 77 | freemem: | ||
| 78 | free(x); | ||
| 79 | ge->impl = 0; | ||
| 80 | return ret; | ||
| 81 | } | ||
| 82 | |||
| 83 | void grail_close(struct grail *ge, int fd) | ||
| 84 | { | ||
| 85 | struct grail_impl *x = ge->impl; | ||
| 86 | void *status; | ||
| 87 | touch_engine_detach(&x->engine, &x->dev); | ||
| 88 | gru_destroy(ge); | ||
| 89 | touch_dev_close(&x->dev, fd); | ||
| 90 | gin_destroy(ge); | ||
| 91 | free(ge->impl); | ||
| 92 | ge->impl = 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | int grail_idle(struct grail *ge, int fd, int ms) | ||
| 96 | { | ||
| 97 | struct grail_impl *x = ge->impl; | ||
| 98 | return touch_dev_idle(&x->dev, fd, ms); | ||
| 99 | } | ||
| 100 | |||
| 101 | int grail_pull(struct grail *ge, int fd) | ||
| 102 | { | ||
| 103 | struct grail_impl *x = ge->impl; | ||
| 104 | return touch_dev_pull(&x->dev, fd); | ||
| 105 | } | ||
| 106 | |||
| 107 | void grail_get_units(struct grail_coord *min, struct grail_coord *max, | ||
| 108 | const struct grail *ge) | ||
| 109 | { | ||
| 110 | const struct touch_dev_caps *caps = &ge->impl->dev.caps; | ||
| 111 | min->x = caps->info[TP_POS_X].minimum; | ||
| 112 | min->y = caps->info[TP_POS_Y].minimum; | ||
| 113 | max->x = caps->info[TP_POS_X].maximum; | ||
| 114 | max->y = caps->info[TP_POS_Y].maximum; | ||
| 115 | } | ||
