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
38 /*****************************************************************************
40 ****************************************************************************/
43 #include <asm/types.h>
44 #include <linux/input.h>
59 #ifndef NEED_XF86_TYPES
60 #define NEED_XF86_TYPES
62 #include <xf86_OSproc.h>
64 #include <xf86Xinput.h>
66 #include <xf86Module.h>
75 #include <sysfs/libsysfs.h>
80 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
81 #include <X11/Xatom.h>
82 #include <xserver-properties.h>
85 /* Previously found in xf86Xinput.h */
89 #define DBG(lvl, f) {if ((lvl) <= xf86GetVerbosity()) f;}
91 /*****************************************************************************
93 ****************************************************************************/
96 /*****************************************************************************
97 * Variables without includable headers
98 ****************************************************************************/
100 /*****************************************************************************
102 ****************************************************************************/
105 #define read(a,b,c) xf86ReadSerial((a),(b),(c))
107 /* max number of input events to read in one read call */
108 #define MAX_EVENTS 50
110 _X_EXPORT InputDriverRec ACECAD =
122 static XF86ModuleVersionInfo VersionRec =
128 XORG_VERSION_CURRENT,
129 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
137 _X_EXPORT XF86ModuleData acecadModuleData = {
143 /*****************************************************************************
144 * Function Definitions
145 ****************************************************************************/
148 SetupProc( pointer module,
153 xf86AddInputDriver(&ACECAD, module, 0);
158 TearDownProc( pointer p )
161 LocalDevicePtr local = (LocalDevicePtr) p;
162 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
164 DeviceOff (local->dev);
166 xf86CloseSerial (local->fd);
167 XisbFree (priv->buffer);
175 static const char *default_options[] =
183 "FlowControl", "Xoff",
194 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
197 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
198 version >> 16, (version >> 8) & 0xff, version & 0xff);
201 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
206 /* Heavily inspired by synaptics/eventcomm.c */
208 #define DEV_INPUT_EVENT "/dev/input/event"
209 #define EV_DEV_NAME_MAXLEN 64
210 #define SET_EVENT_NUM(str, num) \
211 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
214 fd_query_acecad(int fd, char *ace_name) {
215 char name[256] = "Unknown";
216 int cmp_at = strlen(ace_name);
219 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
221 if (xf86NameCmp(name, ace_name) == 0)
226 static char ace_name_default[7] = "acecad";
229 static char usb_bus_name[4] = "usb";
230 static char acecad_driver_name[11] = "usb_acecad";
234 AceCadAutoDevProbe(LocalDevicePtr local, int verb)
236 /* We are trying to find the right eventX device */
238 Bool have_evdev = FALSE;
240 const int max_skip = 10;
241 char *ace_name = xf86FindOptionValue(local->options, "Name");
242 char fname[EV_DEV_NAME_MAXLEN];
246 struct sysfs_bus *usb_bus = NULL;
247 struct sysfs_driver *acecad_driver = NULL;
248 struct sysfs_device *candidate = NULL;
250 struct dlist *devs = NULL;
251 struct dlist *links = NULL;
253 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
254 usb_bus = sysfs_open_bus(usb_bus_name);
256 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
257 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
259 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
260 devs = sysfs_get_driver_devices(acecad_driver);
262 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
263 dlist_for_each_data(devs, candidate, struct sysfs_device) {
264 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
265 links = sysfs_open_link_list(candidate->path);
266 dlist_for_each_data(links, link, char) {
267 if (sscanf(link, "input:event%d", &i) == 1) {
268 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
272 sysfs_close_list(links);
273 if (i > 0) /* We found something */
277 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
279 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
281 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
282 sysfs_close_bus(usb_bus);
285 /* We found something */
286 np = SET_EVENT_NUM(fname, i);
287 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
288 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
293 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
298 ace_name = ace_name_default;
300 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
305 np = SET_EVENT_NUM(fname, i);
306 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
307 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
310 SYSCALL(fd = open(fname, O_RDONLY));
312 if (errno == ENOENT) {
313 if (++noent_cnt >= max_skip)
323 is_acecad = fd_query_acecad(fd, ace_name);
329 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
330 local->name, i + 1, ace_name);
332 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
334 if (i > max_skip && !have_evdev)
335 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
339 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
341 xf86ReplaceStrOption(local->options, "Device", fname);
348 AceCadPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
350 LocalDevicePtr local = xf86AllocateInput(drv, 0);
351 AceCadPrivatePtr priv = xcalloc (1, sizeof(AceCadPrivateRec));
356 if ((!local) || (!priv))
359 memset(priv, 0, sizeof(AceCadPrivateRec));
361 local->name = dev->identifier;
362 local->type_name = XI_TABLET;
363 local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
364 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
365 local->motion_history_proc = xf86GetMotionEvents;
367 local->control_proc = NULL;
368 local->close_proc = CloseProc;
369 local->switch_mode = NULL;
370 local->conversion_proc = ConvertProc;
371 local->reverse_conversion_proc = ReverseConvertProc;
373 local->private = priv;
374 local->private_flags = 0;
375 local->conf_idev = dev;
376 local->device_control = DeviceControl;
377 /*local->always_core_feedback = 0;*/
379 xf86CollectInputOptions(local, default_options, NULL);
381 xf86OptionListReport(local->options);
383 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
385 s = xf86FindOptionValue(local->options, "Device");
386 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
388 priv->flags |= AUTODEV_FLAG;
389 if (!AceCadAutoDevProbe(local, 0))
391 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
395 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
400 local->fd = xf86OpenSerial (local->options);
403 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
406 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
409 if (IsUSBLine(local->fd)) {
410 priv->flags |= USB_FLAG;
412 local->read_input = USBReadInput;
414 if (USBQueryHardware(local) != Success)
416 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
422 local->read_input = ReadInput;
425 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
427 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
435 priv->acecadReportSpeed = 'Q';
438 priv->acecadReportSpeed = 'R';
441 priv->acecadReportSpeed = 'S';
444 priv->acecadReportSpeed = 'T';
447 priv->acecadReportSpeed = 'R';
449 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
453 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
455 priv->buffer = XisbNew (local->fd, 200);
458 * Verify that hardware is attached and fuctional
460 if (QueryHardware(priv) != Success)
462 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
467 s = xf86FindOptionValue(local->options, "Mode");
468 msgtype = s ? X_CONFIG : X_DEFAULT;
469 if (!(s && (xf86NameCmp(s, "relative") == 0)))
471 priv->flags |= ABSOLUTE_FLAG;
474 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
475 DBG (9, XisbTrace (priv->buffer, 1));
477 local->history_size = xf86SetIntOption(local->options , "HistorySize", 0);
479 xf86ProcessCommonOptions(local, local->options);
481 local->flags |= XI86_CONFIGURED;
485 RemoveEnabledDevice (local->fd);
488 XisbFree(priv->buffer);
491 xf86CloseSerial(local->fd);
493 RemoveEnabledDevice (local->fd);
498 * If something went wrong, cleanup and return NULL
501 if ((local) && (local->fd))
502 xf86CloseSerial (local->fd);
503 if ((priv) && (priv->buffer))
504 XisbFree (priv->buffer);
508 local->private = NULL;
510 xf86DeleteInput(local, 0);
515 DeviceControl (DeviceIntPtr dev, int mode)
526 RetValue = DeviceOn(dev);
529 RetValue = DeviceOff(dev);
532 RetValue = DeviceClose(dev);
542 DeviceOn (DeviceIntPtr dev)
545 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
546 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
548 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
550 local->fd = xf86OpenSerial(local->options);
553 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
554 priv->flags &= ~AVAIL_FLAG;
556 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
557 local->fd = xf86OpenSerial(local->options);
562 priv->flags |= AVAIL_FLAG;
565 if (!(priv->flags & USB_FLAG)) {
566 priv->buffer = XisbNew(local->fd, 200);
569 xf86CloseSerial(local->fd);
574 /* Rets qu'a l'envoyer a la tablette */
575 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
576 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
579 xf86FlushInput(local->fd);
580 xf86AddEnabledDevice (local);
581 dev->public.on = TRUE;
586 DeviceOff (DeviceIntPtr dev)
588 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
589 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
591 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
595 RemoveEnabledDevice (local->fd);
598 XisbFree(priv->buffer);
601 xf86CloseSerial(local->fd);
605 xf86RemoveEnabledDevice (local);
606 dev->public.on = FALSE;
611 DeviceClose (DeviceIntPtr dev)
613 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
615 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
621 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
623 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
625 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
629 DeviceInit (DeviceIntPtr dev)
632 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
633 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
634 unsigned char map[] = {0, 1, 2, 3};
635 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
639 btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
640 btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
641 btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
643 if ((priv->flags & ABSOLUTE_FLAG))
645 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
646 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
647 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
650 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
651 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
652 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Z);
656 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
659 if (InitButtonClassDeviceStruct (dev, 3,
660 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
665 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
669 if (InitFocusClassDeviceStruct (dev) == FALSE)
671 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
675 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
676 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
682 if (InitValuatorClassDeviceStruct (dev, 3,
683 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
686 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
690 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
693 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
699 InitValuatorAxisStruct(dev,
701 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
705 #if XORG_BOTCHED_INPUT
706 screenInfo.screens[0]->width,
708 priv->acecadMaxX, /* max val */
710 1000, /* resolution */
713 InitValuatorAxisStruct(dev,
715 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
719 #if XORG_BOTCHED_INPUT
720 screenInfo.screens[0]->height,
722 priv->acecadMaxY, /* max val */
724 1000, /* resolution */
727 InitValuatorAxisStruct(dev,
729 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
733 priv->acecadMaxZ, /* max val */
734 1000, /* resolution */
740 if (InitProximityClassDeviceStruct (dev) == FALSE)
742 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
746 xf86MotionHistoryAllocate (local);
749 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
750 connaitre la taille... */
752 if (priv->acecadInc > 95)
753 priv->acecadInc = 95;
754 if (priv->acecadInc < 1)
756 /* guess the best increment value given video mode */
757 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
758 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
760 priv->acecadInc = rx;
762 priv->acecadInc = ry;
763 if (priv->acecadInc < 1)
767 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
773 ReadInput (LocalDevicePtr local)
777 int is_core_pointer = 0, is_absolute;
778 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
780 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
782 is_absolute = (priv->flags & ABSOLUTE_FLAG);
783 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
784 is_core_pointer = xf86IsCorePointer(local->dev);
788 * set blocking to -1 on the first call because we know there is data to
789 * read. Xisb automatically clears it after one successful read so that
790 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
791 * read from blocking indefinately.
793 XisbBlockDuration (priv->buffer, -1);
795 while (AceCadGetPacket (priv) == Success)
797 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
798 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
800 if (!(priv->flags & ABSOLUTE_FLAG))
802 x = priv->packet[0] & XSIGN_BIT? x:-x;
803 y = priv->packet[0] & YSIGN_BIT? y:-y;
807 y = priv->acecadMaxY - y ;
811 z = ((int)priv->packet[5] << 2) |
812 (((int)priv->packet[6] & 0x01) << 1) |
813 (((int)priv->packet[6] & 0x10) >> 4);
815 buttons = ((int)priv->packet[0] & 0x07) |
816 ((int)priv->packet[6] & 0x02 << 2);
818 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
822 if (!(priv->acecadOldProximity))
823 if (!is_core_pointer)
825 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
826 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
829 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
830 || (!is_absolute && (x || y)))
832 if (is_absolute || priv->acecadOldProximity)
834 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
835 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
839 if (priv->acecadOldButtons != buttons)
841 int delta = buttons ^ priv->acecadOldButtons;
845 delta &= ~(1 << (id-1));
847 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
848 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
852 priv->acecadOldButtons = buttons;
853 priv->acecadOldX = x;
854 priv->acecadOldY = y;
855 priv->acecadOldZ = z;
856 priv->acecadOldProximity = prox;
860 if (!is_core_pointer)
861 if (priv->acecadOldProximity)
863 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
864 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
866 priv->acecadOldProximity = 0;
869 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
873 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
875 USBReadInput (LocalDevicePtr local)
878 struct input_event * event;
879 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
880 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
881 int x = priv->acecadOldX;
882 int y = priv->acecadOldY;
883 int z = priv->acecadOldZ;
884 int report_x, report_y;
885 int prox = priv->acecadOldProximity;
886 int buttons = priv->acecadOldButtons;
887 int is_core_pointer = 0;
888 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
889 is_core_pointer = xf86IsCorePointer(local->dev);
891 /* Is autodev active? */
892 int autodev = priv->flags & AUTODEV_FLAG;
893 /* Was the device available last time we checked? */
894 int avail = priv->flags & AVAIL_FLAG;
896 SYSCALL(len = read(local->fd, eventbuf, sizeof(eventbuf)));
900 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
903 priv->flags &= ~AVAIL_FLAG;
905 if (AceCadAutoDevProbe(local, 4)) {
906 DeviceOff(local->dev);
907 DeviceOn(local->dev);
914 /* If the device wasn't available last time we checked */
915 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
916 priv->flags |= AVAIL_FLAG;
920 for (event = (struct input_event *)eventbuf;
921 event < (struct input_event *)(eventbuf+len); event++) {
923 switch (event->type) {
924 case EV_SYN: /* 2.6.x */
925 if (event->code != SYN_REPORT)
926 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
929 switch (event->code) {
949 switch (event->code) {
955 buttons = set_bit(buttons,0,event->value);
959 buttons = set_bit(buttons,1,event->value);
963 buttons = set_bit(buttons,2,event->value);
968 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
969 } /* switch event->type */
971 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
972 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
974 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
975 (event->type == EV_ABS && event->code == ABS_MISC)
982 #if XORG_BOTCHED_INPUT
983 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
988 if (!(priv->acecadOldProximity))
989 if (!is_core_pointer)
991 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
995 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
997 if (priv->acecadOldButtons != buttons)
999 int delta = buttons ^ priv->acecadOldButtons;
1002 int id = ffs(delta);
1003 delta &= ~(1 << (id-1));
1005 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
1011 if (!is_core_pointer)
1012 if (priv->acecadOldProximity)
1014 xf86PostProximityEvent(local->dev, 0, 0, 3, report_x, report_y, z);
1016 priv->acecadOldProximity = 0;
1019 priv->acecadOldButtons = buttons;
1020 priv->acecadOldX = x;
1021 priv->acecadOldY = y;
1022 priv->acecadOldZ = z;
1023 priv->acecadOldProximity = prox;
1025 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
1030 CloseProc (LocalDevicePtr local)
1035 * The ConvertProc function may need to be tailored for your device.
1036 * This function converts the device's valuator outputs to x and y coordinates
1037 * to simulate mouse events.
1040 ConvertProc (LocalDevicePtr local, int first, int num,
1041 int v0, int v1, int v2, int v3, int v4, int v5,
1044 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1046 /* TODO: should have a structure to hold which screen the
1047 * pointer is attached to? */
1048 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
1049 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
1050 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
1051 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
1057 ReverseConvertProc (LocalDevicePtr local,
1061 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1063 // xf86Msg(X_INFO, "%s: reverse coordinate conversion in : %d, %d\n", local->name, x, y);
1064 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
1065 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
1066 // xf86Msg(X_INFO, "%s: reverse coordinate conversion out: %d, %d\n", local->name, valuators[0], valuators[1]);
1072 #define WriteString(str)\
1073 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1077 QueryHardware (AceCadPrivatePtr priv)
1086 /* Prompt Mode in order to not be disturbed */
1087 WriteString(ACECAD_PROMPT_MODE);
1090 while (XisbRead(priv->buffer) >= 0);
1092 /* Ask for Config packet*/
1093 WriteString(ACECAD_CONFIG);
1095 /* Read the packet */
1096 XisbBlockDuration (priv->buffer, 1000000);
1099 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1101 if ((AceCadGetPacket (priv) == Success))
1103 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1104 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1105 priv->acecadMaxZ = 512;
1106 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1111 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1115 #define BITS_PER_LONG (sizeof(long) * 8)
1116 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1117 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1118 #define OFF(x) ((x)%BITS_PER_LONG)
1119 #define LONG(x) ((x)/BITS_PER_LONG)
1123 USBQueryHardware (LocalDevicePtr local)
1125 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1126 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1129 char name[256] = "Unknown";
1131 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1132 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1134 memset(bit, 0, sizeof(bit));
1135 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1137 for (i = 0; i < EV_MAX; i++)
1138 if (test_bit(i, bit[0])) {
1139 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1140 for (j = 0; j < KEY_MAX; j++)
1141 if (test_bit(j, bit[i])) {
1143 ioctl(local->fd, EVIOCGABS(j), abs);
1146 priv->acecadMaxX = abs[2];
1150 priv->acecadMaxY = abs[2];
1154 priv->acecadMaxZ = abs[2];
1161 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1167 NewPacket (AceCadPrivatePtr priv)
1173 AceCadGetPacket (AceCadPrivatePtr priv)
1178 while((c = XisbRead(priv->buffer)) >= 0 )
1182 * fail after 500 bytes so the server doesn't hang forever if a
1183 * device sends bad data.
1191 if (c & PHASING_BIT)
1195 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1196 XisbBlockDuration (priv->buffer, 10000);
1197 priv->packet[priv->packeti++] = c;
1198 count = ACECAD_PACKET_SIZE - 1;
1199 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1201 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1202 priv->packet[priv->packeti++] = c;
1204 XisbBlockDuration (priv->buffer, 0);