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
26 /* $XFree86: xc/programs/Xserver/hw/xfree86/input/acecad/acecad.c,v 1.4 2003/10/30 00:40:45 dawes Exp $ */
30 #include <xorgVersion.h>
31 #define XORG_VERSION_BOTCHED XORG_VERSION_NUMERIC(1,4,0,0,0)
32 #if XORG_VERSION_CURRENT >= XORG_VERSION_BOTCHED
33 #define XORG_BOTCHED_INPUT 1
35 #define XORG_BOTCHED_INPUT 0
39 /*****************************************************************************
41 ****************************************************************************/
44 #include <asm/types.h>
45 #include <linux/input.h>
60 #ifndef NEED_XF86_TYPES
61 #define NEED_XF86_TYPES
63 #include <xf86_OSproc.h>
65 #include <xf86Xinput.h>
67 #include <xf86Module.h>
76 #include <sysfs/libsysfs.h>
81 /* Previously found in xf86Xinput.h */
85 #define DBG(lvl, f) {if ((lvl) <= xf86GetVerbosity()) f;}
87 /*****************************************************************************
89 ****************************************************************************/
92 /*****************************************************************************
93 * Variables without includable headers
94 ****************************************************************************/
96 /*****************************************************************************
98 ****************************************************************************/
101 #define read(a,b,c) xf86ReadSerial((a),(b),(c))
103 /* max number of input events to read in one read call */
104 #define MAX_EVENTS 50
106 _X_EXPORT InputDriverRec ACECAD =
118 static XF86ModuleVersionInfo VersionRec =
124 XORG_VERSION_CURRENT,
125 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
133 _X_EXPORT XF86ModuleData acecadModuleData = {
139 /*****************************************************************************
140 * Function Definitions
141 ****************************************************************************/
144 SetupProc( pointer module,
149 xf86AddInputDriver(&ACECAD, module, 0);
154 TearDownProc( pointer p )
157 LocalDevicePtr local = (LocalDevicePtr) p;
158 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
160 DeviceOff (local->dev);
162 xf86CloseSerial (local->fd);
163 XisbFree (priv->buffer);
171 static const char *default_options[] =
179 "FlowControl", "Xoff",
190 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
193 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
194 version >> 16, (version >> 8) & 0xff, version & 0xff);
197 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
202 /* Heavily inspired by synaptics/eventcomm.c */
204 #define DEV_INPUT_EVENT "/dev/input/event"
205 #define EV_DEV_NAME_MAXLEN 64
206 #define SET_EVENT_NUM(str, num) \
207 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
210 fd_query_acecad(int fd, char *ace_name) {
211 char name[256] = "Unknown";
212 int cmp_at = strlen(ace_name);
215 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
217 if (xf86NameCmp(name, ace_name) == 0)
222 static char ace_name_default[7] = "acecad";
225 static char usb_bus_name[4] = "usb";
226 static char acecad_driver_name[11] = "usb_acecad";
230 AceCadAutoDevProbe(LocalDevicePtr local, int verb)
232 /* We are trying to find the right eventX device */
234 Bool have_evdev = FALSE;
236 const int max_skip = 10;
237 char *ace_name = xf86FindOptionValue(local->options, "Name");
238 char fname[EV_DEV_NAME_MAXLEN];
242 struct sysfs_bus *usb_bus = NULL;
243 struct sysfs_driver *acecad_driver = NULL;
244 struct sysfs_device *candidate = NULL;
246 struct dlist *devs = NULL;
247 struct dlist *links = NULL;
249 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
250 usb_bus = sysfs_open_bus(usb_bus_name);
252 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
253 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
255 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
256 devs = sysfs_get_driver_devices(acecad_driver);
258 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
259 dlist_for_each_data(devs, candidate, struct sysfs_device) {
260 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
261 links = sysfs_open_link_list(candidate->path);
262 dlist_for_each_data(links, link, char) {
263 if (sscanf(link, "input:event%d", &i) == 1) {
264 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
268 sysfs_close_list(links);
269 if (i > 0) /* We found something */
273 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
275 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
277 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
278 sysfs_close_bus(usb_bus);
281 /* We found something */
282 np = SET_EVENT_NUM(fname, i);
283 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
284 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
289 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
294 ace_name = ace_name_default;
296 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
301 np = SET_EVENT_NUM(fname, i);
302 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
303 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
306 SYSCALL(fd = open(fname, O_RDONLY));
308 if (errno == ENOENT) {
309 if (++noent_cnt >= max_skip)
319 is_acecad = fd_query_acecad(fd, ace_name);
325 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
326 local->name, i + 1, ace_name);
328 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
330 if (i > max_skip && !have_evdev)
331 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
335 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
337 xf86ReplaceStrOption(local->options, "Device", fname);
344 AceCadPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
346 LocalDevicePtr local = xf86AllocateInput(drv, 0);
347 AceCadPrivatePtr priv = xcalloc (1, sizeof(AceCadPrivateRec));
352 if ((!local) || (!priv))
355 memset(priv, 0, sizeof(AceCadPrivateRec));
357 local->name = dev->identifier;
358 local->type_name = XI_TABLET;
359 local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
360 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
361 local->motion_history_proc = xf86GetMotionEvents;
363 local->control_proc = NULL;
364 local->close_proc = CloseProc;
365 local->switch_mode = NULL;
366 local->conversion_proc = ConvertProc;
367 local->reverse_conversion_proc = ReverseConvertProc;
369 local->private = priv;
370 local->private_flags = 0;
371 local->conf_idev = dev;
372 local->device_control = DeviceControl;
373 /*local->always_core_feedback = 0;*/
375 xf86CollectInputOptions(local, default_options, NULL);
377 xf86OptionListReport(local->options);
379 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
381 s = xf86FindOptionValue(local->options, "Device");
382 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
384 priv->flags |= AUTODEV_FLAG;
385 if (!AceCadAutoDevProbe(local, 0))
387 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
391 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
396 local->fd = xf86OpenSerial (local->options);
399 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
402 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
405 if (IsUSBLine(local->fd)) {
406 priv->flags |= USB_FLAG;
408 local->read_input = USBReadInput;
410 if (USBQueryHardware(local) != Success)
412 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
418 local->read_input = ReadInput;
421 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
423 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
431 priv->acecadReportSpeed = 'Q';
434 priv->acecadReportSpeed = 'R';
437 priv->acecadReportSpeed = 'S';
440 priv->acecadReportSpeed = 'T';
443 priv->acecadReportSpeed = 'R';
445 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
449 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
451 priv->buffer = XisbNew (local->fd, 200);
454 * Verify that hardware is attached and fuctional
456 if (QueryHardware(priv) != Success)
458 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
463 s = xf86FindOptionValue(local->options, "Mode");
464 msgtype = s ? X_CONFIG : X_DEFAULT;
465 if (!(s && (xf86NameCmp(s, "relative") == 0)))
467 priv->flags |= ABSOLUTE_FLAG;
470 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
471 DBG (9, XisbTrace (priv->buffer, 1));
473 local->history_size = xf86SetIntOption(local->options , "HistorySize", 0);
475 xf86ProcessCommonOptions(local, local->options);
477 local->flags |= XI86_CONFIGURED;
481 RemoveEnabledDevice (local->fd);
484 XisbFree(priv->buffer);
487 xf86CloseSerial(local->fd);
489 RemoveEnabledDevice (local->fd);
494 * If something went wrong, cleanup and return NULL
497 if ((local) && (local->fd))
498 xf86CloseSerial (local->fd);
499 if ((priv) && (priv->buffer))
500 XisbFree (priv->buffer);
504 local->private = NULL;
506 xf86DeleteInput(local, 0);
511 DeviceControl (DeviceIntPtr dev, int mode)
522 RetValue = DeviceOn(dev);
525 RetValue = DeviceOff(dev);
528 RetValue = DeviceClose(dev);
538 DeviceOn (DeviceIntPtr dev)
541 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
542 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
544 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
546 local->fd = xf86OpenSerial(local->options);
549 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
550 priv->flags &= ~AVAIL_FLAG;
552 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
553 local->fd = xf86OpenSerial(local->options);
558 priv->flags |= AVAIL_FLAG;
561 if (!(priv->flags & USB_FLAG)) {
562 priv->buffer = XisbNew(local->fd, 200);
565 xf86CloseSerial(local->fd);
570 /* Rets qu'a l'envoyer a la tablette */
571 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
572 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
575 xf86FlushInput(local->fd);
576 xf86AddEnabledDevice (local);
577 dev->public.on = TRUE;
582 DeviceOff (DeviceIntPtr dev)
584 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
585 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
587 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
591 RemoveEnabledDevice (local->fd);
594 XisbFree(priv->buffer);
597 xf86CloseSerial(local->fd);
601 xf86RemoveEnabledDevice (local);
602 dev->public.on = FALSE;
607 DeviceClose (DeviceIntPtr dev)
609 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
611 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
617 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
619 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
621 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
625 DeviceInit (DeviceIntPtr dev)
628 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
629 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
630 unsigned char map[] =
633 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
636 if (InitButtonClassDeviceStruct (dev, 3, map) == FALSE)
638 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
642 if (InitFocusClassDeviceStruct (dev) == FALSE)
644 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
648 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
649 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
655 if (InitValuatorClassDeviceStruct (dev, 3,
656 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
660 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
663 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
669 InitValuatorAxisStruct(dev,
672 #if XORG_BOTCHED_INPUT
673 screenInfo.screens[0]->width,
675 priv->acecadMaxX, /* max val */
677 1000, /* resolution */
680 InitValuatorAxisStruct(dev,
683 #if XORG_BOTCHED_INPUT
684 screenInfo.screens[0]->height,
686 priv->acecadMaxY, /* max val */
688 1000, /* resolution */
691 InitValuatorAxisStruct(dev,
694 priv->acecadMaxZ, /* max val */
695 1000, /* resolution */
701 if (InitProximityClassDeviceStruct (dev) == FALSE)
703 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
707 xf86MotionHistoryAllocate (local);
710 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
711 connaitre la taille... */
713 if (priv->acecadInc > 95)
714 priv->acecadInc = 95;
715 if (priv->acecadInc < 1)
717 /* guess the best increment value given video mode */
718 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
719 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
721 priv->acecadInc = rx;
723 priv->acecadInc = ry;
724 if (priv->acecadInc < 1)
728 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
734 ReadInput (LocalDevicePtr local)
738 int is_core_pointer = 0, is_absolute;
739 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
741 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
743 is_absolute = (priv->flags & ABSOLUTE_FLAG);
744 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
745 is_core_pointer = xf86IsCorePointer(local->dev);
749 * set blocking to -1 on the first call because we know there is data to
750 * read. Xisb automatically clears it after one successful read so that
751 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
752 * read from blocking indefinately.
754 XisbBlockDuration (priv->buffer, -1);
756 while (AceCadGetPacket (priv) == Success)
758 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
759 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
761 if (!(priv->flags & ABSOLUTE_FLAG))
763 x = priv->packet[0] & XSIGN_BIT? x:-x;
764 y = priv->packet[0] & YSIGN_BIT? y:-y;
768 y = priv->acecadMaxY - y ;
772 z = ((int)priv->packet[5] << 2) |
773 (((int)priv->packet[6] & 0x01) << 1) |
774 (((int)priv->packet[6] & 0x10) >> 4);
776 buttons = ((int)priv->packet[0] & 0x07) |
777 ((int)priv->packet[6] & 0x02 << 2);
779 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
783 if (!(priv->acecadOldProximity))
784 if (!is_core_pointer)
786 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
787 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
790 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
791 || (!is_absolute && (x || y)))
793 if (is_absolute || priv->acecadOldProximity)
795 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
796 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
800 if (priv->acecadOldButtons != buttons)
802 int delta = buttons ^ priv->acecadOldButtons;
806 delta &= ~(1 << (id-1));
808 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
809 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
813 priv->acecadOldButtons = buttons;
814 priv->acecadOldX = x;
815 priv->acecadOldY = y;
816 priv->acecadOldZ = z;
817 priv->acecadOldProximity = prox;
821 if (!is_core_pointer)
822 if (priv->acecadOldProximity)
824 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
825 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
827 priv->acecadOldProximity = 0;
830 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
834 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
836 USBReadInput (LocalDevicePtr local)
839 struct input_event * event;
840 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
841 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
842 int x = priv->acecadOldX;
843 int y = priv->acecadOldY;
844 int z = priv->acecadOldZ;
845 int report_x, report_y;
846 int prox = priv->acecadOldProximity;
847 int buttons = priv->acecadOldButtons;
848 int is_core_pointer = 0;
849 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
850 is_core_pointer = xf86IsCorePointer(local->dev);
852 /* Is autodev active? */
853 int autodev = priv->flags & AUTODEV_FLAG;
854 /* Was the device available last time we checked? */
855 int avail = priv->flags & AVAIL_FLAG;
857 SYSCALL(len = read(local->fd, eventbuf, sizeof(eventbuf)));
861 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
864 priv->flags &= ~AVAIL_FLAG;
866 if (AceCadAutoDevProbe(local, 4)) {
867 DeviceOff(local->dev);
868 DeviceOn(local->dev);
875 /* If the device wasn't available last time we checked */
876 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
877 priv->flags |= AVAIL_FLAG;
881 for (event = (struct input_event *)eventbuf;
882 event < (struct input_event *)(eventbuf+len); event++) {
884 switch (event->type) {
885 case EV_SYN: /* 2.6.x */
886 if (event->code != SYN_REPORT)
887 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
890 switch (event->code) {
910 switch (event->code) {
916 buttons = set_bit(buttons,0,event->value);
920 buttons = set_bit(buttons,1,event->value);
924 buttons = set_bit(buttons,2,event->value);
929 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
930 } /* switch event->type */
932 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
933 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
935 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
936 (event->type == EV_ABS && event->code == ABS_MISC)
943 #if XORG_BOTCHED_INPUT
944 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
949 if (!(priv->acecadOldProximity))
950 if (!is_core_pointer)
952 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
956 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
958 if (priv->acecadOldButtons != buttons)
960 int delta = buttons ^ priv->acecadOldButtons;
964 delta &= ~(1 << (id-1));
966 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
972 if (!is_core_pointer)
973 if (priv->acecadOldProximity)
975 xf86PostProximityEvent(local->dev, 0, 0, 3, report_x, report_y, z);
977 priv->acecadOldProximity = 0;
980 priv->acecadOldButtons = buttons;
981 priv->acecadOldX = x;
982 priv->acecadOldY = y;
983 priv->acecadOldZ = z;
984 priv->acecadOldProximity = prox;
986 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
991 CloseProc (LocalDevicePtr local)
996 * The ConvertProc function may need to be tailored for your device.
997 * This function converts the device's valuator outputs to x and y coordinates
998 * to simulate mouse events.
1001 ConvertProc (LocalDevicePtr local, int first, int num,
1002 int v0, int v1, int v2, int v3, int v4, int v5,
1005 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1007 /* TODO: should have a structure to hold which screen the
1008 * pointer is attached to? */
1009 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
1010 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
1011 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
1012 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
1018 ReverseConvertProc (LocalDevicePtr local,
1022 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1024 // xf86Msg(X_INFO, "%s: reverse coordinate conversion in : %d, %d\n", local->name, x, y);
1025 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
1026 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
1027 // xf86Msg(X_INFO, "%s: reverse coordinate conversion out: %d, %d\n", local->name, valuators[0], valuators[1]);
1033 #define WriteString(str)\
1034 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1038 QueryHardware (AceCadPrivatePtr priv)
1047 /* Prompt Mode in order to not be disturbed */
1048 WriteString(ACECAD_PROMPT_MODE);
1051 while (XisbRead(priv->buffer) >= 0);
1053 /* Ask for Config packet*/
1054 WriteString(ACECAD_CONFIG);
1056 /* Read the packet */
1057 XisbBlockDuration (priv->buffer, 1000000);
1060 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1062 if ((AceCadGetPacket (priv) == Success))
1064 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1065 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1066 priv->acecadMaxZ = 512;
1067 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1072 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1076 #define BITS_PER_LONG (sizeof(long) * 8)
1077 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1078 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1079 #define OFF(x) ((x)%BITS_PER_LONG)
1080 #define LONG(x) ((x)/BITS_PER_LONG)
1084 USBQueryHardware (LocalDevicePtr local)
1086 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1087 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1090 char name[256] = "Unknown";
1092 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1093 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1095 memset(bit, 0, sizeof(bit));
1096 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1098 for (i = 0; i < EV_MAX; i++)
1099 if (test_bit(i, bit[0])) {
1100 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1101 for (j = 0; j < KEY_MAX; j++)
1102 if (test_bit(j, bit[i])) {
1104 ioctl(local->fd, EVIOCGABS(j), abs);
1107 priv->acecadMaxX = abs[2];
1111 priv->acecadMaxY = abs[2];
1115 priv->acecadMaxZ = abs[2];
1122 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1128 NewPacket (AceCadPrivatePtr priv)
1134 AceCadGetPacket (AceCadPrivatePtr priv)
1139 while((c = XisbRead(priv->buffer)) >= 0 )
1143 * fail after 500 bytes so the server doesn't hang forever if a
1144 * device sends bad data.
1152 if (c & PHASING_BIT)
1156 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1157 XisbBlockDuration (priv->buffer, 10000);
1158 priv->packet[priv->packeti++] = c;
1159 count = ACECAD_PACKET_SIZE - 1;
1160 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1162 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1163 priv->packet[priv->packeti++] = c;
1165 XisbBlockDuration (priv->buffer, 0);