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 $ */
31 /*****************************************************************************
33 ****************************************************************************/
36 #include <asm/types.h>
37 #include <linux/input.h>
52 #ifndef NEED_XF86_TYPES
53 #define NEED_XF86_TYPES
55 #include <xf86_OSproc.h>
57 #include <xf86Xinput.h>
59 #include <xf86Module.h>
68 #include <sysfs/libsysfs.h>
73 /*****************************************************************************
75 ****************************************************************************/
78 /*****************************************************************************
79 * Variables without includable headers
80 ****************************************************************************/
82 /*****************************************************************************
84 ****************************************************************************/
87 #define read(a,b,c) xf86ReadSerial((a),(b),(c))
89 /* max number of input events to read in one read call */
92 _X_EXPORT InputDriverRec ACECAD =
104 static XF86ModuleVersionInfo VersionRec =
110 XORG_VERSION_CURRENT,
111 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
119 _X_EXPORT XF86ModuleData acecadModuleData = {
125 /*****************************************************************************
126 * Function Definitions
127 ****************************************************************************/
130 SetupProc( pointer module,
135 xf86AddInputDriver(&ACECAD, module, 0);
140 TearDownProc( pointer p )
143 LocalDevicePtr local = (LocalDevicePtr) p;
144 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
146 DeviceOff (local->dev);
148 xf86CloseSerial (local->fd);
149 XisbFree (priv->buffer);
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;
234 unsigned int major = 0, minor = 0;
235 void *libsysfs = NULL;
237 if (libsysfs = dlopen("libsysfs.so", RTLD_NOW | RTLD_GLOBAL)) {
238 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
239 usb_bus = sysfs_open_bus(usb_bus_name);
241 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
242 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
244 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
245 devs = sysfs_get_driver_devices(acecad_driver);
247 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
248 dlist_for_each_data(devs, candidate, struct sysfs_device) {
249 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
250 links = sysfs_open_link_list(candidate->path);
251 dlist_for_each_data(links, link, char) {
252 if (sscanf(link, "input:event%d", &i) == 1) {
253 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
257 sysfs_close_list(links);
258 if (i > 0) /* We found something */
262 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
264 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
266 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
267 sysfs_close_bus(usb_bus);
271 /* We found something */
272 np = SET_EVENT_NUM(fname, i);
273 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
274 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
279 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
281 xf86MsgVerb(X_WARNING, 4, "%s: libsysfs not found\n", local->name);
286 ace_name = ace_name_default;
288 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
293 np = SET_EVENT_NUM(fname, i);
294 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
295 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
298 SYSCALL(fd = open(fname, O_RDONLY));
300 if (errno == ENOENT) {
301 if (++noent_cnt >= max_skip)
311 is_acecad = fd_query_acecad(fd, ace_name);
317 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
318 local->name, i + 1, ace_name);
320 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
322 if (i > max_skip && !have_evdev)
323 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
327 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
329 xf86ReplaceStrOption(local->options, "Device", fname);
336 AceCadPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
338 LocalDevicePtr local = xf86AllocateInput(drv, 0);
339 AceCadPrivatePtr priv = xcalloc (1, sizeof(AceCadPrivateRec));
344 if ((!local) || (!priv))
347 memset(priv, 0, sizeof(AceCadPrivateRec));
349 local->name = dev->identifier;
350 local->type_name = "ACECAD Tablet";
351 local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
352 local->motion_history_proc = xf86GetMotionEvents;
353 local->control_proc = NULL;
354 local->close_proc = CloseProc;
355 local->switch_mode = NULL;
356 local->conversion_proc = ConvertProc;
357 local->reverse_conversion_proc = ReverseConvertProc;
359 local->private = priv;
360 local->private_flags = 0;
361 local->conf_idev = dev;
362 local->device_control = DeviceControl;
363 /*local->always_core_feedback = 0;*/
365 xf86CollectInputOptions(local, default_options, NULL);
367 xf86OptionListReport(local->options);
369 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
371 s = xf86FindOptionValue(local->options, "Device");
372 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
374 priv->flags |= AUTODEV_FLAG;
375 if (!AceCadAutoDevProbe(local, 0))
377 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
381 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
386 local->fd = xf86OpenSerial (local->options);
389 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
392 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
395 if (IsUSBLine(local->fd)) {
396 priv->flags |= USB_FLAG;
398 local->read_input = USBReadInput;
400 if (USBQueryHardware(local) != Success)
402 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
408 local->read_input = ReadInput;
411 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
413 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
421 priv->acecadReportSpeed = 'Q';
424 priv->acecadReportSpeed = 'R';
427 priv->acecadReportSpeed = 'S';
430 priv->acecadReportSpeed = 'T';
433 priv->acecadReportSpeed = 'R';
435 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
439 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
441 priv->buffer = XisbNew (local->fd, 200);
444 * Verify that hardware is attached and fuctional
446 if (QueryHardware(priv) != Success)
448 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
453 s = xf86FindOptionValue(local->options, "Mode");
454 msgtype = s ? X_CONFIG : X_DEFAULT;
455 if (!(s && (xf86NameCmp(s, "relative") == 0)))
457 priv->flags |= ABSOLUTE_FLAG;
460 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
461 DBG (9, XisbTrace (priv->buffer, 1));
463 local->history_size = xf86SetIntOption(local->options , "HistorySize", 0);
465 xf86ProcessCommonOptions(local, local->options);
467 local->flags |= XI86_CONFIGURED;
471 RemoveEnabledDevice (local->fd);
474 XisbFree(priv->buffer);
477 xf86CloseSerial(local->fd);
479 RemoveEnabledDevice (local->fd);
484 * If something went wrong, cleanup and return NULL
487 if ((local) && (local->fd))
488 xf86CloseSerial (local->fd);
489 if ((priv) && (priv->buffer))
490 XisbFree (priv->buffer);
494 local->private = NULL;
496 xf86DeleteInput(local, 0);
501 DeviceControl (DeviceIntPtr dev, int mode)
512 RetValue = DeviceOn(dev);
515 RetValue = DeviceOff(dev);
518 RetValue = DeviceClose(dev);
528 DeviceOn (DeviceIntPtr dev)
531 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
532 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
534 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
536 local->fd = xf86OpenSerial(local->options);
539 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
540 priv->flags &= ~AVAIL_FLAG;
542 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
543 local->fd = xf86OpenSerial(local->options);
548 priv->flags |= AVAIL_FLAG;
551 if (!(priv->flags & USB_FLAG)) {
552 priv->buffer = XisbNew(local->fd, 200);
555 xf86CloseSerial(local->fd);
560 /* Rets qu'a l'envoyer a la tablette */
561 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
562 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
565 xf86FlushInput(local->fd);
566 xf86AddEnabledDevice (local);
567 dev->public.on = TRUE;
572 DeviceOff (DeviceIntPtr dev)
574 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
575 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
577 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
581 RemoveEnabledDevice (local->fd);
584 XisbFree(priv->buffer);
587 xf86CloseSerial(local->fd);
591 xf86RemoveEnabledDevice (local);
592 dev->public.on = FALSE;
597 DeviceClose (DeviceIntPtr dev)
599 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
601 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
607 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
609 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
611 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
615 DeviceInit (DeviceIntPtr dev)
618 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
619 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
620 unsigned char map[] =
623 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
626 if (InitButtonClassDeviceStruct (dev, 3, map) == FALSE)
628 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
632 if (InitFocusClassDeviceStruct (dev) == FALSE)
634 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
638 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
639 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
645 if (InitValuatorClassDeviceStruct (dev, 3, xf86GetMotionEvents,
647 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
650 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
656 InitValuatorAxisStruct(dev,
659 priv->acecadMaxX, /* max val */
660 1000, /* resolution */
663 InitValuatorAxisStruct(dev,
666 priv->acecadMaxY, /* max val */
667 1000, /* resolution */
670 InitValuatorAxisStruct(dev,
673 priv->acecadMaxZ, /* max val */
674 1000, /* resolution */
680 if (InitProximityClassDeviceStruct (dev) == FALSE)
682 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
686 xf86MotionHistoryAllocate (local);
689 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
690 connaitre la taille... */
692 if (priv->acecadInc > 95)
693 priv->acecadInc = 95;
694 if (priv->acecadInc < 1)
696 /* guess the best increment value given video mode */
697 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
698 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
700 priv->acecadInc = rx;
702 priv->acecadInc = ry;
703 if (priv->acecadInc < 1)
707 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
713 ReadInput (LocalDevicePtr local)
717 int is_core_pointer, is_absolute;
718 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
720 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
722 is_absolute = (priv->flags & ABSOLUTE_FLAG);
723 is_core_pointer = xf86IsCorePointer(local->dev);
726 * set blocking to -1 on the first call because we know there is data to
727 * read. Xisb automatically clears it after one successful read so that
728 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
729 * read from blocking indefinately.
731 XisbBlockDuration (priv->buffer, -1);
733 while (AceCadGetPacket (priv) == Success)
735 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
736 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
738 if (!(priv->flags & ABSOLUTE_FLAG))
740 x = priv->packet[0] & XSIGN_BIT? x:-x;
741 y = priv->packet[0] & YSIGN_BIT? y:-y;
745 y = priv->acecadMaxY - y ;
749 z = ((int)priv->packet[5] << 2) |
750 (((int)priv->packet[6] & 0x01) << 1) |
751 (((int)priv->packet[6] & 0x10) >> 4);
753 buttons = ((int)priv->packet[0] & 0x07) |
754 ((int)priv->packet[6] & 0x02 << 2);
756 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
760 if (!(priv->acecadOldProximity))
761 if (!is_core_pointer)
763 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
764 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
767 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
768 || (!is_absolute && (x || y)))
770 if (is_absolute || priv->acecadOldProximity)
772 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
773 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
777 if (priv->acecadOldButtons != buttons)
779 int delta = buttons ^ priv->acecadOldButtons;
783 delta &= ~(1 << (id-1));
785 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
786 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
790 priv->acecadOldButtons = buttons;
791 priv->acecadOldX = x;
792 priv->acecadOldY = y;
793 priv->acecadOldZ = z;
794 priv->acecadOldProximity = prox;
798 if (!is_core_pointer)
799 if (priv->acecadOldProximity)
801 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
802 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
804 priv->acecadOldProximity = 0;
807 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
811 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
813 USBReadInput (LocalDevicePtr local)
816 struct input_event * event;
817 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
818 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
819 int x = priv->acecadOldX;
820 int y = priv->acecadOldY;
821 int z = priv->acecadOldZ;
822 int prox = priv->acecadOldProximity;
823 int buttons = priv->acecadOldButtons;
824 int is_core_pointer = xf86IsCorePointer(local->dev);
825 /* Is autodev active? */
826 int autodev = priv->flags & AUTODEV_FLAG;
827 /* Was the device available last time we checked? */
828 int avail = priv->flags & AVAIL_FLAG;
830 SYSCALL(len = read(local->fd, eventbuf, sizeof(eventbuf)));
834 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
837 priv->flags &= ~AVAIL_FLAG;
839 if (AceCadAutoDevProbe(local, 4)) {
840 DeviceOff(local->dev);
841 DeviceOn(local->dev);
848 /* If the device wasn't available last time we checked */
849 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
850 priv->flags |= AVAIL_FLAG;
854 for (event = (struct input_event *)eventbuf;
855 event < (struct input_event *)(eventbuf+len); event++) {
857 switch (event->type) {
858 case EV_SYN: /* 2.6.x */
859 if (event->code != SYN_REPORT)
860 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
863 switch (event->code) {
883 switch (event->code) {
889 buttons = set_bit(buttons,0,event->value);
893 buttons = set_bit(buttons,1,event->value);
897 buttons = set_bit(buttons,2,event->value);
902 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
903 } /* switch event->type */
905 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
906 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
908 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
909 (event->type == EV_ABS && event->code == ABS_MISC)
916 if (!(priv->acecadOldProximity))
917 if (!is_core_pointer)
919 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
923 xf86PostMotionEvent(local->dev, 1, 0, 3, x, y, z);
925 if (priv->acecadOldButtons != buttons)
927 int delta = buttons ^ priv->acecadOldButtons;
931 delta &= ~(1 << (id-1));
933 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
939 if (!is_core_pointer)
940 if (priv->acecadOldProximity)
942 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
944 priv->acecadOldProximity = 0;
947 priv->acecadOldButtons = buttons;
948 priv->acecadOldX = x;
949 priv->acecadOldY = y;
950 priv->acecadOldZ = z;
951 priv->acecadOldProximity = prox;
953 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
958 CloseProc (LocalDevicePtr local)
963 * The ConvertProc function may need to be tailored for your device.
964 * This function converts the device's valuator outputs to x and y coordinates
965 * to simulate mouse events.
968 ConvertProc (LocalDevicePtr local, int first, int num,
969 int v0, int v1, int v2, int v3, int v4, int v5,
972 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
974 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
975 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
981 ReverseConvertProc (LocalDevicePtr local,
985 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
987 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
988 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
994 #define WriteString(str)\
995 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
999 QueryHardware (AceCadPrivatePtr priv)
1008 /* Prompt Mode in order to not be disturbed */
1009 WriteString(ACECAD_PROMPT_MODE);
1012 while (XisbRead(priv->buffer) >= 0);
1014 /* Ask for Config packet*/
1015 WriteString(ACECAD_CONFIG);
1017 /* Read the packet */
1018 XisbBlockDuration (priv->buffer, 1000000);
1021 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1023 if ((AceCadGetPacket (priv) == Success))
1025 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1026 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1027 priv->acecadMaxZ = 512;
1028 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1033 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1037 #define BITS_PER_LONG (sizeof(long) * 8)
1038 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1039 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1040 #define OFF(x) ((x)%BITS_PER_LONG)
1041 #define LONG(x) ((x)/BITS_PER_LONG)
1045 USBQueryHardware (LocalDevicePtr local)
1047 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1048 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1051 char name[256] = "Unknown";
1053 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1054 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1056 memset(bit, 0, sizeof(bit));
1057 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1059 for (i = 0; i < EV_MAX; i++)
1060 if (test_bit(i, bit[0])) {
1061 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1062 for (j = 0; j < KEY_MAX; j++)
1063 if (test_bit(j, bit[i])) {
1065 ioctl(local->fd, EVIOCGABS(j), abs);
1068 priv->acecadMaxX = abs[2];
1072 priv->acecadMaxY = abs[2];
1076 priv->acecadMaxZ = abs[2];
1083 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1089 NewPacket (AceCadPrivatePtr priv)
1095 AceCadGetPacket (AceCadPrivatePtr priv)
1100 while((c = XisbRead(priv->buffer)) >= 0 )
1104 * fail after 500 bytes so the server doesn't hang forever if a
1105 * device sends bad data.
1113 if (c & PHASING_BIT)
1117 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1118 XisbBlockDuration (priv->buffer, 10000);
1119 priv->packet[priv->packeti++] = c;
1120 count = ACECAD_PACKET_SIZE - 1;
1121 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1123 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1124 priv->packet[priv->packeti++] = c;
1126 XisbBlockDuration (priv->buffer, 0);