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 #include <X11/Xatom.h>
83 #include <xserver-properties.h>
85 /* Previously found in xf86Xinput.h */
89 #define DBG(lvl, f) {if ((lvl) <= xf86GetVerbosity()) f;}
91 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
92 #error "XINPUT ABI 12 required."
95 /*****************************************************************************
97 ****************************************************************************/
100 /*****************************************************************************
101 * Variables without includable headers
102 ****************************************************************************/
104 /*****************************************************************************
106 ****************************************************************************/
108 /* max number of input events to read in one read call */
109 #define MAX_EVENTS 50
111 static char *default_options[] =
119 "FlowControl", "Xoff",
123 _X_EXPORT InputDriverRec ACECAD =
134 static XF86ModuleVersionInfo VersionRec =
140 XORG_VERSION_CURRENT,
141 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
149 _X_EXPORT XF86ModuleData acecadModuleData = {
155 /*****************************************************************************
156 * Function Definitions
157 ****************************************************************************/
160 SetupProc( pointer module,
165 xf86AddInputDriver(&ACECAD, module, 0);
170 TearDownProc( pointer p )
174 #ifdef HAVE_LINUX_INPUT_H
181 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
184 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
185 version >> 16, (version >> 8) & 0xff, version & 0xff);
188 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
193 /* Heavily inspired by synaptics/eventcomm.c */
195 #define DEV_INPUT_EVENT "/dev/input/event"
196 #define EV_DEV_NAME_MAXLEN 64
197 #define SET_EVENT_NUM(str, num) \
198 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
201 fd_query_acecad(int fd, char *ace_name) {
202 char name[256] = "Unknown";
203 int cmp_at = strlen(ace_name);
206 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
208 if (xf86NameCmp(name, ace_name) == 0)
213 static char ace_name_default[7] = "acecad";
215 #ifdef HAVE_SYSFS_LIBSYSFS_H
216 static char usb_bus_name[4] = "usb";
217 static char acecad_driver_name[11] = "usb_acecad";
221 AceCadAutoDevProbe(InputInfoPtr local, int verb)
223 /* We are trying to find the right eventX device */
225 Bool have_evdev = FALSE;
227 const int max_skip = 10;
228 char *ace_name = xf86FindOptionValue(local->options, "Name");
229 char fname[EV_DEV_NAME_MAXLEN];
232 #ifdef HAVE_SYSFS_LIBSYSFS_H
233 struct sysfs_bus *usb_bus = NULL;
234 struct sysfs_driver *acecad_driver = NULL;
235 struct sysfs_device *candidate = NULL;
237 struct dlist *devs = NULL;
238 struct dlist *links = NULL;
240 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
241 usb_bus = sysfs_open_bus(usb_bus_name);
243 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
244 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
246 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
247 devs = sysfs_get_driver_devices(acecad_driver);
249 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
250 dlist_for_each_data(devs, candidate, struct sysfs_device) {
251 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
252 links = sysfs_open_link_list(candidate->path);
253 dlist_for_each_data(links, link, char) {
254 if (sscanf(link, "input:event%d", &i) == 1) {
255 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
259 sysfs_close_list(links);
260 if (i > 0) /* We found something */
264 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
266 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
268 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
269 sysfs_close_bus(usb_bus);
272 /* We found something */
273 np = SET_EVENT_NUM(fname, i);
274 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
275 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
280 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
285 ace_name = ace_name_default;
287 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
292 np = SET_EVENT_NUM(fname, i);
293 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
294 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
297 SYSCALL(fd = open(fname, O_RDONLY));
299 if (errno == ENOENT) {
300 if (++noent_cnt >= max_skip)
310 is_acecad = fd_query_acecad(fd, ace_name);
316 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
317 local->name, i + 1, ace_name);
319 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
321 if (i > max_skip && !have_evdev)
322 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
326 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
328 xf86ReplaceStrOption(local->options, "Device", fname);
335 AceCadPreInit(InputDriverPtr drv, InputInfoPtr local, int flags)
337 AceCadPrivatePtr priv = calloc (1, sizeof(AceCadPrivateRec));
345 memset(priv, 0, sizeof(AceCadPrivateRec));
346 local->private = priv;
348 local->device_control = DeviceControl;
349 local->type_name = XI_TABLET;
351 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
353 s = xf86FindOptionValue(local->options, "Device");
354 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
355 #ifdef HAVE_LINUX_INPUT_H
356 priv->flags |= AUTODEV_FLAG;
357 if (!AceCadAutoDevProbe(local, 0))
359 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
363 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
368 local->fd = xf86OpenSerial (local->options);
371 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
374 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
376 #ifdef HAVE_LINUX_INPUT_H
377 if (IsUSBLine(local->fd)) {
378 priv->flags |= USB_FLAG;
380 local->read_input = USBReadInput;
382 if (USBQueryHardware(local) != Success)
384 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
390 local->read_input = ReadInput;
393 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
395 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
403 priv->acecadReportSpeed = 'Q';
406 priv->acecadReportSpeed = 'R';
409 priv->acecadReportSpeed = 'S';
412 priv->acecadReportSpeed = 'T';
415 priv->acecadReportSpeed = 'R';
417 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
421 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
423 priv->buffer = XisbNew (local->fd, 200);
426 * Verify that hardware is attached and fuctional
428 if (QueryHardware(priv) != Success)
430 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
435 s = xf86FindOptionValue(local->options, "Mode");
436 msgtype = s ? X_CONFIG : X_DEFAULT;
437 if (!(s && (xf86NameCmp(s, "relative") == 0)))
439 priv->flags |= ABSOLUTE_FLAG;
442 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
443 DBG (9, XisbTrace (priv->buffer, 1));
445 xf86ProcessCommonOptions(local, local->options);
449 RemoveEnabledDevice (local->fd);
452 XisbFree(priv->buffer);
455 xf86CloseSerial(local->fd);
457 RemoveEnabledDevice (local->fd);
462 * If something went wrong, cleanup and return NULL
465 if ((local) && (local->fd))
466 xf86CloseSerial (local->fd);
467 if ((priv) && (priv->buffer))
468 XisbFree (priv->buffer);
472 local->private = NULL;
478 DeviceControl (DeviceIntPtr dev, int mode)
489 RetValue = DeviceOn(dev);
492 RetValue = DeviceOff(dev);
495 RetValue = DeviceClose(dev);
505 DeviceOn (DeviceIntPtr dev)
508 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
509 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
511 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
513 local->fd = xf86OpenSerial(local->options);
516 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
517 priv->flags &= ~AVAIL_FLAG;
518 #ifdef HAVE_LINUX_INPUT_H
519 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
520 local->fd = xf86OpenSerial(local->options);
525 priv->flags |= AVAIL_FLAG;
528 if (!(priv->flags & USB_FLAG)) {
529 priv->buffer = XisbNew(local->fd, 200);
532 xf86CloseSerial(local->fd);
537 /* Rets qu'a l'envoyer a la tablette */
538 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
539 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
542 xf86FlushInput(local->fd);
543 xf86AddEnabledDevice (local);
544 dev->public.on = TRUE;
549 DeviceOff (DeviceIntPtr dev)
551 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
552 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
554 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
558 RemoveEnabledDevice (local->fd);
561 XisbFree(priv->buffer);
564 xf86CloseSerial(local->fd);
568 xf86RemoveEnabledDevice (local);
569 dev->public.on = FALSE;
574 DeviceClose (DeviceIntPtr dev)
576 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
578 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
584 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
586 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
588 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
592 DeviceInit (DeviceIntPtr dev)
595 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
596 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
597 unsigned char map[] = {0, 1, 2, 3};
602 btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
603 btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
604 btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
606 if ((priv->flags & ABSOLUTE_FLAG))
608 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
609 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
610 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
613 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
614 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
615 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Z);
618 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
621 if (InitButtonClassDeviceStruct (dev, 3,
625 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
629 if (InitFocusClassDeviceStruct (dev) == FALSE)
631 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
635 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
636 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
640 history_size = xf86SetIntOption(local->options , "HistorySize", 0);
643 if (InitValuatorClassDeviceStruct (dev, 3,
646 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
649 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
655 InitValuatorAxisStruct(dev,
659 #if XORG_BOTCHED_INPUT
660 screenInfo.screens[0]->width,
662 priv->acecadMaxX, /* max val */
664 1000, /* resolution */
669 InitValuatorAxisStruct(dev,
673 #if XORG_BOTCHED_INPUT
674 screenInfo.screens[0]->height,
676 priv->acecadMaxY, /* max val */
678 1000, /* resolution */
683 InitValuatorAxisStruct(dev,
687 priv->acecadMaxZ, /* max val */
688 1000, /* resolution */
696 if (InitProximityClassDeviceStruct (dev) == FALSE)
698 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
702 xf86MotionHistoryAllocate (local);
705 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
706 connaitre la taille... */
708 if (priv->acecadInc > 95)
709 priv->acecadInc = 95;
710 if (priv->acecadInc < 1)
712 /* guess the best increment value given video mode */
713 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
714 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
716 priv->acecadInc = rx;
718 priv->acecadInc = ry;
719 if (priv->acecadInc < 1)
723 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
729 ReadInput (InputInfoPtr local)
734 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
736 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
738 is_absolute = (priv->flags & ABSOLUTE_FLAG);
741 * set blocking to -1 on the first call because we know there is data to
742 * read. Xisb automatically clears it after one successful read so that
743 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
744 * read from blocking indefinately.
746 XisbBlockDuration (priv->buffer, -1);
748 while (AceCadGetPacket (priv) == Success)
750 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
751 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
753 if (!(priv->flags & ABSOLUTE_FLAG))
755 x = priv->packet[0] & XSIGN_BIT? x:-x;
756 y = priv->packet[0] & YSIGN_BIT? y:-y;
760 y = priv->acecadMaxY - y ;
764 z = ((int)priv->packet[5] << 2) |
765 (((int)priv->packet[6] & 0x01) << 1) |
766 (((int)priv->packet[6] & 0x10) >> 4);
768 buttons = ((int)priv->packet[0] & 0x07) |
769 ((int)priv->packet[6] & 0x02 << 2);
771 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
775 if (!(priv->acecadOldProximity))
777 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
778 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
781 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
782 || (!is_absolute && (x || y)))
784 if (is_absolute || priv->acecadOldProximity)
786 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
787 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
791 if (priv->acecadOldButtons != buttons)
793 int delta = buttons ^ priv->acecadOldButtons;
797 delta &= ~(1 << (id-1));
799 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
800 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
804 priv->acecadOldButtons = buttons;
805 priv->acecadOldX = x;
806 priv->acecadOldY = y;
807 priv->acecadOldZ = z;
808 priv->acecadOldProximity = prox;
812 if (priv->acecadOldProximity)
814 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
815 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
817 priv->acecadOldProximity = 0;
820 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
823 #ifdef HAVE_LINUX_INPUT_H
824 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
826 USBReadInput (InputInfoPtr local)
829 struct input_event * event;
830 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
831 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
832 int x = priv->acecadOldX;
833 int y = priv->acecadOldY;
834 int z = priv->acecadOldZ;
835 int report_x = 0, report_y = 0;
836 int prox = priv->acecadOldProximity;
837 int buttons = priv->acecadOldButtons;
838 /* Is autodev active? */
839 int autodev = priv->flags & AUTODEV_FLAG;
840 /* Was the device available last time we checked? */
841 int avail = priv->flags & AVAIL_FLAG;
843 SYSCALL(len = xf86ReadSerial(local->fd, eventbuf, sizeof(eventbuf)));
847 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
850 priv->flags &= ~AVAIL_FLAG;
852 if (AceCadAutoDevProbe(local, 4)) {
853 DeviceOff(local->dev);
854 DeviceOn(local->dev);
861 /* If the device wasn't available last time we checked */
862 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
863 priv->flags |= AVAIL_FLAG;
867 for (event = (struct input_event *)eventbuf;
868 event < (struct input_event *)(eventbuf+len); event++) {
870 switch (event->type) {
871 case EV_SYN: /* 2.6.x */
872 if (event->code != SYN_REPORT)
873 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
876 switch (event->code) {
896 switch (event->code) {
902 buttons = set_bit(buttons,0,event->value);
906 buttons = set_bit(buttons,1,event->value);
910 buttons = set_bit(buttons,2,event->value);
915 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
916 } /* switch event->type */
918 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
919 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
921 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
922 (event->type == EV_ABS && event->code == ABS_MISC)
929 #if XORG_BOTCHED_INPUT
930 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
935 if (!(priv->acecadOldProximity))
937 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
941 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
943 if (priv->acecadOldButtons != buttons)
945 int delta = buttons ^ priv->acecadOldButtons;
949 delta &= ~(1 << (id-1));
951 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
957 if (priv->acecadOldProximity)
959 xf86PostProximityEvent(local->dev, 0, 0, 3, report_x, report_y, z);
961 priv->acecadOldProximity = 0;
964 priv->acecadOldButtons = buttons;
965 priv->acecadOldX = x;
966 priv->acecadOldY = y;
967 priv->acecadOldZ = z;
968 priv->acecadOldProximity = prox;
970 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
975 * The ConvertProc function may need to be tailored for your device.
976 * This function converts the device's valuator outputs to x and y coordinates
977 * to simulate mouse events.
980 ConvertProc (InputInfoPtr local, int first, int num,
981 int v0, int v1, int v2, int v3, int v4, int v5,
984 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
986 /* TODO: should have a structure to hold which screen the
987 * pointer is attached to? */
988 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
989 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
990 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
991 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
996 #define WriteString(str)\
997 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1001 QueryHardware (AceCadPrivatePtr priv)
1010 /* Prompt Mode in order to not be disturbed */
1011 WriteString(ACECAD_PROMPT_MODE);
1014 while (XisbRead(priv->buffer) >= 0);
1016 /* Ask for Config packet*/
1017 WriteString(ACECAD_CONFIG);
1019 /* Read the packet */
1020 XisbBlockDuration (priv->buffer, 1000000);
1023 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1025 if ((AceCadGetPacket (priv) == Success))
1027 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1028 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1029 priv->acecadMaxZ = 512;
1030 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1035 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1039 #define BITS_PER_LONG (sizeof(long) * 8)
1040 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1041 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1042 #define OFF(x) ((x)%BITS_PER_LONG)
1043 #define LONG(x) ((x)/BITS_PER_LONG)
1045 #ifdef HAVE_LINUX_INPUT_H
1047 USBQueryHardware (InputInfoPtr local)
1049 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1050 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1053 char name[256] = "Unknown";
1055 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1056 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1058 memset(bit, 0, sizeof(bit));
1059 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1061 for (i = 0; i < EV_MAX; i++)
1062 if (test_bit(i, bit[0])) {
1063 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1064 for (j = 0; j < KEY_MAX; j++)
1065 if (test_bit(j, bit[i])) {
1067 ioctl(local->fd, EVIOCGABS(j), abs);
1070 priv->acecadMaxX = abs[2];
1074 priv->acecadMaxY = abs[2];
1078 priv->acecadMaxZ = abs[2];
1085 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1091 NewPacket (AceCadPrivatePtr priv)
1097 AceCadGetPacket (AceCadPrivatePtr priv)
1102 while((c = XisbRead(priv->buffer)) >= 0 )
1106 * fail after 500 bytes so the server doesn't hang forever if a
1107 * device sends bad data.
1115 if (c & PHASING_BIT)
1119 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1120 XisbBlockDuration (priv->buffer, 10000);
1121 priv->packet[priv->packeti++] = c;
1122 count = ACECAD_PACKET_SIZE - 1;
1123 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1125 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1126 priv->packet[priv->packeti++] = c;
1128 XisbBlockDuration (priv->buffer, 0);