release 0.1
[u-tools.git] / u-tools / apps / tslib / plugins / corgi-raw.c
blobfdb16a1997081508132820798c0b9f6022f8e61a
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <unistd.h>
5 #include "config.h"
6 #include "tslib-private.h"
8 struct corgi_ts_event { /* Used in the Sharp Zaurus SL-C700 */
9 short pressure;
10 short x;
11 short y;
12 short millisecs;
15 static int corgi_read(struct tslib_module_info *inf, struct ts_sample *samp, int nr)
17 struct tsdev *ts = inf->dev;
18 struct corgi_ts_event *corgi_evt;
19 int ret;
20 int total = 0;
21 corgi_evt = alloca(sizeof(*corgi_evt) * nr);
22 ret = read(ts->fd, corgi_evt, sizeof(*corgi_evt) * nr);
23 if(ret > 0) {
24 int nr = ret / sizeof(*corgi_evt);
25 while(ret >= (int)sizeof(*corgi_evt)) {
26 samp->x = corgi_evt->x;
27 samp->y = corgi_evt->y;
28 samp->pressure = corgi_evt->pressure;
29 #ifdef DEBUG
30 fprintf(stderr,"RAW---------------------------> %d %d %d\n",samp->x,samp->y,samp->pressure);
31 #endif /*DEBUG*/
32 samp->tv.tv_usec = corgi_evt->millisecs % 1000;
33 samp->tv.tv_sec = corgi_evt->millisecs / 1000;
34 samp++;
35 corgi_evt++;
36 ret -= sizeof(*corgi_evt);
38 } else {
39 return -1;
41 ret = nr;
42 return ret;
45 static const struct tslib_ops corgi_ops =
47 .read = corgi_read,
50 TSAPI struct tslib_module_info *mod_init(struct tsdev *dev, const char *params)
52 struct tslib_module_info *m;
54 m = malloc(sizeof(struct tslib_module_info));
55 if (m == NULL)
56 return NULL;
58 m->ops = &corgi_ops;
59 return m;