aboutsummaryrefslogtreecommitdiffstats
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)
downloadxorg-input-kobomultitouch-3734c2c5dc65f41aa727d9d69201d604eab6e77d.tar.gz
xorg-input-kobomultitouch-3734c2c5dc65f41aa727d9d69201d604eab6e77d.tar.bz2
xorg-input-kobomultitouch-3734c2c5dc65f41aa727d9d69201d604eab6e77d.zip
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
MODULES = src
o_src = capabilities \
+ iobuffer \
hwdata \
mtouch \
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 @@
#include "capabilities.h"
-#include <errno.h>
////////////////////////////////////////////////////////
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 @@
#include <xf86_OSproc.h>
#include <xf86Xinput.h>
#include <linux/input.h>
+#include <errno.h>
//#include <exevents.h>
////////////////////////////////////////////////////////
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 @@
#include "hwdata.h"
-#include <errno.h>
/******************************************************/
-static int parse_event(struct HWData *hw)
+void init_hwdata(struct HWData *hw)
+{
+ memset(hw, 0, sizeof(struct HWData));
+}
+
+/******************************************************/
+
+bool read_hwdata(struct HWData *hw, const struct input_event* ev)
{
- const struct input_event *ev = hw->event + hw->at++;
bool on = ev->value != 0;
switch (ev->type) {
case EV_SYN:
switch (ev->code) {
case SYN_REPORT:
- return 0;
+ return 1;
}
break;
case EV_KEY:
@@ -61,28 +66,11 @@ static int parse_event(struct HWData *hw)
}
break;
}
- return -EAGAIN;
+ return 0;
}
/******************************************************/
-int read_hwdata(struct HWData *hw, int fd)
-{
- int n;
- do {
- while (hw->at < hw->nev)
- if (!parse_event(hw))
- return 0;
- n = read(fd, hw->event, sizeof(hw->event));
- hw->at = 0;
- hw->nev = n / sizeof(struct input_event);
- xf86Msg(X_INFO, "multitouch: read: %d %d\n", n, hw->nev);
- } while (n > 0);
- return -EIO;
-};
-
-/******************************************************/
-
void output_hwdata(const struct HWData *hw)
{
}
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 @@
#include "common.h"
-#define DIM_EVENTS 64
#define DIM_FINGER 16
////////////////////////////////////////////////////////
@@ -18,15 +17,15 @@ struct FingerData {
////////////////////////////////////////////////////////
struct HWData {
- struct input_event event[DIM_EVENTS];
struct FingerData finger[DIM_FINGER];
- int at, nev, nfinger;
+ int nfinger;
bool left, middle, right;
};
////////////////////////////////////////////////////////
-int read_hwdata(struct HWData *hw, int fd);
+void init_hwdata(struct HWData *hw);
+bool read_hwdata(struct HWData *hw, const struct input_event* ev);
void output_hwdata(const struct HWData *hw);
////////////////////////////////////////////////////////
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 @@
+#include "iobuffer.h"
+
+////////////////////////////////////////////////////////
+
+void init_iobuf(struct IOBuffer *buf)
+{
+ memset(buf, 0, sizeof(struct IOBuffer));
+ buf->at = buf->begin;
+ buf->top = buf->at;
+ buf->end = buf->begin + DIM_BUFFER;
+}
+
+////////////////////////////////////////////////////////
+
+const struct input_event* get_iobuf_event(struct IOBuffer *buf, int fd)
+{
+ const struct input_event *ev;
+ int n = buf->top - buf->at;
+ if (n < EVENT_SIZE) {
+ /* partial event is available: save it */
+ if (buf->at != buf->begin && n > 0)
+ memmove(buf->begin, buf->at, n);
+ /* start from the beginning */
+ buf->at = buf->begin;
+ buf->top = buf->at + n;
+ /* read more data */
+ SYSCALL(n = read(fd, buf->top, buf->end - buf->top));
+ if (n <= 0)
+ return NULL;
+ buf->top += n;
+ }
+ if (buf->top - buf->at < EVENT_SIZE)
+ return NULL;
+ ev = (const struct input_event *)buf->at;
+ buf->at += EVENT_SIZE;
+ return ev;
+}
+
+////////////////////////////////////////////////////////
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 @@
+#ifndef IOBUFFER_H
+#define IOBUFFER_H
+
+#include "common.h"
+
+#define EVENT_SIZE sizeof(struct input_event)
+#define DIM_EVENTS 64
+#define DIM_BUFFER (DIM_EVENTS * EVENT_SIZE)
+
+////////////////////////////////////////////////////////
+
+struct IOBuffer {
+ char begin[DIM_BUFFER], *at, *top, *end;
+};
+
+////////////////////////////////////////////////////////
+
+void init_iobuf(struct IOBuffer *buf);
+const struct input_event* get_iobuf_event(struct IOBuffer *buf, int fd);
+
+////////////////////////////////////////////////////////
+
+#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 @@
#include "mtouch.h"
-#include <errno.h>
/******************************************************/
@@ -17,6 +16,8 @@ int configure_mtouch(struct MTouch *mt, int fd)
int open_mtouch(struct MTouch *mt, int fd)
{
int rc;
+ init_iobuf(&mt->buf);
+ init_hwdata(&mt->hw);
if (mt->grabbed)
return 0;
SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)1));
@@ -34,7 +35,7 @@ void close_mtouch(struct MTouch *mt, int fd)
{
int rc;
if (!mt->grabbed)
- return 0;
+ return;
SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)0));
if (rc < 0)
xf86Msg(X_WARNING, "multitouch: cannot ungrab device\n");
@@ -42,3 +43,14 @@ void close_mtouch(struct MTouch *mt, int fd)
}
/******************************************************/
+
+bool read_synchronized_event(struct MTouch *mt, int fd)
+{
+ const struct input_event* ev;
+ while(ev = get_iobuf_event(&mt->buf, fd))
+ if (read_hwdata(&mt->hw, ev))
+ return 1;
+ return 0;
+}
+
+/******************************************************/
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 @@
#define MTOUCH_H
#include "capabilities.h"
+#include "iobuffer.h"
#include "hwdata.h"
////////////////////////////////////////////////////////
struct MTouch {
struct Capabilities caps;
+ struct IOBuffer buf;
struct HWData hw;
bool grabbed;
};
@@ -18,6 +20,8 @@ int configure_mtouch(struct MTouch *mt, int fd);
int open_mtouch(struct MTouch *mt, int fd);
void close_mtouch(struct MTouch *mt, int fd);
+bool read_synchronized_event(struct MTouch *mt, int fd);
+
////////////////////////////////////////////////////////
#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)
xf86Msg(X_INFO, "read_input called\n");
if (local->fd >= 0) {
- while (!read_hwdata(&mt->hw, local->fd)) {
+ while (read_synchronized_event(mt, local->fd)) {
+ xf86Msg(X_INFO, "synced event\n");
// do all the good stuff here
}
}