diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/capabilities.c | 4 | ||||
-rw-r--r-- | src/capabilities.h | 3 | ||||
-rw-r--r-- | src/common.h | 1 | ||||
-rw-r--r-- | src/hwdata.c | 90 | ||||
-rw-r--r-- | src/hwdata.h | 34 | ||||
-rw-r--r-- | src/mtouch.c | 22 | ||||
-rw-r--r-- | src/mtouch.h | 21 | ||||
-rw-r--r-- | src/multitouch.c | 123 |
9 files changed, 275 insertions, 25 deletions
@@ -3,6 +3,8 @@ FDIS = 11-multitouch.fdi MODULES = src o_src = capabilities \ + hwdata \ + mtouch \ multitouch TARGETS = $(addsuffix /test,$(MODULES)) diff --git a/src/capabilities.c b/src/capabilities.c index 513a254..d0a157b 100644 --- a/src/capabilities.c +++ b/src/capabilities.c @@ -62,11 +62,13 @@ int read_capabilities(struct Capabilities *cap, int fd) SETABS(cap, orientation, absbits, ABS_MT_ORIENTATION, fd); SETABS(cap, position_x, absbits, ABS_MT_POSITION_X, fd); SETABS(cap, position_y, absbits, ABS_MT_POSITION_Y, fd); + + return 0; } //////////////////////////////////////////////////////// -int output_capabilities(const struct Capabilities *cap) +void output_capabilities(const struct Capabilities *cap) { char line[1024]; memset(line, 0, sizeof(line)); diff --git a/src/capabilities.h b/src/capabilities.h index 5cde963..cd00353 100644 --- a/src/capabilities.h +++ b/src/capabilities.h @@ -2,7 +2,6 @@ #define CAPABILITIES_H #include "common.h" -#include <linux/input.h> //////////////////////////////////////////////////////// @@ -25,7 +24,7 @@ struct Capabilities { //////////////////////////////////////////////////////// int read_capabilities(struct Capabilities *cap, int fd); -int output_capabilities(const struct Capabilities *cap); +void output_capabilities(const struct Capabilities *cap); //////////////////////////////////////////////////////// diff --git a/src/common.h b/src/common.h index 7aabd7e..22cd9e9 100644 --- a/src/common.h +++ b/src/common.h @@ -5,6 +5,7 @@ #include <xf86.h> #include <xf86_OSproc.h> #include <xf86Xinput.h> +#include <linux/input.h> //#include <exevents.h> //////////////////////////////////////////////////////// diff --git a/src/hwdata.c b/src/hwdata.c new file mode 100644 index 0000000..212e860 --- /dev/null +++ b/src/hwdata.c @@ -0,0 +1,90 @@ +#include "hwdata.h" +#include <errno.h> + +/******************************************************/ + +static int parse_event(struct HWData *hw) +{ + 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; + } + break; + case EV_KEY: + switch (ev->code) { + case BTN_LEFT: + hw->left = on; + break; + case BTN_MIDDLE: + hw->middle = on; + break; + case BTN_RIGHT: + hw->right = on; + break; + case BTN_MT_REPORT_PACKET: + if (on) + hw->nfinger = 0; + break; + case BTN_MT_REPORT_FINGER: + if (!on && hw->nfinger < DIM_FINGER) + hw->nfinger++; + break; + } + break; + case EV_ABS: + switch (ev->code) { + case ABS_MT_TOUCH_MAJOR: + hw->finger[hw->nfinger].touch_major = ev->value; + break; + case ABS_MT_TOUCH_MINOR: + hw->finger[hw->nfinger].touch_minor = ev->value; + break; + case ABS_MT_WIDTH_MAJOR: + hw->finger[hw->nfinger].width_major = ev->value; + break; + case ABS_MT_WIDTH_MINOR: + hw->finger[hw->nfinger].width_minor = ev->value; + break; + case ABS_MT_ORIENTATION: + hw->finger[hw->nfinger].orientation = ev->value; + break; + case ABS_MT_POSITION_X: + hw->finger[hw->nfinger].position_x = ev->value; + break; + case ABS_MT_POSITION_Y: + hw->finger[hw->nfinger].position_y = ev->value; + break; + } + break; + } + return -EAGAIN; +} + +/******************************************************/ + +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 new file mode 100644 index 0000000..beb98b0 --- /dev/null +++ b/src/hwdata.h @@ -0,0 +1,34 @@ +#ifndef HWDATA_H +#define HWDATA_H + +#include "common.h" + +#define DIM_EVENTS 64 +#define DIM_FINGER 16 + +//////////////////////////////////////////////////////// + +struct FingerData { + int touch_major, touch_minor; + int width_major, width_minor; + int orientation; + int position_x, position_y; +}; + +//////////////////////////////////////////////////////// + +struct HWData { + struct input_event event[DIM_EVENTS]; + struct FingerData finger[DIM_FINGER]; + int at, nev, nfinger; + bool left, middle, right; +}; + +//////////////////////////////////////////////////////// + +int read_hwdata(struct HWData *hw, int fd); +void output_hwdata(const struct HWData *hw); + +//////////////////////////////////////////////////////// + +#endif diff --git a/src/mtouch.c b/src/mtouch.c new file mode 100644 index 0000000..2d05921 --- /dev/null +++ b/src/mtouch.c @@ -0,0 +1,22 @@ +#include "mtouch.h" +#include <errno.h> + +/******************************************************/ + +int configure_mtouch(struct MTouch *mt, int fd) +{ + int rc = read_capabilities(&mt->caps, fd); + if (rc < 0) + return rc; + output_capabilities(&mt->caps); + return 0; +} + +/******************************************************/ + +int init_mtouch(struct MTouch *mt) +{ + return 0; +} + +/******************************************************/ diff --git a/src/mtouch.h b/src/mtouch.h new file mode 100644 index 0000000..a945162 --- /dev/null +++ b/src/mtouch.h @@ -0,0 +1,21 @@ +#ifndef MTOUCH_H +#define MTOUCH_H + +#include "capabilities.h" +#include "hwdata.h" + +//////////////////////////////////////////////////////// + +struct MTouch { + struct Capabilities caps; + struct HWData hw; +}; + +//////////////////////////////////////////////////////// + +int configure_mtouch(struct MTouch *mt, int fd); +int init_mtouch(struct MTouch *mt); + +//////////////////////////////////////////////////////// + +#endif diff --git a/src/multitouch.c b/src/multitouch.c index 6818e7c..9fb6d82 100644 --- a/src/multitouch.c +++ b/src/multitouch.c @@ -21,47 +21,125 @@ * **************************************************************************/ -#include "capabilities.h" +#include "mtouch.h" + +//////////////////////////////////////////////////////////////////////////// + +static int device_init(LocalDevicePtr local) +{ + struct MTouch *mt = local->private; + local->fd = xf86OpenSerial(local->options); + if (local->fd < 0) { + xf86Msg(X_ERROR, "multitouch: cannot configure device\n"); + return local->fd; + } + if (configure_mtouch(mt, local->fd)) + return -1; + xf86CloseSerial(local->fd); + return 0; +} + +//////////////////////////////////////////////////////////////////////////// + +static int device_on(LocalDevicePtr local) +{ + struct MTouch *mt = local->private; + local->fd = xf86OpenSerial(local->options); + if (local->fd < 0) { + xf86Msg(X_ERROR, "multitouch: cannot open device\n"); + return local->fd; + } + if (init_mtouch(mt)) + return -1; + return 0; +} + +//////////////////////////////////////////////////////////////////////////// + +static void device_off(LocalDevicePtr local) +{ + if(local->fd >= 0) + xf86CloseSerial(local->fd); +} + +//////////////////////////////////////////////////////////////////////////// + +static void device_close(LocalDevicePtr local) +{ +} + +//////////////////////////////////////////////////////////////////////////// + +/* called for each full received packet from the touchpad */ +static void read_input(LocalDevicePtr local) +{ + struct MTouch *mt = local->private; + + xf86Msg(X_INFO, "read_input called\n"); + + if (local->fd >= 0) { + while (!read_hwdata(&mt->hw, local->fd)) { + // do all the good stuff here + } + } +} + +//////////////////////////////////////////////////////////////////////////// + +static Bool device_control(DeviceIntPtr dev, int mode) +{ + LocalDevicePtr local = dev->public.devicePrivate; + switch (mode) { + case DEVICE_INIT: + xf86Msg(X_INFO, "device control: init\n"); + if (device_init(local)) + return !Success; + return Success; + case DEVICE_ON: + xf86Msg(X_INFO, "device control: on\n"); + if (device_on(local)) + return !Success; + return Success; + case DEVICE_OFF: + xf86Msg(X_INFO, "device control: off\n"); + device_off(local); + return Success; + case DEVICE_CLOSE: + xf86Msg(X_INFO, "device control: close\n"); + device_close(local); + return Success; + default: + xf86Msg(X_INFO, "device control: default\n"); + return BadValue; + } +} + //////////////////////////////////////////////////////////////////////////// static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags) { + struct MTouch *mt; InputInfoPtr local = xf86AllocateInput(drv, 0); if (!local) goto error; + mt = xcalloc(1, sizeof(struct MTouch)); + if (!mt) + goto error; local->name = dev->identifier; local->type_name = XI_TOUCHPAD; - local->device_control = 0;//DeviceControl; - local->read_input = 0;//ReadInput; - local->control_proc = 0;//ControlProc; - local->close_proc = 0;//CloseProc; - local->switch_mode = 0;//SwitchMode; - local->conversion_proc = 0;//ConvertProc; - local->reverse_conversion_proc = NULL; - local->dev = NULL; - local->private = 0;//priv; + local->device_control = device_control; + local->read_input = read_input; + local->private = mt; local->private_flags = 0; local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS; local->conf_idev = dev; - //local->motion_history_proc = xf86GetMotionEvents; - //local->history_size = 0; local->always_core_feedback = 0; xf86CollectInputOptions(local, NULL, NULL); xf86OptionListReport(local->options); - local->fd = xf86OpenSerial(local->options); - if (local->fd < 0) { - xf86Msg(X_ERROR, "multitouch: cannot open device\n"); - goto error; - } - struct Capabilities cap; - read_capabilities(&cap, local->fd); - output_capabilities(&cap); - xf86CloseSerial(local->fd); - local->fd = -1; local->flags |= XI86_CONFIGURED; error: return local; @@ -69,6 +147,7 @@ static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags) static void uninit(InputDriverPtr drv, InputInfoPtr local, int flags) { + xfree(local->private); xf86DeleteInput(local, 0); } |