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
31 #include <xorg-server.h>
32 #include <xorgVersion.h>
33 #define XORG_VERSION_BOTCHED XORG_VERSION_NUMERIC(1,4,0,0,0)
34 #if XORG_VERSION_CURRENT >= XORG_VERSION_BOTCHED
35 #define XORG_BOTCHED_INPUT 1
37 #define XORG_BOTCHED_INPUT 0
40 /*****************************************************************************
42 ****************************************************************************/
44 #ifdef HAVE_LINUX_INPUT_H
45 #include <asm/types.h>
46 #include <linux/input.h>
61 #ifndef NEED_XF86_TYPES
62 #define NEED_XF86_TYPES
64 #include <xf86_OSproc.h>
66 #include <xf86Xinput.h>
68 #include <xf86Module.h>
74 #ifdef HAVE_LINUX_INPUT_H
76 #ifdef HAVE_SYSFS_LIBSYSFS_H
77 #include <sysfs/libsysfs.h>
82 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
83 #include <X11/Xatom.h>
84 #include <xserver-properties.h>
87 /* Previously found in xf86Xinput.h */
91 #define DBG(lvl, f) {if ((lvl) <= xf86GetVerbosity()) f;}
93 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
94 #error "XINPUT ABI 12 required."
97 /*****************************************************************************
99 ****************************************************************************/
102 /*****************************************************************************
103 * Variables without includable headers
104 ****************************************************************************/
106 /*****************************************************************************
108 ****************************************************************************/
110 /* max number of input events to read in one read call */
111 #define MAX_EVENTS 50
113 static char *default_options[] =
121 "FlowControl", "Xoff",
125 _X_EXPORT InputDriverRec ACECAD =
133 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
138 static XF86ModuleVersionInfo VersionRec =
144 XORG_VERSION_CURRENT,
145 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
153 _X_EXPORT XF86ModuleData acecadModuleData = {
159 /*****************************************************************************
160 * Function Definitions
161 ****************************************************************************/
164 SetupProc( pointer module,
169 xf86AddInputDriver(&ACECAD, module, 0);
174 TearDownProc( pointer p )
178 #ifdef HAVE_LINUX_INPUT_H
185 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
188 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
189 version >> 16, (version >> 8) & 0xff, version & 0xff);
192 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
197 /* Heavily inspired by synaptics/eventcomm.c */
199 #define DEV_INPUT_EVENT "/dev/input/event"
200 #define EV_DEV_NAME_MAXLEN 64
201 #define SET_EVENT_NUM(str, num) \
202 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
205 fd_query_acecad(int fd, char *ace_name) {
206 char name[256] = "Unknown";
207 int cmp_at = strlen(ace_name);
210 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
212 if (xf86NameCmp(name, ace_name) == 0)
217 static char ace_name_default[7] = "acecad";
219 #ifdef HAVE_SYSFS_LIBSYSFS_H
220 static char usb_bus_name[4] = "usb";
221 static char acecad_driver_name[11] = "usb_acecad";
225 AceCadAutoDevProbe(InputInfoPtr local, int verb)
227 /* We are trying to find the right eventX device */
229 Bool have_evdev = FALSE;
231 const int max_skip = 10;
232 char *ace_name = xf86FindOptionValue(local->options, "Name");
233 char fname[EV_DEV_NAME_MAXLEN];
236 #ifdef HAVE_SYSFS_LIBSYSFS_H
237 struct sysfs_bus *usb_bus = NULL;
238 struct sysfs_driver *acecad_driver = NULL;
239 struct sysfs_device *candidate = NULL;
241 struct dlist *devs = NULL;
242 struct dlist *links = NULL;
244 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
245 usb_bus = sysfs_open_bus(usb_bus_name);
247 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
248 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
250 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
251 devs = sysfs_get_driver_devices(acecad_driver);
253 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
254 dlist_for_each_data(devs, candidate, struct sysfs_device) {
255 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
256 links = sysfs_open_link_list(candidate->path);
257 dlist_for_each_data(links, link, char) {
258 if (sscanf(link, "input:event%d", &i) == 1) {
259 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
263 sysfs_close_list(links);
264 if (i > 0) /* We found something */
268 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
270 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
272 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
273 sysfs_close_bus(usb_bus);
276 /* We found something */
277 np = SET_EVENT_NUM(fname, i);
278 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
279 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
284 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
289 ace_name = ace_name_default;
291 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
296 np = SET_EVENT_NUM(fname, i);
297 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
298 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
301 SYSCALL(fd = open(fname, O_RDONLY));
303 if (errno == ENOENT) {
304 if (++noent_cnt >= max_skip)
314 is_acecad = fd_query_acecad(fd, ace_name);
320 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
321 local->name, i + 1, ace_name);
323 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
325 if (i > max_skip && !have_evdev)
326 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
330 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
332 xf86ReplaceStrOption(local->options, "Device", fname);
339 AceCadPreInit(InputDriverPtr drv, InputInfoPtr local, int flags)
341 AceCadPrivatePtr priv = calloc (1, sizeof(AceCadPrivateRec));
349 memset(priv, 0, sizeof(AceCadPrivateRec));
351 local->device_control = DeviceControl;
353 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
355 s = xf86FindOptionValue(local->options, "Device");
356 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
357 #ifdef HAVE_LINUX_INPUT_H
358 priv->flags |= AUTODEV_FLAG;
359 if (!AceCadAutoDevProbe(local, 0))
361 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
365 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
370 local->fd = xf86OpenSerial (local->options);
373 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
376 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
378 #ifdef HAVE_LINUX_INPUT_H
379 if (IsUSBLine(local->fd)) {
380 priv->flags |= USB_FLAG;
382 local->read_input = USBReadInput;
384 if (USBQueryHardware(local) != Success)
386 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
392 local->read_input = ReadInput;
395 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
397 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
405 priv->acecadReportSpeed = 'Q';
408 priv->acecadReportSpeed = 'R';
411 priv->acecadReportSpeed = 'S';
414 priv->acecadReportSpeed = 'T';
417 priv->acecadReportSpeed = 'R';
419 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
423 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
425 priv->buffer = XisbNew (local->fd, 200);
428 * Verify that hardware is attached and fuctional
430 if (QueryHardware(priv) != Success)
432 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
437 s = xf86FindOptionValue(local->options, "Mode");
438 msgtype = s ? X_CONFIG : X_DEFAULT;
439 if (!(s && (xf86NameCmp(s, "relative") == 0)))
441 priv->flags |= ABSOLUTE_FLAG;
444 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
445 DBG (9, XisbTrace (priv->buffer, 1));
447 xf86ProcessCommonOptions(local, local->options);
451 RemoveEnabledDevice (local->fd);
454 XisbFree(priv->buffer);
457 xf86CloseSerial(local->fd);
459 RemoveEnabledDevice (local->fd);
464 * If something went wrong, cleanup and return NULL
467 if ((local) && (local->fd))
468 xf86CloseSerial (local->fd);
469 if ((priv) && (priv->buffer))
470 XisbFree (priv->buffer);
474 local->private = NULL;
476 xf86DeleteInput(local, 0);
481 DeviceControl (DeviceIntPtr dev, int mode)
492 RetValue = DeviceOn(dev);
495 RetValue = DeviceOff(dev);
498 RetValue = DeviceClose(dev);
508 DeviceOn (DeviceIntPtr dev)
511 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
512 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
514 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
516 local->fd = xf86OpenSerial(local->options);
519 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
520 priv->flags &= ~AVAIL_FLAG;
521 #ifdef HAVE_LINUX_INPUT_H
522 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
523 local->fd = xf86OpenSerial(local->options);
528 priv->flags |= AVAIL_FLAG;
531 if (!(priv->flags & USB_FLAG)) {
532 priv->buffer = XisbNew(local->fd, 200);
535 xf86CloseSerial(local->fd);
540 /* Rets qu'a l'envoyer a la tablette */
541 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
542 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
545 xf86FlushInput(local->fd);
546 xf86AddEnabledDevice (local);
547 dev->public.on = TRUE;
552 DeviceOff (DeviceIntPtr dev)
554 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
555 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
557 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
561 RemoveEnabledDevice (local->fd);
564 XisbFree(priv->buffer);
567 xf86CloseSerial(local->fd);
571 xf86RemoveEnabledDevice (local);
572 dev->public.on = FALSE;
577 DeviceClose (DeviceIntPtr dev)
579 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
581 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
587 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
589 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
591 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
595 DeviceInit (DeviceIntPtr dev)
598 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
599 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
600 unsigned char map[] = {0, 1, 2, 3};
602 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
606 btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
607 btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
608 btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
610 if ((priv->flags & ABSOLUTE_FLAG))
612 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
613 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
614 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
617 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
618 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
619 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Z);
623 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
626 if (InitButtonClassDeviceStruct (dev, 3,
627 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
632 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
636 if (InitFocusClassDeviceStruct (dev) == FALSE)
638 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
642 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
643 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
647 history_size = xf86SetIntOption(local->options , "HistorySize", 0);
650 if (InitValuatorClassDeviceStruct (dev, 3,
651 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
655 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
658 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
664 InitValuatorAxisStruct(dev,
666 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
670 #if XORG_BOTCHED_INPUT
671 screenInfo.screens[0]->width,
673 priv->acecadMaxX, /* max val */
675 1000, /* resolution */
678 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
682 InitValuatorAxisStruct(dev,
684 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
688 #if XORG_BOTCHED_INPUT
689 screenInfo.screens[0]->height,
691 priv->acecadMaxY, /* max val */
693 1000, /* resolution */
696 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
700 InitValuatorAxisStruct(dev,
702 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
706 priv->acecadMaxZ, /* max val */
707 1000, /* resolution */
710 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
717 if (InitProximityClassDeviceStruct (dev) == FALSE)
719 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
723 xf86MotionHistoryAllocate (local);
726 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
727 connaitre la taille... */
729 if (priv->acecadInc > 95)
730 priv->acecadInc = 95;
731 if (priv->acecadInc < 1)
733 /* guess the best increment value given video mode */
734 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
735 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
737 priv->acecadInc = rx;
739 priv->acecadInc = ry;
740 if (priv->acecadInc < 1)
744 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
750 ReadInput (InputInfoPtr local)
754 int is_core_pointer = 0, is_absolute;
755 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
757 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
759 is_absolute = (priv->flags & ABSOLUTE_FLAG);
762 * set blocking to -1 on the first call because we know there is data to
763 * read. Xisb automatically clears it after one successful read so that
764 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
765 * read from blocking indefinately.
767 XisbBlockDuration (priv->buffer, -1);
769 while (AceCadGetPacket (priv) == Success)
771 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
772 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
774 if (!(priv->flags & ABSOLUTE_FLAG))
776 x = priv->packet[0] & XSIGN_BIT? x:-x;
777 y = priv->packet[0] & YSIGN_BIT? y:-y;
781 y = priv->acecadMaxY - y ;
785 z = ((int)priv->packet[5] << 2) |
786 (((int)priv->packet[6] & 0x01) << 1) |
787 (((int)priv->packet[6] & 0x10) >> 4);
789 buttons = ((int)priv->packet[0] & 0x07) |
790 ((int)priv->packet[6] & 0x02 << 2);
792 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
796 if (!(priv->acecadOldProximity))
797 if (!is_core_pointer)
799 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
800 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
803 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
804 || (!is_absolute && (x || y)))
806 if (is_absolute || priv->acecadOldProximity)
808 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
809 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
813 if (priv->acecadOldButtons != buttons)
815 int delta = buttons ^ priv->acecadOldButtons;
819 delta &= ~(1 << (id-1));
821 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
822 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
826 priv->acecadOldButtons = buttons;
827 priv->acecadOldX = x;
828 priv->acecadOldY = y;
829 priv->acecadOldZ = z;
830 priv->acecadOldProximity = prox;
834 if (!is_core_pointer)
835 if (priv->acecadOldProximity)
837 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
838 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
840 priv->acecadOldProximity = 0;
843 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
846 #ifdef HAVE_LINUX_INPUT_H
847 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
849 USBReadInput (InputInfoPtr local)
852 struct input_event * event;
853 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
854 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
855 int x = priv->acecadOldX;
856 int y = priv->acecadOldY;
857 int z = priv->acecadOldZ;
858 int report_x = 0, report_y = 0;
859 int prox = priv->acecadOldProximity;
860 int buttons = priv->acecadOldButtons;
861 int is_core_pointer = 0;
862 /* Is autodev active? */
863 int autodev = priv->flags & AUTODEV_FLAG;
864 /* Was the device available last time we checked? */
865 int avail = priv->flags & AVAIL_FLAG;
867 SYSCALL(len = xf86ReadSerial(local->fd, eventbuf, sizeof(eventbuf)));
871 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
874 priv->flags &= ~AVAIL_FLAG;
876 if (AceCadAutoDevProbe(local, 4)) {
877 DeviceOff(local->dev);
878 DeviceOn(local->dev);
885 /* If the device wasn't available last time we checked */
886 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
887 priv->flags |= AVAIL_FLAG;
891 for (event = (struct input_event *)eventbuf;
892 event < (struct input_event *)(eventbuf+len); event++) {
894 switch (event->type) {
895 case EV_SYN: /* 2.6.x */
896 if (event->code != SYN_REPORT)
897 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
900 switch (event->code) {
920 switch (event->code) {
926 buttons = set_bit(buttons,0,event->value);
930 buttons = set_bit(buttons,1,event->value);
934 buttons = set_bit(buttons,2,event->value);
939 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
940 } /* switch event->type */
942 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
943 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
945 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
946 (event->type == EV_ABS && event->code == ABS_MISC)
953 #if XORG_BOTCHED_INPUT
954 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
959 if (!(priv->acecadOldProximity))
960 if (!is_core_pointer)
962 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
966 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
968 if (priv->acecadOldButtons != buttons)
970 int delta = buttons ^ priv->acecadOldButtons;
974 delta &= ~(1 << (id-1));
976 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
982 if (!is_core_pointer)
983 if (priv->acecadOldProximity)
985 xf86PostProximityEvent(local->dev, 0, 0, 3, report_x, report_y, z);
987 priv->acecadOldProximity = 0;
990 priv->acecadOldButtons = buttons;
991 priv->acecadOldX = x;
992 priv->acecadOldY = y;
993 priv->acecadOldZ = z;
994 priv->acecadOldProximity = prox;
996 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
1001 * The ConvertProc function may need to be tailored for your device.
1002 * This function converts the device's valuator outputs to x and y coordinates
1003 * to simulate mouse events.
1006 ConvertProc (InputInfoPtr local, int first, int num,
1007 int v0, int v1, int v2, int v3, int v4, int v5,
1010 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1012 /* TODO: should have a structure to hold which screen the
1013 * pointer is attached to? */
1014 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
1015 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
1016 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
1017 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
1022 #define WriteString(str)\
1023 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1027 QueryHardware (AceCadPrivatePtr priv)
1036 /* Prompt Mode in order to not be disturbed */
1037 WriteString(ACECAD_PROMPT_MODE);
1040 while (XisbRead(priv->buffer) >= 0);
1042 /* Ask for Config packet*/
1043 WriteString(ACECAD_CONFIG);
1045 /* Read the packet */
1046 XisbBlockDuration (priv->buffer, 1000000);
1049 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1051 if ((AceCadGetPacket (priv) == Success))
1053 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1054 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1055 priv->acecadMaxZ = 512;
1056 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1061 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1065 #define BITS_PER_LONG (sizeof(long) * 8)
1066 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1067 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1068 #define OFF(x) ((x)%BITS_PER_LONG)
1069 #define LONG(x) ((x)/BITS_PER_LONG)
1071 #ifdef HAVE_LINUX_INPUT_H
1073 USBQueryHardware (InputInfoPtr local)
1075 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1076 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1079 char name[256] = "Unknown";
1081 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1082 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1084 memset(bit, 0, sizeof(bit));
1085 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1087 for (i = 0; i < EV_MAX; i++)
1088 if (test_bit(i, bit[0])) {
1089 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1090 for (j = 0; j < KEY_MAX; j++)
1091 if (test_bit(j, bit[i])) {
1093 ioctl(local->fd, EVIOCGABS(j), abs);
1096 priv->acecadMaxX = abs[2];
1100 priv->acecadMaxY = abs[2];
1104 priv->acecadMaxZ = abs[2];
1111 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1117 NewPacket (AceCadPrivatePtr priv)
1123 AceCadGetPacket (AceCadPrivatePtr priv)
1128 while((c = XisbRead(priv->buffer)) >= 0 )
1132 * fail after 500 bytes so the server doesn't hang forever if a
1133 * device sends bad data.
1141 if (c & PHASING_BIT)
1145 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1146 XisbBlockDuration (priv->buffer, 10000);
1147 priv->packet[priv->packeti++] = c;
1148 count = ACECAD_PACKET_SIZE - 1;
1149 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1151 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1152 priv->packet[priv->packeti++] = c;
1154 XisbBlockDuration (priv->buffer, 0);