summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2008-11-06 16:00:08 +0100
committerHenrik Rydberg <rydberg@euromail.se>2008-11-06 16:00:08 +0100
commit3734c2c5dc65f41aa727d9d69201d604eab6e77d (patch)
treeea9fa82ccc2afef9183f01f77084a69d85756542
parent826439bce844fdbc8d7e47c0964cb15fd8a8fe93 (diff)
event loop works, buffer works, now look at synched event
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
-rw-r--r--Makefile1
-rw-r--r--src/capabilities.c1
-rw-r--r--src/common.h1
-rw-r--r--src/hwdata.c32
-rw-r--r--src/hwdata.h7
-rw-r--r--src/iobuffer.c39
-rw-r--r--src/iobuffer.h23
-rw-r--r--src/mtouch.c16
-rw-r--r--src/mtouch.h4
-rw-r--r--src/multitouch.c3
10 files changed, 97 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index c6b6cf2..59b0aba 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,7 @@ FDIS = 11-multitouch.fdi
3MODULES = src 3MODULES = src
4 4
5o_src = capabilities \ 5o_src = capabilities \
6 iobuffer \
6 hwdata \ 7 hwdata \
7 mtouch \ 8 mtouch \
8 multitouch 9 multitouch
diff --git a/src/capabilities.c b/src/capabilities.c
index d0a157b..a0655c8 100644
--- a/src/capabilities.c
+++ b/src/capabilities.c
@@ -1,5 +1,4 @@
1#include "capabilities.h" 1#include "capabilities.h"
2#include <errno.h>
3 2
4//////////////////////////////////////////////////////// 3////////////////////////////////////////////////////////
5 4
diff --git a/src/common.h b/src/common.h
index 22cd9e9..5a83f95 100644
--- a/src/common.h
+++ b/src/common.h
@@ -6,6 +6,7 @@
6#include <xf86_OSproc.h> 6#include <xf86_OSproc.h>
7#include <xf86Xinput.h> 7#include <xf86Xinput.h>
8#include <linux/input.h> 8#include <linux/input.h>
9#include <errno.h>
9//#include <exevents.h> 10//#include <exevents.h>
10 11
11//////////////////////////////////////////////////////// 12////////////////////////////////////////////////////////
diff --git a/src/hwdata.c b/src/hwdata.c
index 212e860..17b9a46 100644
--- a/src/hwdata.c
+++ b/src/hwdata.c
@@ -1,17 +1,22 @@
1#include "hwdata.h" 1#include "hwdata.h"
2#include <errno.h>
3 2
4/******************************************************/ 3/******************************************************/
5 4
6static int parse_event(struct HWData *hw) 5void init_hwdata(struct HWData *hw)
6{
7 memset(hw, 0, sizeof(struct HWData));
8}
9
10/******************************************************/
11
12bool read_hwdata(struct HWData *hw, const struct input_event* ev)
7{ 13{
8 const struct input_event *ev = hw->event + hw->at++;
9 bool on = ev->value != 0; 14 bool on = ev->value != 0;
10 switch (ev->type) { 15 switch (ev->type) {
11 case EV_SYN: 16 case EV_SYN:
12 switch (ev->code) { 17 switch (ev->code) {
13 case SYN_REPORT: 18 case SYN_REPORT:
14 return 0; 19 return 1;
15 } 20 }
16 break; 21 break;
17 case EV_KEY: 22 case EV_KEY:
@@ -61,28 +66,11 @@ static int parse_event(struct HWData *hw)
61 } 66 }
62 break; 67 break;
63 } 68 }
64 return -EAGAIN; 69 return 0;
65} 70}
66 71
67/******************************************************/ 72/******************************************************/
68 73
69int read_hwdata(struct HWData *hw, int fd)
70{
71 int n;
72 do {
73 while (hw->at < hw->nev)
74 if (!parse_event(hw))
75 return 0;
76 n = read(fd, hw->event, sizeof(hw->event));
77 hw->at = 0;
78 hw->nev = n / sizeof(struct input_event);
79 xf86Msg(X_INFO, "multitouch: read: %d %d\n", n, hw->nev);
80 } while (n > 0);
81 return -EIO;
82};
83
84/******************************************************/
85
86void output_hwdata(const struct HWData *hw) 74void output_hwdata(const struct HWData *hw)
87{ 75{
88} 76}
diff --git a/src/hwdata.h b/src/hwdata.h
index beb98b0..b9316db 100644
--- a/src/hwdata.h
+++ b/src/hwdata.h
@@ -3,7 +3,6 @@
3 3
4#include "common.h" 4#include "common.h"
5 5
6#define DIM_EVENTS 64
7#define DIM_FINGER 16 6#define DIM_FINGER 16
8 7
9//////////////////////////////////////////////////////// 8////////////////////////////////////////////////////////
@@ -18,15 +17,15 @@ struct FingerData {
18//////////////////////////////////////////////////////// 17////////////////////////////////////////////////////////
19 18
20struct HWData { 19struct HWData {
21 struct input_event event[DIM_EVENTS];
22 struct FingerData finger[DIM_FINGER]; 20 struct FingerData finger[DIM_FINGER];
23 int at, nev, nfinger; 21 int nfinger;
24 bool left, middle, right; 22 bool left, middle, right;
25}; 23};
26 24
27//////////////////////////////////////////////////////// 25////////////////////////////////////////////////////////
28 26
29int read_hwdata(struct HWData *hw, int fd); 27void init_hwdata(struct HWData *hw);
28bool read_hwdata(struct HWData *hw, const struct input_event* ev);
30void output_hwdata(const struct HWData *hw); 29void output_hwdata(const struct HWData *hw);
31 30
32//////////////////////////////////////////////////////// 31////////////////////////////////////////////////////////
diff --git a/src/iobuffer.c b/src/iobuffer.c
new file mode 100644
index 0000000..8bfcc07
--- /dev/null
+++ b/src/iobuffer.c
@@ -0,0 +1,39 @@
1#include "iobuffer.h"
2
3////////////////////////////////////////////////////////
4
5void init_iobuf(struct IOBuffer *buf)
6{
7 memset(buf, 0, sizeof(struct IOBuffer));
8 buf->at = buf->begin;
9 buf->top = buf->at;
10 buf->end = buf->begin + DIM_BUFFER;
11}
12
13////////////////////////////////////////////////////////
14
15const struct input_event* get_iobuf_event(struct IOBuffer *buf, int fd)
16{
17 const struct input_event *ev;
18 int n = buf->top - buf->at;
19 if (n < EVENT_SIZE) {
20 /* partial event is available: save it */
21 if (buf->at != buf->begin && n > 0)
22 memmove(buf->begin, buf->at, n);
23 /* start from the beginning */
24 buf->at = buf->begin;
25 buf->top = buf->at + n;
26 /* read more data */
27 SYSCALL(n = read(fd, buf->top, buf->end - buf->top));
28 if (n <= 0)
29 return NULL;
30 buf->top += n;
31 }
32 if (buf->top - buf->at < EVENT_SIZE)
33 return NULL;
34 ev = (const struct input_event *)buf->at;
35 buf->at += EVENT_SIZE;
36 return ev;
37}
38
39////////////////////////////////////////////////////////
diff --git a/src/iobuffer.h b/src/iobuffer.h
new file mode 100644
index 0000000..41c8d0d
--- /dev/null
+++ b/src/iobuffer.h
@@ -0,0 +1,23 @@
1#ifndef IOBUFFER_H
2#define IOBUFFER_H
3
4#include "common.h"
5
6#define EVENT_SIZE sizeof(struct input_event)
7#define DIM_EVENTS 64
8#define DIM_BUFFER (DIM_EVENTS * EVENT_SIZE)
9
10////////////////////////////////////////////////////////
11
12struct IOBuffer {
13 char begin[DIM_BUFFER], *at, *top, *end;
14};
15
16////////////////////////////////////////////////////////
17
18void init_iobuf(struct IOBuffer *buf);
19const struct input_event* get_iobuf_event(struct IOBuffer *buf, int fd);
20
21////////////////////////////////////////////////////////
22
23#endif
diff --git a/src/mtouch.c b/src/mtouch.c
index a74a1f6..e469d2e 100644
--- a/src/mtouch.c
+++ b/src/mtouch.c
@@ -1,5 +1,4 @@
1#include "mtouch.h" 1#include "mtouch.h"
2#include <errno.h>
3 2
4/******************************************************/ 3/******************************************************/
5 4
@@ -17,6 +16,8 @@ int configure_mtouch(struct MTouch *mt, int fd)
17int open_mtouch(struct MTouch *mt, int fd) 16int open_mtouch(struct MTouch *mt, int fd)
18{ 17{
19 int rc; 18 int rc;
19 init_iobuf(&mt->buf);
20 init_hwdata(&mt->hw);
20 if (mt->grabbed) 21 if (mt->grabbed)
21 return 0; 22 return 0;
22 SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)1)); 23 SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)1));
@@ -34,7 +35,7 @@ void close_mtouch(struct MTouch *mt, int fd)
34{ 35{
35 int rc; 36 int rc;
36 if (!mt->grabbed) 37 if (!mt->grabbed)
37 return 0; 38 return;
38 SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)0)); 39 SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)0));
39 if (rc < 0) 40 if (rc < 0)
40 xf86Msg(X_WARNING, "multitouch: cannot ungrab device\n"); 41 xf86Msg(X_WARNING, "multitouch: cannot ungrab device\n");
@@ -42,3 +43,14 @@ void close_mtouch(struct MTouch *mt, int fd)
42} 43}
43 44
44/******************************************************/ 45/******************************************************/
46
47bool read_synchronized_event(struct MTouch *mt, int fd)
48{
49 const struct input_event* ev;
50 while(ev = get_iobuf_event(&mt->buf, fd))
51 if (read_hwdata(&mt->hw, ev))
52 return 1;
53 return 0;
54}
55
56/******************************************************/
diff --git a/src/mtouch.h b/src/mtouch.h
index d036a8f..8324e9e 100644
--- a/src/mtouch.h
+++ b/src/mtouch.h
@@ -2,12 +2,14 @@
2#define MTOUCH_H 2#define MTOUCH_H
3 3
4#include "capabilities.h" 4#include "capabilities.h"
5#include "iobuffer.h"
5#include "hwdata.h" 6#include "hwdata.h"
6 7
7//////////////////////////////////////////////////////// 8////////////////////////////////////////////////////////
8 9
9struct MTouch { 10struct MTouch {
10 struct Capabilities caps; 11 struct Capabilities caps;
12 struct IOBuffer buf;
11 struct HWData hw; 13 struct HWData hw;
12 bool grabbed; 14 bool grabbed;
13}; 15};
@@ -18,6 +20,8 @@ int configure_mtouch(struct MTouch *mt, int fd);
18int open_mtouch(struct MTouch *mt, int fd); 20int open_mtouch(struct MTouch *mt, int fd);
19void close_mtouch(struct MTouch *mt, int fd); 21void close_mtouch(struct MTouch *mt, int fd);
20 22
23bool read_synchronized_event(struct MTouch *mt, int fd);
24
21//////////////////////////////////////////////////////// 25////////////////////////////////////////////////////////
22 26
23#endif 27#endif
diff --git a/src/multitouch.c b/src/multitouch.c
index 73aaffd..40895c9 100644
--- a/src/multitouch.c
+++ b/src/multitouch.c
@@ -83,7 +83,8 @@ static void read_input(LocalDevicePtr local)
83 xf86Msg(X_INFO, "read_input called\n"); 83 xf86Msg(X_INFO, "read_input called\n");
84 84
85 if (local->fd >= 0) { 85 if (local->fd >= 0) {
86 while (!read_hwdata(&mt->hw, local->fd)) { 86 while (read_synchronized_event(mt, local->fd)) {
87 xf86Msg(X_INFO, "synced event\n");
87 // do all the good stuff here 88 // do all the good stuff here
88 } 89 }
89 } 90 }