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 /*****************************************************************************
95 ****************************************************************************/
98 /*****************************************************************************
99 * Variables without includable headers
100 ****************************************************************************/
102 /*****************************************************************************
104 ****************************************************************************/
106 /* max number of input events to read in one read call */
107 #define MAX_EVENTS 50
109 static const char *default_options[] =
117 "FlowControl", "Xoff",
121 _X_EXPORT InputDriverRec ACECAD =
131 static XF86ModuleVersionInfo VersionRec =
137 XORG_VERSION_CURRENT,
138 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
146 _X_EXPORT XF86ModuleData acecadModuleData = {
152 /*****************************************************************************
153 * Function Definitions
154 ****************************************************************************/
157 SetupProc( pointer module,
162 xf86AddInputDriver(&ACECAD, module, 0);
167 TearDownProc( pointer p )
171 #ifdef HAVE_LINUX_INPUT_H
178 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
181 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
182 version >> 16, (version >> 8) & 0xff, version & 0xff);
185 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
190 /* Heavily inspired by synaptics/eventcomm.c */
192 #define DEV_INPUT_EVENT "/dev/input/event"
193 #define EV_DEV_NAME_MAXLEN 64
194 #define SET_EVENT_NUM(str, num) \
195 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
198 fd_query_acecad(int fd, char *ace_name) {
199 char name[256] = "Unknown";
200 int cmp_at = strlen(ace_name);
203 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
205 if (xf86NameCmp(name, ace_name) == 0)
210 static char ace_name_default[7] = "acecad";
212 #ifdef HAVE_SYSFS_LIBSYSFS_H
213 static char usb_bus_name[4] = "usb";
214 static char acecad_driver_name[11] = "usb_acecad";
218 AceCadAutoDevProbe(InputInfoPtr local, int verb)
220 /* We are trying to find the right eventX device */
222 Bool have_evdev = FALSE;
224 const int max_skip = 10;
225 char *ace_name = xf86FindOptionValue(local->options, "Name");
226 char fname[EV_DEV_NAME_MAXLEN];
229 #ifdef HAVE_SYSFS_LIBSYSFS_H
230 struct sysfs_bus *usb_bus = NULL;
231 struct sysfs_driver *acecad_driver = NULL;
232 struct sysfs_device *candidate = NULL;
234 struct dlist *devs = NULL;
235 struct dlist *links = NULL;
237 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
238 usb_bus = sysfs_open_bus(usb_bus_name);
240 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
241 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
243 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
244 devs = sysfs_get_driver_devices(acecad_driver);
246 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
247 dlist_for_each_data(devs, candidate, struct sysfs_device) {
248 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
249 links = sysfs_open_link_list(candidate->path);
250 dlist_for_each_data(links, link, char) {
251 if (sscanf(link, "input:event%d", &i) == 1) {
252 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
256 sysfs_close_list(links);
257 if (i > 0) /* We found something */
261 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
263 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
265 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
266 sysfs_close_bus(usb_bus);
269 /* We found something */
270 np = SET_EVENT_NUM(fname, i);
271 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
272 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
277 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
282 ace_name = ace_name_default;
284 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
289 np = SET_EVENT_NUM(fname, i);
290 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
291 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
294 SYSCALL(fd = open(fname, O_RDONLY));
296 if (errno == ENOENT) {
297 if (++noent_cnt >= max_skip)
307 is_acecad = fd_query_acecad(fd, ace_name);
313 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
314 local->name, i + 1, ace_name);
316 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
318 if (i > max_skip && !have_evdev)
319 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
323 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
325 xf86ReplaceStrOption(local->options, "Device", fname);
332 AceCadPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
334 InputInfoPtr local = xf86AllocateInput(drv, 0);
335 AceCadPrivatePtr priv = calloc (1, sizeof(AceCadPrivateRec));
340 if ((!local) || (!priv))
343 memset(priv, 0, sizeof(AceCadPrivateRec));
345 local->name = dev->identifier;
346 local->type_name = XI_TABLET;
347 local->flags = XI86_SEND_DRAG_EVENTS;
348 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
349 local->motion_history_proc = xf86GetMotionEvents;
351 local->control_proc = NULL;
352 local->close_proc = CloseProc;
353 local->switch_mode = NULL;
354 local->conversion_proc = ConvertProc;
355 local->reverse_conversion_proc = ReverseConvertProc;
357 local->private = priv;
358 local->private_flags = 0;
359 local->conf_idev = dev;
360 local->device_control = DeviceControl;
361 /*local->always_core_feedback = 0;*/
363 xf86CollectInputOptions(local, default_options, NULL);
365 xf86OptionListReport(local->options);
367 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
369 s = xf86FindOptionValue(local->options, "Device");
370 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
371 #ifdef HAVE_LINUX_INPUT_H
372 priv->flags |= AUTODEV_FLAG;
373 if (!AceCadAutoDevProbe(local, 0))
375 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
379 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
384 local->fd = xf86OpenSerial (local->options);
387 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
390 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
392 #ifdef HAVE_LINUX_INPUT_H
393 if (IsUSBLine(local->fd)) {
394 priv->flags |= USB_FLAG;
396 local->read_input = USBReadInput;
398 if (USBQueryHardware(local) != Success)
400 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
406 local->read_input = ReadInput;
409 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
411 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
419 priv->acecadReportSpeed = 'Q';
422 priv->acecadReportSpeed = 'R';
425 priv->acecadReportSpeed = 'S';
428 priv->acecadReportSpeed = 'T';
431 priv->acecadReportSpeed = 'R';
433 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
437 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
439 priv->buffer = XisbNew (local->fd, 200);
442 * Verify that hardware is attached and fuctional
444 if (QueryHardware(priv) != Success)
446 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
451 s = xf86FindOptionValue(local->options, "Mode");
452 msgtype = s ? X_CONFIG : X_DEFAULT;
453 if (!(s && (xf86NameCmp(s, "relative") == 0)))
455 priv->flags |= ABSOLUTE_FLAG;
458 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
459 DBG (9, XisbTrace (priv->buffer, 1));
461 local->history_size = xf86SetIntOption(local->options , "HistorySize", 0);
463 xf86ProcessCommonOptions(local, local->options);
465 local->flags |= XI86_CONFIGURED;
469 RemoveEnabledDevice (local->fd);
472 XisbFree(priv->buffer);
475 xf86CloseSerial(local->fd);
477 RemoveEnabledDevice (local->fd);
482 * If something went wrong, cleanup and return NULL
485 if ((local) && (local->fd))
486 xf86CloseSerial (local->fd);
487 if ((priv) && (priv->buffer))
488 XisbFree (priv->buffer);
492 local->private = NULL;
494 xf86DeleteInput(local, 0);
499 DeviceControl (DeviceIntPtr dev, int mode)
510 RetValue = DeviceOn(dev);
513 RetValue = DeviceOff(dev);
516 RetValue = DeviceClose(dev);
526 DeviceOn (DeviceIntPtr dev)
529 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
530 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
532 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
534 local->fd = xf86OpenSerial(local->options);
537 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
538 priv->flags &= ~AVAIL_FLAG;
539 #ifdef HAVE_LINUX_INPUT_H
540 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
541 local->fd = xf86OpenSerial(local->options);
546 priv->flags |= AVAIL_FLAG;
549 if (!(priv->flags & USB_FLAG)) {
550 priv->buffer = XisbNew(local->fd, 200);
553 xf86CloseSerial(local->fd);
558 /* Rets qu'a l'envoyer a la tablette */
559 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
560 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
563 xf86FlushInput(local->fd);
564 xf86AddEnabledDevice (local);
565 dev->public.on = TRUE;
570 DeviceOff (DeviceIntPtr dev)
572 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
573 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
575 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
579 RemoveEnabledDevice (local->fd);
582 XisbFree(priv->buffer);
585 xf86CloseSerial(local->fd);
589 xf86RemoveEnabledDevice (local);
590 dev->public.on = FALSE;
595 DeviceClose (DeviceIntPtr dev)
597 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
599 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
605 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
607 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
609 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
613 DeviceInit (DeviceIntPtr dev)
616 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
617 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
618 unsigned char map[] = {0, 1, 2, 3};
619 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
623 btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
624 btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
625 btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
627 if ((priv->flags & ABSOLUTE_FLAG))
629 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
630 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
631 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
634 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
635 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
636 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Z);
640 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
643 if (InitButtonClassDeviceStruct (dev, 3,
644 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
649 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
653 if (InitFocusClassDeviceStruct (dev) == FALSE)
655 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
659 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
660 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
666 if (InitValuatorClassDeviceStruct (dev, 3,
667 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
670 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
674 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
677 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
683 InitValuatorAxisStruct(dev,
685 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
689 #if XORG_BOTCHED_INPUT
690 screenInfo.screens[0]->width,
692 priv->acecadMaxX, /* max val */
694 1000, /* resolution */
697 InitValuatorAxisStruct(dev,
699 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
703 #if XORG_BOTCHED_INPUT
704 screenInfo.screens[0]->height,
706 priv->acecadMaxY, /* max val */
708 1000, /* resolution */
711 InitValuatorAxisStruct(dev,
713 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
717 priv->acecadMaxZ, /* max val */
718 1000, /* resolution */
724 if (InitProximityClassDeviceStruct (dev) == FALSE)
726 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
730 xf86MotionHistoryAllocate (local);
733 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
734 connaitre la taille... */
736 if (priv->acecadInc > 95)
737 priv->acecadInc = 95;
738 if (priv->acecadInc < 1)
740 /* guess the best increment value given video mode */
741 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
742 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
744 priv->acecadInc = rx;
746 priv->acecadInc = ry;
747 if (priv->acecadInc < 1)
751 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
757 ReadInput (InputInfoPtr local)
761 int is_core_pointer = 0, is_absolute;
762 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
764 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
766 is_absolute = (priv->flags & ABSOLUTE_FLAG);
767 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
768 is_core_pointer = xf86IsCorePointer(local->dev);
772 * set blocking to -1 on the first call because we know there is data to
773 * read. Xisb automatically clears it after one successful read so that
774 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
775 * read from blocking indefinately.
777 XisbBlockDuration (priv->buffer, -1);
779 while (AceCadGetPacket (priv) == Success)
781 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
782 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
784 if (!(priv->flags & ABSOLUTE_FLAG))
786 x = priv->packet[0] & XSIGN_BIT? x:-x;
787 y = priv->packet[0] & YSIGN_BIT? y:-y;
791 y = priv->acecadMaxY - y ;
795 z = ((int)priv->packet[5] << 2) |
796 (((int)priv->packet[6] & 0x01) << 1) |
797 (((int)priv->packet[6] & 0x10) >> 4);
799 buttons = ((int)priv->packet[0] & 0x07) |
800 ((int)priv->packet[6] & 0x02 << 2);
802 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
806 if (!(priv->acecadOldProximity))
807 if (!is_core_pointer)
809 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
810 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
813 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
814 || (!is_absolute && (x || y)))
816 if (is_absolute || priv->acecadOldProximity)
818 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
819 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
823 if (priv->acecadOldButtons != buttons)
825 int delta = buttons ^ priv->acecadOldButtons;
829 delta &= ~(1 << (id-1));
831 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
832 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
836 priv->acecadOldButtons = buttons;
837 priv->acecadOldX = x;
838 priv->acecadOldY = y;
839 priv->acecadOldZ = z;
840 priv->acecadOldProximity = prox;
844 if (!is_core_pointer)
845 if (priv->acecadOldProximity)
847 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
848 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
850 priv->acecadOldProximity = 0;
853 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
856 #ifdef HAVE_LINUX_INPUT_H
857 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
859 USBReadInput (InputInfoPtr local)
862 struct input_event * event;
863 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
864 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
865 int x = priv->acecadOldX;
866 int y = priv->acecadOldY;
867 int z = priv->acecadOldZ;
868 int report_x, report_y;
869 int prox = priv->acecadOldProximity;
870 int buttons = priv->acecadOldButtons;
871 int is_core_pointer = 0;
872 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
873 is_core_pointer = xf86IsCorePointer(local->dev);
875 /* Is autodev active? */
876 int autodev = priv->flags & AUTODEV_FLAG;
877 /* Was the device available last time we checked? */
878 int avail = priv->flags & AVAIL_FLAG;
880 SYSCALL(len = xf86ReadSerial(local->fd, eventbuf, sizeof(eventbuf)));
884 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
887 priv->flags &= ~AVAIL_FLAG;
889 if (AceCadAutoDevProbe(local, 4)) {
890 DeviceOff(local->dev);
891 DeviceOn(local->dev);
898 /* If the device wasn't available last time we checked */
899 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
900 priv->flags |= AVAIL_FLAG;
904 for (event = (struct input_event *)eventbuf;
905 event < (struct input_event *)(eventbuf+len); event++) {
907 switch (event->type) {
908 case EV_SYN: /* 2.6.x */
909 if (event->code != SYN_REPORT)
910 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
913 switch (event->code) {
933 switch (event->code) {
939 buttons = set_bit(buttons,0,event->value);
943 buttons = set_bit(buttons,1,event->value);
947 buttons = set_bit(buttons,2,event->value);
952 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
953 } /* switch event->type */
955 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
956 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
958 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
959 (event->type == EV_ABS && event->code == ABS_MISC)
966 #if XORG_BOTCHED_INPUT
967 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
972 if (!(priv->acecadOldProximity))
973 if (!is_core_pointer)
975 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
979 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
981 if (priv->acecadOldButtons != buttons)
983 int delta = buttons ^ priv->acecadOldButtons;
987 delta &= ~(1 << (id-1));
989 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
995 if (!is_core_pointer)
996 if (priv->acecadOldProximity)
998 xf86PostProximityEvent(local->dev, 0, 0, 3, report_x, report_y, z);
1000 priv->acecadOldProximity = 0;
1003 priv->acecadOldButtons = buttons;
1004 priv->acecadOldX = x;
1005 priv->acecadOldY = y;
1006 priv->acecadOldZ = z;
1007 priv->acecadOldProximity = prox;
1009 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
1014 CloseProc (InputInfoPtr local)
1019 * The ConvertProc function may need to be tailored for your device.
1020 * This function converts the device's valuator outputs to x and y coordinates
1021 * to simulate mouse events.
1024 ConvertProc (InputInfoPtr local, int first, int num,
1025 int v0, int v1, int v2, int v3, int v4, int v5,
1028 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1030 /* TODO: should have a structure to hold which screen the
1031 * pointer is attached to? */
1032 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
1033 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
1034 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
1035 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
1041 ReverseConvertProc (InputInfoPtr local,
1045 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1047 // xf86Msg(X_INFO, "%s: reverse coordinate conversion in : %d, %d\n", local->name, x, y);
1048 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
1049 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
1050 // xf86Msg(X_INFO, "%s: reverse coordinate conversion out: %d, %d\n", local->name, valuators[0], valuators[1]);
1056 #define WriteString(str)\
1057 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1061 QueryHardware (AceCadPrivatePtr priv)
1070 /* Prompt Mode in order to not be disturbed */
1071 WriteString(ACECAD_PROMPT_MODE);
1074 while (XisbRead(priv->buffer) >= 0);
1076 /* Ask for Config packet*/
1077 WriteString(ACECAD_CONFIG);
1079 /* Read the packet */
1080 XisbBlockDuration (priv->buffer, 1000000);
1083 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1085 if ((AceCadGetPacket (priv) == Success))
1087 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1088 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1089 priv->acecadMaxZ = 512;
1090 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1095 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1099 #define BITS_PER_LONG (sizeof(long) * 8)
1100 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1101 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1102 #define OFF(x) ((x)%BITS_PER_LONG)
1103 #define LONG(x) ((x)/BITS_PER_LONG)
1105 #ifdef HAVE_LINUX_INPUT_H
1107 USBQueryHardware (InputInfoPtr local)
1109 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1110 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1113 char name[256] = "Unknown";
1115 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1116 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1118 memset(bit, 0, sizeof(bit));
1119 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1121 for (i = 0; i < EV_MAX; i++)
1122 if (test_bit(i, bit[0])) {
1123 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1124 for (j = 0; j < KEY_MAX; j++)
1125 if (test_bit(j, bit[i])) {
1127 ioctl(local->fd, EVIOCGABS(j), abs);
1130 priv->acecadMaxX = abs[2];
1134 priv->acecadMaxY = abs[2];
1138 priv->acecadMaxZ = abs[2];
1145 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1151 NewPacket (AceCadPrivatePtr priv)
1157 AceCadGetPacket (AceCadPrivatePtr priv)
1162 while((c = XisbRead(priv->buffer)) >= 0 )
1166 * fail after 500 bytes so the server doesn't hang forever if a
1167 * device sends bad data.
1175 if (c & PHASING_BIT)
1179 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1180 XisbBlockDuration (priv->buffer, 10000);
1181 priv->packet[priv->packeti++] = c;
1182 count = ACECAD_PACKET_SIZE - 1;
1183 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1185 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1186 priv->packet[priv->packeti++] = c;
1188 XisbBlockDuration (priv->buffer, 0);