2 * Copyright (c) 2001 Edouard TISSERANT <tissered@esstin.u-nancy.fr>
3 * Parts inspired from Shane Watts <shane@bofh.asn.au> XFree86 3 Acecad Driver
4 * Thanks to Emily, from AceCad, For giving me documents.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <xorgVersion.h>
30 #define XORG_VERSION_BOTCHED XORG_VERSION_NUMERIC(1,4,0,0,0)
31 #if XORG_VERSION_CURRENT >= XORG_VERSION_BOTCHED
32 #define XORG_BOTCHED_INPUT 1
34 #define XORG_BOTCHED_INPUT 0
37 /*****************************************************************************
39 ****************************************************************************/
42 #include <asm/types.h>
43 #include <linux/input.h>
58 #ifndef NEED_XF86_TYPES
59 #define NEED_XF86_TYPES
61 #include <xf86_OSproc.h>
63 #include <xf86Xinput.h>
65 #include <xf86Module.h>
74 #include <sysfs/libsysfs.h>
79 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
80 #include <X11/Xatom.h>
81 #include <xserver-properties.h>
84 /* Previously found in xf86Xinput.h */
88 #define DBG(lvl, f) {if ((lvl) <= xf86GetVerbosity()) f;}
90 /*****************************************************************************
92 ****************************************************************************/
95 /*****************************************************************************
96 * Variables without includable headers
97 ****************************************************************************/
99 /*****************************************************************************
101 ****************************************************************************/
103 /* max number of input events to read in one read call */
104 #define MAX_EVENTS 50
106 _X_EXPORT InputDriverRec ACECAD =
117 static XF86ModuleVersionInfo VersionRec =
123 XORG_VERSION_CURRENT,
124 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
132 _X_EXPORT XF86ModuleData acecadModuleData = {
138 /*****************************************************************************
139 * Function Definitions
140 ****************************************************************************/
143 SetupProc( pointer module,
148 xf86AddInputDriver(&ACECAD, module, 0);
153 TearDownProc( pointer p )
157 static const char *default_options[] =
165 "FlowControl", "Xoff",
176 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
179 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
180 version >> 16, (version >> 8) & 0xff, version & 0xff);
183 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
188 /* Heavily inspired by synaptics/eventcomm.c */
190 #define DEV_INPUT_EVENT "/dev/input/event"
191 #define EV_DEV_NAME_MAXLEN 64
192 #define SET_EVENT_NUM(str, num) \
193 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
196 fd_query_acecad(int fd, char *ace_name) {
197 char name[256] = "Unknown";
198 int cmp_at = strlen(ace_name);
201 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
203 if (xf86NameCmp(name, ace_name) == 0)
208 static char ace_name_default[7] = "acecad";
211 static char usb_bus_name[4] = "usb";
212 static char acecad_driver_name[11] = "usb_acecad";
216 AceCadAutoDevProbe(LocalDevicePtr local, int verb)
218 /* We are trying to find the right eventX device */
220 Bool have_evdev = FALSE;
222 const int max_skip = 10;
223 char *ace_name = xf86FindOptionValue(local->options, "Name");
224 char fname[EV_DEV_NAME_MAXLEN];
228 struct sysfs_bus *usb_bus = NULL;
229 struct sysfs_driver *acecad_driver = NULL;
230 struct sysfs_device *candidate = NULL;
232 struct dlist *devs = NULL;
233 struct dlist *links = NULL;
235 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
236 usb_bus = sysfs_open_bus(usb_bus_name);
238 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
239 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
241 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
242 devs = sysfs_get_driver_devices(acecad_driver);
244 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
245 dlist_for_each_data(devs, candidate, struct sysfs_device) {
246 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
247 links = sysfs_open_link_list(candidate->path);
248 dlist_for_each_data(links, link, char) {
249 if (sscanf(link, "input:event%d", &i) == 1) {
250 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
254 sysfs_close_list(links);
255 if (i > 0) /* We found something */
259 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
261 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
263 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
264 sysfs_close_bus(usb_bus);
267 /* We found something */
268 np = SET_EVENT_NUM(fname, i);
269 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
270 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
275 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
280 ace_name = ace_name_default;
282 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
287 np = SET_EVENT_NUM(fname, i);
288 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
289 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
292 SYSCALL(fd = open(fname, O_RDONLY));
294 if (errno == ENOENT) {
295 if (++noent_cnt >= max_skip)
305 is_acecad = fd_query_acecad(fd, ace_name);
311 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
312 local->name, i + 1, ace_name);
314 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
316 if (i > max_skip && !have_evdev)
317 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
321 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
323 xf86ReplaceStrOption(local->options, "Device", fname);
330 AceCadPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
332 LocalDevicePtr local = xf86AllocateInput(drv, 0);
333 AceCadPrivatePtr priv = xcalloc (1, sizeof(AceCadPrivateRec));
338 if ((!local) || (!priv))
341 memset(priv, 0, sizeof(AceCadPrivateRec));
343 local->name = dev->identifier;
344 local->type_name = XI_TABLET;
345 local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
346 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
347 local->motion_history_proc = xf86GetMotionEvents;
349 local->control_proc = NULL;
350 local->close_proc = CloseProc;
351 local->switch_mode = NULL;
352 local->conversion_proc = ConvertProc;
353 local->reverse_conversion_proc = ReverseConvertProc;
355 local->private = priv;
356 local->private_flags = 0;
357 local->conf_idev = dev;
358 local->device_control = DeviceControl;
359 /*local->always_core_feedback = 0;*/
361 xf86CollectInputOptions(local, default_options, NULL);
363 xf86OptionListReport(local->options);
365 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
367 s = xf86FindOptionValue(local->options, "Device");
368 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
370 priv->flags |= AUTODEV_FLAG;
371 if (!AceCadAutoDevProbe(local, 0))
373 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
377 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
382 local->fd = xf86OpenSerial (local->options);
385 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
388 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
391 if (IsUSBLine(local->fd)) {
392 priv->flags |= USB_FLAG;
394 local->read_input = USBReadInput;
396 if (USBQueryHardware(local) != Success)
398 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
404 local->read_input = ReadInput;
407 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
409 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
417 priv->acecadReportSpeed = 'Q';
420 priv->acecadReportSpeed = 'R';
423 priv->acecadReportSpeed = 'S';
426 priv->acecadReportSpeed = 'T';
429 priv->acecadReportSpeed = 'R';
431 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
435 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
437 priv->buffer = XisbNew (local->fd, 200);
440 * Verify that hardware is attached and fuctional
442 if (QueryHardware(priv) != Success)
444 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
449 s = xf86FindOptionValue(local->options, "Mode");
450 msgtype = s ? X_CONFIG : X_DEFAULT;
451 if (!(s && (xf86NameCmp(s, "relative") == 0)))
453 priv->flags |= ABSOLUTE_FLAG;
456 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
457 DBG (9, XisbTrace (priv->buffer, 1));
459 local->history_size = xf86SetIntOption(local->options , "HistorySize", 0);
461 xf86ProcessCommonOptions(local, local->options);
463 local->flags |= XI86_CONFIGURED;
467 RemoveEnabledDevice (local->fd);
470 XisbFree(priv->buffer);
473 xf86CloseSerial(local->fd);
475 RemoveEnabledDevice (local->fd);
480 * If something went wrong, cleanup and return NULL
483 if ((local) && (local->fd))
484 xf86CloseSerial (local->fd);
485 if ((priv) && (priv->buffer))
486 XisbFree (priv->buffer);
490 local->private = NULL;
492 xf86DeleteInput(local, 0);
497 DeviceControl (DeviceIntPtr dev, int mode)
508 RetValue = DeviceOn(dev);
511 RetValue = DeviceOff(dev);
514 RetValue = DeviceClose(dev);
524 DeviceOn (DeviceIntPtr dev)
527 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
528 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
530 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
532 local->fd = xf86OpenSerial(local->options);
535 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
536 priv->flags &= ~AVAIL_FLAG;
538 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
539 local->fd = xf86OpenSerial(local->options);
544 priv->flags |= AVAIL_FLAG;
547 if (!(priv->flags & USB_FLAG)) {
548 priv->buffer = XisbNew(local->fd, 200);
551 xf86CloseSerial(local->fd);
556 /* Rets qu'a l'envoyer a la tablette */
557 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
558 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
561 xf86FlushInput(local->fd);
562 xf86AddEnabledDevice (local);
563 dev->public.on = TRUE;
568 DeviceOff (DeviceIntPtr dev)
570 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
571 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
573 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
577 RemoveEnabledDevice (local->fd);
580 XisbFree(priv->buffer);
583 xf86CloseSerial(local->fd);
587 xf86RemoveEnabledDevice (local);
588 dev->public.on = FALSE;
593 DeviceClose (DeviceIntPtr dev)
595 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
597 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
603 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
605 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
607 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
611 DeviceInit (DeviceIntPtr dev)
614 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
615 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
616 unsigned char map[] = {0, 1, 2, 3};
617 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
621 btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
622 btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
623 btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
625 if ((priv->flags & ABSOLUTE_FLAG))
627 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
628 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
629 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
632 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
633 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
634 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Z);
638 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
641 if (InitButtonClassDeviceStruct (dev, 3,
642 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
647 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
651 if (InitFocusClassDeviceStruct (dev) == FALSE)
653 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
657 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
658 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
664 if (InitValuatorClassDeviceStruct (dev, 3,
665 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
668 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
672 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
675 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
681 InitValuatorAxisStruct(dev,
683 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
687 #if XORG_BOTCHED_INPUT
688 screenInfo.screens[0]->width,
690 priv->acecadMaxX, /* max val */
692 1000, /* resolution */
695 InitValuatorAxisStruct(dev,
697 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
701 #if XORG_BOTCHED_INPUT
702 screenInfo.screens[0]->height,
704 priv->acecadMaxY, /* max val */
706 1000, /* resolution */
709 InitValuatorAxisStruct(dev,
711 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
715 priv->acecadMaxZ, /* max val */
716 1000, /* resolution */
722 if (InitProximityClassDeviceStruct (dev) == FALSE)
724 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
728 xf86MotionHistoryAllocate (local);
731 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
732 connaitre la taille... */
734 if (priv->acecadInc > 95)
735 priv->acecadInc = 95;
736 if (priv->acecadInc < 1)
738 /* guess the best increment value given video mode */
739 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
740 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
742 priv->acecadInc = rx;
744 priv->acecadInc = ry;
745 if (priv->acecadInc < 1)
749 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
755 ReadInput (LocalDevicePtr local)
759 int is_core_pointer = 0, is_absolute;
760 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
762 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
764 is_absolute = (priv->flags & ABSOLUTE_FLAG);
765 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
766 is_core_pointer = xf86IsCorePointer(local->dev);
770 * set blocking to -1 on the first call because we know there is data to
771 * read. Xisb automatically clears it after one successful read so that
772 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
773 * read from blocking indefinately.
775 XisbBlockDuration (priv->buffer, -1);
777 while (AceCadGetPacket (priv) == Success)
779 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
780 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
782 if (!(priv->flags & ABSOLUTE_FLAG))
784 x = priv->packet[0] & XSIGN_BIT? x:-x;
785 y = priv->packet[0] & YSIGN_BIT? y:-y;
789 y = priv->acecadMaxY - y ;
793 z = ((int)priv->packet[5] << 2) |
794 (((int)priv->packet[6] & 0x01) << 1) |
795 (((int)priv->packet[6] & 0x10) >> 4);
797 buttons = ((int)priv->packet[0] & 0x07) |
798 ((int)priv->packet[6] & 0x02 << 2);
800 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
804 if (!(priv->acecadOldProximity))
805 if (!is_core_pointer)
807 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
808 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
811 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
812 || (!is_absolute && (x || y)))
814 if (is_absolute || priv->acecadOldProximity)
816 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
817 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
821 if (priv->acecadOldButtons != buttons)
823 int delta = buttons ^ priv->acecadOldButtons;
827 delta &= ~(1 << (id-1));
829 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
830 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
834 priv->acecadOldButtons = buttons;
835 priv->acecadOldX = x;
836 priv->acecadOldY = y;
837 priv->acecadOldZ = z;
838 priv->acecadOldProximity = prox;
842 if (!is_core_pointer)
843 if (priv->acecadOldProximity)
845 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
846 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
848 priv->acecadOldProximity = 0;
851 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
855 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
857 USBReadInput (LocalDevicePtr local)
860 struct input_event * event;
861 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
862 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
863 int x = priv->acecadOldX;
864 int y = priv->acecadOldY;
865 int z = priv->acecadOldZ;
866 int report_x, report_y;
867 int prox = priv->acecadOldProximity;
868 int buttons = priv->acecadOldButtons;
869 int is_core_pointer = 0;
870 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
871 is_core_pointer = xf86IsCorePointer(local->dev);
873 /* Is autodev active? */
874 int autodev = priv->flags & AUTODEV_FLAG;
875 /* Was the device available last time we checked? */
876 int avail = priv->flags & AVAIL_FLAG;
878 SYSCALL(len = xf86ReadSerial(local->fd, eventbuf, sizeof(eventbuf)));
882 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
885 priv->flags &= ~AVAIL_FLAG;
887 if (AceCadAutoDevProbe(local, 4)) {
888 DeviceOff(local->dev);
889 DeviceOn(local->dev);
896 /* If the device wasn't available last time we checked */
897 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
898 priv->flags |= AVAIL_FLAG;
902 for (event = (struct input_event *)eventbuf;
903 event < (struct input_event *)(eventbuf+len); event++) {
905 switch (event->type) {
906 case EV_SYN: /* 2.6.x */
907 if (event->code != SYN_REPORT)
908 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
911 switch (event->code) {
931 switch (event->code) {
937 buttons = set_bit(buttons,0,event->value);
941 buttons = set_bit(buttons,1,event->value);
945 buttons = set_bit(buttons,2,event->value);
950 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
951 } /* switch event->type */
953 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
954 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
956 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
957 (event->type == EV_ABS && event->code == ABS_MISC)
964 #if XORG_BOTCHED_INPUT
965 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
970 if (!(priv->acecadOldProximity))
971 if (!is_core_pointer)
973 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
977 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
979 if (priv->acecadOldButtons != buttons)
981 int delta = buttons ^ priv->acecadOldButtons;
985 delta &= ~(1 << (id-1));
987 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
993 if (!is_core_pointer)
994 if (priv->acecadOldProximity)
996 xf86PostProximityEvent(local->dev, 0, 0, 3, report_x, report_y, z);
998 priv->acecadOldProximity = 0;
1001 priv->acecadOldButtons = buttons;
1002 priv->acecadOldX = x;
1003 priv->acecadOldY = y;
1004 priv->acecadOldZ = z;
1005 priv->acecadOldProximity = prox;
1007 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
1012 CloseProc (LocalDevicePtr local)
1017 * The ConvertProc function may need to be tailored for your device.
1018 * This function converts the device's valuator outputs to x and y coordinates
1019 * to simulate mouse events.
1022 ConvertProc (LocalDevicePtr local, int first, int num,
1023 int v0, int v1, int v2, int v3, int v4, int v5,
1026 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1028 /* TODO: should have a structure to hold which screen the
1029 * pointer is attached to? */
1030 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
1031 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
1032 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
1033 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
1039 ReverseConvertProc (LocalDevicePtr local,
1043 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1045 // xf86Msg(X_INFO, "%s: reverse coordinate conversion in : %d, %d\n", local->name, x, y);
1046 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
1047 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
1048 // xf86Msg(X_INFO, "%s: reverse coordinate conversion out: %d, %d\n", local->name, valuators[0], valuators[1]);
1054 #define WriteString(str)\
1055 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1059 QueryHardware (AceCadPrivatePtr priv)
1068 /* Prompt Mode in order to not be disturbed */
1069 WriteString(ACECAD_PROMPT_MODE);
1072 while (XisbRead(priv->buffer) >= 0);
1074 /* Ask for Config packet*/
1075 WriteString(ACECAD_CONFIG);
1077 /* Read the packet */
1078 XisbBlockDuration (priv->buffer, 1000000);
1081 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1083 if ((AceCadGetPacket (priv) == Success))
1085 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1086 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1087 priv->acecadMaxZ = 512;
1088 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1093 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1097 #define BITS_PER_LONG (sizeof(long) * 8)
1098 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1099 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1100 #define OFF(x) ((x)%BITS_PER_LONG)
1101 #define LONG(x) ((x)/BITS_PER_LONG)
1105 USBQueryHardware (LocalDevicePtr local)
1107 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1108 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1111 char name[256] = "Unknown";
1113 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1114 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1116 memset(bit, 0, sizeof(bit));
1117 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1119 for (i = 0; i < EV_MAX; i++)
1120 if (test_bit(i, bit[0])) {
1121 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1122 for (j = 0; j < KEY_MAX; j++)
1123 if (test_bit(j, bit[i])) {
1125 ioctl(local->fd, EVIOCGABS(j), abs);
1128 priv->acecadMaxX = abs[2];
1132 priv->acecadMaxY = abs[2];
1136 priv->acecadMaxZ = abs[2];
1143 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1149 NewPacket (AceCadPrivatePtr priv)
1155 AceCadGetPacket (AceCadPrivatePtr priv)
1160 while((c = XisbRead(priv->buffer)) >= 0 )
1164 * fail after 500 bytes so the server doesn't hang forever if a
1165 * device sends bad data.
1173 if (c & PHASING_BIT)
1177 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1178 XisbBlockDuration (priv->buffer, 10000);
1179 priv->packet[priv->packeti++] = c;
1180 count = ACECAD_PACKET_SIZE - 1;
1181 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1183 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1184 priv->packet[priv->packeti++] = c;
1186 XisbBlockDuration (priv->buffer, 0);