diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2008-11-06 14:03:42 +0100 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2008-11-06 14:03:42 +0100 |
| commit | a773c79d6d767ddfe574ad513ab0276bdd13a717 (patch) | |
| tree | 8d879fe396dab810bf5632c9777c3931c08eb396 /src/multitouch.c | |
| parent | 030a3c8a38a81ea882fa0a3b0bfce61ded50a20d (diff) | |
Driver stages in place - should one support multiple
device instances by moving the private alloc to init/close?
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/multitouch.c')
| -rw-r--r-- | src/multitouch.c | 123 |
1 files changed, 101 insertions, 22 deletions
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 @@ | |||
| 21 | * | 21 | * |
| 22 | **************************************************************************/ | 22 | **************************************************************************/ |
| 23 | 23 | ||
| 24 | #include "capabilities.h" | 24 | #include "mtouch.h" |
| 25 | |||
| 26 | //////////////////////////////////////////////////////////////////////////// | ||
| 27 | |||
| 28 | static int device_init(LocalDevicePtr local) | ||
| 29 | { | ||
| 30 | struct MTouch *mt = local->private; | ||
| 31 | local->fd = xf86OpenSerial(local->options); | ||
| 32 | if (local->fd < 0) { | ||
| 33 | xf86Msg(X_ERROR, "multitouch: cannot configure device\n"); | ||
| 34 | return local->fd; | ||
| 35 | } | ||
| 36 | if (configure_mtouch(mt, local->fd)) | ||
| 37 | return -1; | ||
| 38 | xf86CloseSerial(local->fd); | ||
| 39 | return 0; | ||
| 40 | } | ||
| 41 | |||
| 42 | //////////////////////////////////////////////////////////////////////////// | ||
| 43 | |||
| 44 | static int device_on(LocalDevicePtr local) | ||
| 45 | { | ||
| 46 | struct MTouch *mt = local->private; | ||
| 47 | local->fd = xf86OpenSerial(local->options); | ||
| 48 | if (local->fd < 0) { | ||
| 49 | xf86Msg(X_ERROR, "multitouch: cannot open device\n"); | ||
| 50 | return local->fd; | ||
| 51 | } | ||
| 52 | if (init_mtouch(mt)) | ||
| 53 | return -1; | ||
| 54 | return 0; | ||
| 55 | } | ||
| 56 | |||
| 57 | //////////////////////////////////////////////////////////////////////////// | ||
| 58 | |||
| 59 | static void device_off(LocalDevicePtr local) | ||
| 60 | { | ||
| 61 | if(local->fd >= 0) | ||
| 62 | xf86CloseSerial(local->fd); | ||
| 63 | } | ||
| 64 | |||
| 65 | //////////////////////////////////////////////////////////////////////////// | ||
| 66 | |||
| 67 | static void device_close(LocalDevicePtr local) | ||
| 68 | { | ||
| 69 | } | ||
| 70 | |||
| 71 | //////////////////////////////////////////////////////////////////////////// | ||
| 72 | |||
| 73 | /* called for each full received packet from the touchpad */ | ||
| 74 | static void read_input(LocalDevicePtr local) | ||
| 75 | { | ||
| 76 | struct MTouch *mt = local->private; | ||
| 77 | |||
| 78 | xf86Msg(X_INFO, "read_input called\n"); | ||
| 79 | |||
| 80 | if (local->fd >= 0) { | ||
| 81 | while (!read_hwdata(&mt->hw, local->fd)) { | ||
| 82 | // do all the good stuff here | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | //////////////////////////////////////////////////////////////////////////// | ||
| 88 | |||
| 89 | static Bool device_control(DeviceIntPtr dev, int mode) | ||
| 90 | { | ||
| 91 | LocalDevicePtr local = dev->public.devicePrivate; | ||
| 92 | switch (mode) { | ||
| 93 | case DEVICE_INIT: | ||
| 94 | xf86Msg(X_INFO, "device control: init\n"); | ||
| 95 | if (device_init(local)) | ||
| 96 | return !Success; | ||
| 97 | return Success; | ||
| 98 | case DEVICE_ON: | ||
| 99 | xf86Msg(X_INFO, "device control: on\n"); | ||
| 100 | if (device_on(local)) | ||
| 101 | return !Success; | ||
| 102 | return Success; | ||
| 103 | case DEVICE_OFF: | ||
| 104 | xf86Msg(X_INFO, "device control: off\n"); | ||
| 105 | device_off(local); | ||
| 106 | return Success; | ||
| 107 | case DEVICE_CLOSE: | ||
| 108 | xf86Msg(X_INFO, "device control: close\n"); | ||
| 109 | device_close(local); | ||
| 110 | return Success; | ||
| 111 | default: | ||
| 112 | xf86Msg(X_INFO, "device control: default\n"); | ||
| 113 | return BadValue; | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 25 | 117 | ||
| 26 | //////////////////////////////////////////////////////////////////////////// | 118 | //////////////////////////////////////////////////////////////////////////// |
| 27 | 119 | ||
| 28 | static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags) | 120 | static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags) |
| 29 | { | 121 | { |
| 122 | struct MTouch *mt; | ||
| 30 | InputInfoPtr local = xf86AllocateInput(drv, 0); | 123 | InputInfoPtr local = xf86AllocateInput(drv, 0); |
| 31 | if (!local) | 124 | if (!local) |
| 32 | goto error; | 125 | goto error; |
| 126 | mt = xcalloc(1, sizeof(struct MTouch)); | ||
| 127 | if (!mt) | ||
| 128 | goto error; | ||
| 33 | 129 | ||
| 34 | local->name = dev->identifier; | 130 | local->name = dev->identifier; |
| 35 | local->type_name = XI_TOUCHPAD; | 131 | local->type_name = XI_TOUCHPAD; |
| 36 | local->device_control = 0;//DeviceControl; | 132 | local->device_control = device_control; |
| 37 | local->read_input = 0;//ReadInput; | 133 | local->read_input = read_input; |
| 38 | local->control_proc = 0;//ControlProc; | 134 | local->private = mt; |
| 39 | local->close_proc = 0;//CloseProc; | ||
| 40 | local->switch_mode = 0;//SwitchMode; | ||
| 41 | local->conversion_proc = 0;//ConvertProc; | ||
| 42 | local->reverse_conversion_proc = NULL; | ||
| 43 | local->dev = NULL; | ||
| 44 | local->private = 0;//priv; | ||
| 45 | local->private_flags = 0; | 135 | local->private_flags = 0; |
| 46 | local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS; | 136 | local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS; |
| 47 | local->conf_idev = dev; | 137 | local->conf_idev = dev; |
| 48 | //local->motion_history_proc = xf86GetMotionEvents; | ||
| 49 | //local->history_size = 0; | ||
| 50 | local->always_core_feedback = 0; | 138 | local->always_core_feedback = 0; |
| 51 | 139 | ||
| 52 | xf86CollectInputOptions(local, NULL, NULL); | 140 | xf86CollectInputOptions(local, NULL, NULL); |
| 53 | xf86OptionListReport(local->options); | 141 | xf86OptionListReport(local->options); |
| 54 | 142 | ||
| 55 | local->fd = xf86OpenSerial(local->options); | ||
| 56 | if (local->fd < 0) { | ||
| 57 | xf86Msg(X_ERROR, "multitouch: cannot open device\n"); | ||
| 58 | goto error; | ||
| 59 | } | ||
| 60 | struct Capabilities cap; | ||
| 61 | read_capabilities(&cap, local->fd); | ||
| 62 | output_capabilities(&cap); | ||
| 63 | xf86CloseSerial(local->fd); | ||
| 64 | local->fd = -1; | ||
| 65 | local->flags |= XI86_CONFIGURED; | 143 | local->flags |= XI86_CONFIGURED; |
| 66 | error: | 144 | error: |
| 67 | return local; | 145 | return local; |
| @@ -69,6 +147,7 @@ static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags) | |||
| 69 | 147 | ||
| 70 | static void uninit(InputDriverPtr drv, InputInfoPtr local, int flags) | 148 | static void uninit(InputDriverPtr drv, InputInfoPtr local, int flags) |
| 71 | { | 149 | { |
| 150 | xfree(local->private); | ||
| 72 | xf86DeleteInput(local, 0); | 151 | xf86DeleteInput(local, 0); |
| 73 | } | 152 | } |
| 74 | 153 | ||
