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
29 #include <xorg-server.h>
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 ****************************************************************************/
104 /* max number of input events to read in one read call */
105 #define MAX_EVENTS 50
107 _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 )
158 static const char *default_options[] =
166 "FlowControl", "Xoff",
177 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
180 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
181 version >> 16, (version >> 8) & 0xff, version & 0xff);
184 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
189 /* Heavily inspired by synaptics/eventcomm.c */
191 #define DEV_INPUT_EVENT "/dev/input/event"
192 #define EV_DEV_NAME_MAXLEN 64
193 #define SET_EVENT_NUM(str, num) \
194 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
197 fd_query_acecad(int fd, char *ace_name) {
198 char name[256] = "Unknown";
199 int cmp_at = strlen(ace_name);
202 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
204 if (xf86NameCmp(name, ace_name) == 0)
209 static char ace_name_default[7] = "acecad";
212 static char usb_bus_name[4] = "usb";
213 static char acecad_driver_name[11] = "usb_acecad";
217 AceCadAutoDevProbe(LocalDevicePtr local, int verb)
219 /* We are trying to find the right eventX device */
221 Bool have_evdev = FALSE;
223 const int max_skip = 10;
224 char *ace_name = xf86FindOptionValue(local->options, "Name");
225 char fname[EV_DEV_NAME_MAXLEN];
229 struct sysfs_bus *usb_bus = NULL;
230 struct sysfs_driver *acecad_driver = NULL;
231 struct sysfs_device *candidate = NULL;
233 struct dlist *devs = NULL;
234 struct dlist *links = NULL;
236 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
237 usb_bus = sysfs_open_bus(usb_bus_name);
239 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
240 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
242 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
243 devs = sysfs_get_driver_devices(acecad_driver);
245 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
246 dlist_for_each_data(devs, candidate, struct sysfs_device) {
247 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
248 links = sysfs_open_link_list(candidate->path);
249 dlist_for_each_data(links, link, char) {
250 if (sscanf(link, "input:event%d", &i) == 1) {
251 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
255 sysfs_close_list(links);
256 if (i > 0) /* We found something */
260 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
262 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
264 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
265 sysfs_close_bus(usb_bus);
268 /* We found something */
269 np = SET_EVENT_NUM(fname, i);
270 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
271 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
276 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
281 ace_name = ace_name_default;
283 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
288 np = SET_EVENT_NUM(fname, i);
289 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
290 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
293 SYSCALL(fd = open(fname, O_RDONLY));
295 if (errno == ENOENT) {
296 if (++noent_cnt >= max_skip)
306 is_acecad = fd_query_acecad(fd, ace_name);
312 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
313 local->name, i + 1, ace_name);
315 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
317 if (i > max_skip && !have_evdev)
318 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
322 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
324 xf86ReplaceStrOption(local->options, "Device", fname);
331 AceCadPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
333 LocalDevicePtr local = xf86AllocateInput(drv, 0);
334 AceCadPrivatePtr priv = xcalloc (1, sizeof(AceCadPrivateRec));
339 if ((!local) || (!priv))
342 memset(priv, 0, sizeof(AceCadPrivateRec));
344 local->name = dev->identifier;
345 local->type_name = XI_TABLET;
346 local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
347 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
348 local->motion_history_proc = xf86GetMotionEvents;
350 local->control_proc = NULL;
351 local->close_proc = CloseProc;
352 local->switch_mode = NULL;
353 local->conversion_proc = ConvertProc;
354 local->reverse_conversion_proc = ReverseConvertProc;
356 local->private = priv;
357 local->private_flags = 0;
358 local->conf_idev = dev;
359 local->device_control = DeviceControl;
360 /*local->always_core_feedback = 0;*/
362 xf86CollectInputOptions(local, default_options, NULL);
364 xf86OptionListReport(local->options);
366 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
368 s = xf86FindOptionValue(local->options, "Device");
369 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
371 priv->flags |= AUTODEV_FLAG;
372 if (!AceCadAutoDevProbe(local, 0))
374 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
378 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
383 local->fd = xf86OpenSerial (local->options);
386 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
389 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
392 if (IsUSBLine(local->fd)) {
393 priv->flags |= USB_FLAG;
395 local->read_input = USBReadInput;
397 if (USBQueryHardware(local) != Success)
399 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
405 local->read_input = ReadInput;
408 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
410 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
418 priv->acecadReportSpeed = 'Q';
421 priv->acecadReportSpeed = 'R';
424 priv->acecadReportSpeed = 'S';
427 priv->acecadReportSpeed = 'T';
430 priv->acecadReportSpeed = 'R';
432 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
436 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
438 priv->buffer = XisbNew (local->fd, 200);
441 * Verify that hardware is attached and fuctional
443 if (QueryHardware(priv) != Success)
445 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
450 s = xf86FindOptionValue(local->options, "Mode");
451 msgtype = s ? X_CONFIG : X_DEFAULT;
452 if (!(s && (xf86NameCmp(s, "relative") == 0)))
454 priv->flags |= ABSOLUTE_FLAG;
457 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
458 DBG (9, XisbTrace (priv->buffer, 1));
460 local->history_size = xf86SetIntOption(local->options , "HistorySize", 0);
462 xf86ProcessCommonOptions(local, local->options);
464 local->flags |= XI86_CONFIGURED;
468 RemoveEnabledDevice (local->fd);
471 XisbFree(priv->buffer);
474 xf86CloseSerial(local->fd);
476 RemoveEnabledDevice (local->fd);
481 * If something went wrong, cleanup and return NULL
484 if ((local) && (local->fd))
485 xf86CloseSerial (local->fd);
486 if ((priv) && (priv->buffer))
487 XisbFree (priv->buffer);
491 local->private = NULL;
493 xf86DeleteInput(local, 0);
498 DeviceControl (DeviceIntPtr dev, int mode)
509 RetValue = DeviceOn(dev);
512 RetValue = DeviceOff(dev);
515 RetValue = DeviceClose(dev);
525 DeviceOn (DeviceIntPtr dev)
528 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
529 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
531 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
533 local->fd = xf86OpenSerial(local->options);
536 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
537 priv->flags &= ~AVAIL_FLAG;
539 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
540 local->fd = xf86OpenSerial(local->options);
545 priv->flags |= AVAIL_FLAG;
548 if (!(priv->flags & USB_FLAG)) {
549 priv->buffer = XisbNew(local->fd, 200);
552 xf86CloseSerial(local->fd);
557 /* Rets qu'a l'envoyer a la tablette */
558 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
559 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
562 xf86FlushInput(local->fd);
563 xf86AddEnabledDevice (local);
564 dev->public.on = TRUE;
569 DeviceOff (DeviceIntPtr dev)
571 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
572 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
574 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
578 RemoveEnabledDevice (local->fd);
581 XisbFree(priv->buffer);
584 xf86CloseSerial(local->fd);
588 xf86RemoveEnabledDevice (local);
589 dev->public.on = FALSE;
594 DeviceClose (DeviceIntPtr dev)
596 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
598 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
604 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
606 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
608 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
612 DeviceInit (DeviceIntPtr dev)
615 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
616 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
617 unsigned char map[] = {0, 1, 2, 3};
618 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
622 btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
623 btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
624 btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
626 if ((priv->flags & ABSOLUTE_FLAG))
628 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
629 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
630 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
633 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
634 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
635 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Z);
639 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
642 if (InitButtonClassDeviceStruct (dev, 3,
643 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
648 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
652 if (InitFocusClassDeviceStruct (dev) == FALSE)
654 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
658 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
659 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
665 if (InitValuatorClassDeviceStruct (dev, 3,
666 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
669 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
673 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
676 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
682 InitValuatorAxisStruct(dev,
684 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
688 #if XORG_BOTCHED_INPUT
689 screenInfo.screens[0]->width,
691 priv->acecadMaxX, /* max val */
693 1000, /* resolution */
696 InitValuatorAxisStruct(dev,
698 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
702 #if XORG_BOTCHED_INPUT
703 screenInfo.screens[0]->height,
705 priv->acecadMaxY, /* max val */
707 1000, /* resolution */
710 InitValuatorAxisStruct(dev,
712 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
716 priv->acecadMaxZ, /* max val */
717 1000, /* resolution */
723 if (InitProximityClassDeviceStruct (dev) == FALSE)
725 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
729 xf86MotionHistoryAllocate (local);
732 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
733 connaitre la taille... */
735 if (priv->acecadInc > 95)
736 priv->acecadInc = 95;
737 if (priv->acecadInc < 1)
739 /* guess the best increment value given video mode */
740 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
741 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
743 priv->acecadInc = rx;
745 priv->acecadInc = ry;
746 if (priv->acecadInc < 1)
750 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
756 ReadInput (LocalDevicePtr local)
760 int is_core_pointer = 0, is_absolute;
761 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
763 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
765 is_absolute = (priv->flags & ABSOLUTE_FLAG);
766 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
767 is_core_pointer = xf86IsCorePointer(local->dev);
771 * set blocking to -1 on the first call because we know there is data to
772 * read. Xisb automatically clears it after one successful read so that
773 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
774 * read from blocking indefinately.
776 XisbBlockDuration (priv->buffer, -1);
778 while (AceCadGetPacket (priv) == Success)
780 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
781 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
783 if (!(priv->flags & ABSOLUTE_FLAG))
785 x = priv->packet[0] & XSIGN_BIT? x:-x;
786 y = priv->packet[0] & YSIGN_BIT? y:-y;
790 y = priv->acecadMaxY - y ;
794 z = ((int)priv->packet[5] << 2) |
795 (((int)priv->packet[6] & 0x01) << 1) |
796 (((int)priv->packet[6] & 0x10) >> 4);
798 buttons = ((int)priv->packet[0] & 0x07) |
799 ((int)priv->packet[6] & 0x02 << 2);
801 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
805 if (!(priv->acecadOldProximity))
806 if (!is_core_pointer)
808 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
809 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
812 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
813 || (!is_absolute && (x || y)))
815 if (is_absolute || priv->acecadOldProximity)
817 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
818 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
822 if (priv->acecadOldButtons != buttons)
824 int delta = buttons ^ priv->acecadOldButtons;
828 delta &= ~(1 << (id-1));
830 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
831 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
835 priv->acecadOldButtons = buttons;
836 priv->acecadOldX = x;
837 priv->acecadOldY = y;
838 priv->acecadOldZ = z;
839 priv->acecadOldProximity = prox;
843 if (!is_core_pointer)
844 if (priv->acecadOldProximity)
846 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
847 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
849 priv->acecadOldProximity = 0;
852 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
856 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
858 USBReadInput (LocalDevicePtr local)
861 struct input_event * event;
862 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
863 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
864 int x = priv->acecadOldX;
865 int y = priv->acecadOldY;
866 int z = priv->acecadOldZ;
867 int report_x, report_y;
868 int prox = priv->acecadOldProximity;
869 int buttons = priv->acecadOldButtons;
870 int is_core_pointer = 0;
871 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
872 is_core_pointer = xf86IsCorePointer(local->dev);
874 /* Is autodev active? */
875 int autodev = priv->flags & AUTODEV_FLAG;
876 /* Was the device available last time we checked? */
877 int avail = priv->flags & AVAIL_FLAG;
879 SYSCALL(len = xf86ReadSerial(local->fd, eventbuf, sizeof(eventbuf)));
883 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
886 priv->flags &= ~AVAIL_FLAG;
888 if (AceCadAutoDevProbe(local, 4)) {
889 DeviceOff(local->dev);
890 DeviceOn(local->dev);
897 /* If the device wasn't available last time we checked */
898 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
899 priv->flags |= AVAIL_FLAG;
903 for (event = (struct input_event *)eventbuf;
904 event < (struct input_event *)(eventbuf+len); event++) {
906 switch (event->type) {
907 case EV_SYN: /* 2.6.x */
908 if (event->code != SYN_REPORT)
909 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
912 switch (event->code) {
932 switch (event->code) {
938 buttons = set_bit(buttons,0,event->value);
942 buttons = set_bit(buttons,1,event->value);
946 buttons = set_bit(buttons,2,event->value);
951 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
952 } /* switch event->type */
954 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
955 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
957 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
958 (event->type == EV_ABS && event->code == ABS_MISC)
965 #if XORG_BOTCHED_INPUT
966 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
971 if (!(priv->acecadOldProximity))
972 if (!is_core_pointer)
974 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
978 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
980 if (priv->acecadOldButtons != buttons)
982 int delta = buttons ^ priv->acecadOldButtons;
986 delta &= ~(1 << (id-1));
988 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
994 if (!is_core_pointer)
995 if (priv->acecadOldProximity)
997 xf86PostProximityEvent(local->dev, 0, 0, 3, report_x, report_y, z);
999 priv->acecadOldProximity = 0;
1002 priv->acecadOldButtons = buttons;
1003 priv->acecadOldX = x;
1004 priv->acecadOldY = y;
1005 priv->acecadOldZ = z;
1006 priv->acecadOldProximity = prox;
1008 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
1013 CloseProc (LocalDevicePtr local)
1018 * The ConvertProc function may need to be tailored for your device.
1019 * This function converts the device's valuator outputs to x and y coordinates
1020 * to simulate mouse events.
1023 ConvertProc (LocalDevicePtr local, int first, int num,
1024 int v0, int v1, int v2, int v3, int v4, int v5,
1027 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1029 /* TODO: should have a structure to hold which screen the
1030 * pointer is attached to? */
1031 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
1032 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
1033 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
1034 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
1040 ReverseConvertProc (LocalDevicePtr local,
1044 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1046 // xf86Msg(X_INFO, "%s: reverse coordinate conversion in : %d, %d\n", local->name, x, y);
1047 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
1048 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
1049 // xf86Msg(X_INFO, "%s: reverse coordinate conversion out: %d, %d\n", local->name, valuators[0], valuators[1]);
1055 #define WriteString(str)\
1056 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1060 QueryHardware (AceCadPrivatePtr priv)
1069 /* Prompt Mode in order to not be disturbed */
1070 WriteString(ACECAD_PROMPT_MODE);
1073 while (XisbRead(priv->buffer) >= 0);
1075 /* Ask for Config packet*/
1076 WriteString(ACECAD_CONFIG);
1078 /* Read the packet */
1079 XisbBlockDuration (priv->buffer, 1000000);
1082 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1084 if ((AceCadGetPacket (priv) == Success))
1086 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1087 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1088 priv->acecadMaxZ = 512;
1089 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1094 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1098 #define BITS_PER_LONG (sizeof(long) * 8)
1099 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1100 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1101 #define OFF(x) ((x)%BITS_PER_LONG)
1102 #define LONG(x) ((x)/BITS_PER_LONG)
1106 USBQueryHardware (LocalDevicePtr local)
1108 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1109 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1112 char name[256] = "Unknown";
1114 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1115 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1117 memset(bit, 0, sizeof(bit));
1118 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1120 for (i = 0; i < EV_MAX; i++)
1121 if (test_bit(i, bit[0])) {
1122 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1123 for (j = 0; j < KEY_MAX; j++)
1124 if (test_bit(j, bit[i])) {
1126 ioctl(local->fd, EVIOCGABS(j), abs);
1129 priv->acecadMaxX = abs[2];
1133 priv->acecadMaxY = abs[2];
1137 priv->acecadMaxZ = abs[2];
1144 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1150 NewPacket (AceCadPrivatePtr priv)
1156 AceCadGetPacket (AceCadPrivatePtr priv)
1161 while((c = XisbRead(priv->buffer)) >= 0 )
1165 * fail after 500 bytes so the server doesn't hang forever if a
1166 * device sends bad data.
1174 if (c & PHASING_BIT)
1178 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1179 XisbBlockDuration (priv->buffer, 10000);
1180 priv->packet[priv->packeti++] = c;
1181 count = ACECAD_PACKET_SIZE - 1;
1182 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1184 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1185 priv->packet[priv->packeti++] = c;
1187 XisbBlockDuration (priv->buffer, 0);