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 /* Previously found in xf86Xinput.h */
77 #define DBG(lvl, f) {if ((lvl) <= xf86GetVerbosity()) f;}
79 /*****************************************************************************
81 ****************************************************************************/
84 /*****************************************************************************
85 * Variables without includable headers
86 ****************************************************************************/
88 /*****************************************************************************
90 ****************************************************************************/
93 #define read(a,b,c) xf86ReadSerial((a),(b),(c))
95 /* max number of input events to read in one read call */
98 _X_EXPORT InputDriverRec ACECAD =
110 static XF86ModuleVersionInfo VersionRec =
116 XORG_VERSION_CURRENT,
117 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
125 _X_EXPORT XF86ModuleData acecadModuleData = {
131 /*****************************************************************************
132 * Function Definitions
133 ****************************************************************************/
136 SetupProc( pointer module,
141 xf86AddInputDriver(&ACECAD, module, 0);
146 TearDownProc( pointer p )
149 LocalDevicePtr local = (LocalDevicePtr) p;
150 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
152 DeviceOff (local->dev);
154 xf86CloseSerial (local->fd);
155 XisbFree (priv->buffer);
163 static const char *default_options[] =
171 "FlowControl", "Xoff",
182 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
185 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
186 version >> 16, (version >> 8) & 0xff, version & 0xff);
189 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
194 /* Heavily inspired by synaptics/eventcomm.c */
196 #define DEV_INPUT_EVENT "/dev/input/event"
197 #define EV_DEV_NAME_MAXLEN 64
198 #define SET_EVENT_NUM(str, num) \
199 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
202 fd_query_acecad(int fd, char *ace_name) {
203 char name[256] = "Unknown";
204 int cmp_at = strlen(ace_name);
207 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
209 if (xf86NameCmp(name, ace_name) == 0)
214 static char ace_name_default[7] = "acecad";
217 static char usb_bus_name[4] = "usb";
218 static char acecad_driver_name[11] = "usb_acecad";
222 AceCadAutoDevProbe(LocalDevicePtr local, int verb)
224 /* We are trying to find the right eventX device */
226 Bool have_evdev = FALSE;
228 const int max_skip = 10;
229 char *ace_name = xf86FindOptionValue(local->options, "Name");
230 char fname[EV_DEV_NAME_MAXLEN];
234 struct sysfs_bus *usb_bus = NULL;
235 struct sysfs_driver *acecad_driver = NULL;
236 struct sysfs_device *candidate = NULL;
238 struct dlist *devs = NULL;
239 struct dlist *links = NULL;
240 unsigned int major = 0, minor = 0;
241 void *libsysfs = NULL;
243 if (libsysfs = dlopen("libsysfs.so", RTLD_NOW | RTLD_GLOBAL)) {
244 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
245 usb_bus = sysfs_open_bus(usb_bus_name);
247 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
248 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
250 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
251 devs = sysfs_get_driver_devices(acecad_driver);
253 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
254 dlist_for_each_data(devs, candidate, struct sysfs_device) {
255 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
256 links = sysfs_open_link_list(candidate->path);
257 dlist_for_each_data(links, link, char) {
258 if (sscanf(link, "input:event%d", &i) == 1) {
259 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
263 sysfs_close_list(links);
264 if (i > 0) /* We found something */
268 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
270 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
272 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
273 sysfs_close_bus(usb_bus);
277 /* We found something */
278 np = SET_EVENT_NUM(fname, i);
279 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
280 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
285 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
287 xf86MsgVerb(X_WARNING, 4, "%s: libsysfs not found\n", local->name);
292 ace_name = ace_name_default;
294 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
299 np = SET_EVENT_NUM(fname, i);
300 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
301 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
304 SYSCALL(fd = open(fname, O_RDONLY));
306 if (errno == ENOENT) {
307 if (++noent_cnt >= max_skip)
317 is_acecad = fd_query_acecad(fd, ace_name);
323 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
324 local->name, i + 1, ace_name);
326 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
328 if (i > max_skip && !have_evdev)
329 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
333 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
335 xf86ReplaceStrOption(local->options, "Device", fname);
342 AceCadPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
344 LocalDevicePtr local = xf86AllocateInput(drv, 0);
345 AceCadPrivatePtr priv = xcalloc (1, sizeof(AceCadPrivateRec));
350 if ((!local) || (!priv))
353 memset(priv, 0, sizeof(AceCadPrivateRec));
355 local->name = dev->identifier;
356 local->type_name = "ACECAD Tablet";
357 local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
358 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
359 local->motion_history_proc = xf86GetMotionEvents;
361 local->control_proc = NULL;
362 local->close_proc = CloseProc;
363 local->switch_mode = NULL;
364 local->conversion_proc = ConvertProc;
365 local->reverse_conversion_proc = ReverseConvertProc;
367 local->private = priv;
368 local->private_flags = 0;
369 local->conf_idev = dev;
370 local->device_control = DeviceControl;
371 /*local->always_core_feedback = 0;*/
373 xf86CollectInputOptions(local, default_options, NULL);
375 xf86OptionListReport(local->options);
377 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
379 s = xf86FindOptionValue(local->options, "Device");
380 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
382 priv->flags |= AUTODEV_FLAG;
383 if (!AceCadAutoDevProbe(local, 0))
385 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
389 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
394 local->fd = xf86OpenSerial (local->options);
397 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
400 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
403 if (IsUSBLine(local->fd)) {
404 priv->flags |= USB_FLAG;
406 local->read_input = USBReadInput;
408 if (USBQueryHardware(local) != Success)
410 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
416 local->read_input = ReadInput;
419 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
421 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
429 priv->acecadReportSpeed = 'Q';
432 priv->acecadReportSpeed = 'R';
435 priv->acecadReportSpeed = 'S';
438 priv->acecadReportSpeed = 'T';
441 priv->acecadReportSpeed = 'R';
443 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
447 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
449 priv->buffer = XisbNew (local->fd, 200);
452 * Verify that hardware is attached and fuctional
454 if (QueryHardware(priv) != Success)
456 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
461 s = xf86FindOptionValue(local->options, "Mode");
462 msgtype = s ? X_CONFIG : X_DEFAULT;
463 if (!(s && (xf86NameCmp(s, "relative") == 0)))
465 priv->flags |= ABSOLUTE_FLAG;
468 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
469 DBG (9, XisbTrace (priv->buffer, 1));
471 local->history_size = xf86SetIntOption(local->options , "HistorySize", 0);
473 xf86ProcessCommonOptions(local, local->options);
475 local->flags |= XI86_CONFIGURED;
479 RemoveEnabledDevice (local->fd);
482 XisbFree(priv->buffer);
485 xf86CloseSerial(local->fd);
487 RemoveEnabledDevice (local->fd);
492 * If something went wrong, cleanup and return NULL
495 if ((local) && (local->fd))
496 xf86CloseSerial (local->fd);
497 if ((priv) && (priv->buffer))
498 XisbFree (priv->buffer);
502 local->private = NULL;
504 xf86DeleteInput(local, 0);
509 DeviceControl (DeviceIntPtr dev, int mode)
520 RetValue = DeviceOn(dev);
523 RetValue = DeviceOff(dev);
526 RetValue = DeviceClose(dev);
536 DeviceOn (DeviceIntPtr dev)
539 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
540 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
542 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
544 local->fd = xf86OpenSerial(local->options);
547 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
548 priv->flags &= ~AVAIL_FLAG;
550 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
551 local->fd = xf86OpenSerial(local->options);
556 priv->flags |= AVAIL_FLAG;
559 if (!(priv->flags & USB_FLAG)) {
560 priv->buffer = XisbNew(local->fd, 200);
563 xf86CloseSerial(local->fd);
568 /* Rets qu'a l'envoyer a la tablette */
569 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
570 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
573 xf86FlushInput(local->fd);
574 xf86AddEnabledDevice (local);
575 dev->public.on = TRUE;
580 DeviceOff (DeviceIntPtr dev)
582 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
583 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
585 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
589 RemoveEnabledDevice (local->fd);
592 XisbFree(priv->buffer);
595 xf86CloseSerial(local->fd);
599 xf86RemoveEnabledDevice (local);
600 dev->public.on = FALSE;
605 DeviceClose (DeviceIntPtr dev)
607 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
609 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
615 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
617 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
619 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
623 DeviceInit (DeviceIntPtr dev)
626 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
627 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
628 unsigned char map[] =
631 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
634 if (InitButtonClassDeviceStruct (dev, 3, map) == FALSE)
636 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
640 if (InitFocusClassDeviceStruct (dev) == FALSE)
642 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
646 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
647 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
653 if (InitValuatorClassDeviceStruct (dev, 3, xf86GetMotionEvents,
655 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
658 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
664 InitValuatorAxisStruct(dev,
667 priv->acecadMaxX, /* max val */
668 1000, /* resolution */
671 InitValuatorAxisStruct(dev,
674 priv->acecadMaxY, /* max val */
675 1000, /* resolution */
678 InitValuatorAxisStruct(dev,
681 priv->acecadMaxZ, /* max val */
682 1000, /* resolution */
688 if (InitProximityClassDeviceStruct (dev) == FALSE)
690 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
694 xf86MotionHistoryAllocate (local);
697 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
698 connaitre la taille... */
700 if (priv->acecadInc > 95)
701 priv->acecadInc = 95;
702 if (priv->acecadInc < 1)
704 /* guess the best increment value given video mode */
705 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
706 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
708 priv->acecadInc = rx;
710 priv->acecadInc = ry;
711 if (priv->acecadInc < 1)
715 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
721 ReadInput (LocalDevicePtr local)
725 int is_core_pointer = 1, is_absolute;
726 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
728 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
730 is_absolute = (priv->flags & ABSOLUTE_FLAG);
731 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
732 is_core_pointer = xf86IsCorePointer(local->dev);
736 * set blocking to -1 on the first call because we know there is data to
737 * read. Xisb automatically clears it after one successful read so that
738 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
739 * read from blocking indefinately.
741 XisbBlockDuration (priv->buffer, -1);
743 while (AceCadGetPacket (priv) == Success)
745 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
746 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
748 if (!(priv->flags & ABSOLUTE_FLAG))
750 x = priv->packet[0] & XSIGN_BIT? x:-x;
751 y = priv->packet[0] & YSIGN_BIT? y:-y;
755 y = priv->acecadMaxY - y ;
759 z = ((int)priv->packet[5] << 2) |
760 (((int)priv->packet[6] & 0x01) << 1) |
761 (((int)priv->packet[6] & 0x10) >> 4);
763 buttons = ((int)priv->packet[0] & 0x07) |
764 ((int)priv->packet[6] & 0x02 << 2);
766 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
770 if (!(priv->acecadOldProximity))
771 if (!is_core_pointer)
773 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
774 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
777 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
778 || (!is_absolute && (x || y)))
780 if (is_absolute || priv->acecadOldProximity)
782 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
783 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
787 if (priv->acecadOldButtons != buttons)
789 int delta = buttons ^ priv->acecadOldButtons;
793 delta &= ~(1 << (id-1));
795 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
796 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
800 priv->acecadOldButtons = buttons;
801 priv->acecadOldX = x;
802 priv->acecadOldY = y;
803 priv->acecadOldZ = z;
804 priv->acecadOldProximity = prox;
808 if (!is_core_pointer)
809 if (priv->acecadOldProximity)
811 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
812 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
814 priv->acecadOldProximity = 0;
817 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
821 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
823 USBReadInput (LocalDevicePtr local)
826 struct input_event * event;
827 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
828 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
829 int x = priv->acecadOldX;
830 int y = priv->acecadOldY;
831 int z = priv->acecadOldZ;
832 int report_x, report_y;
833 int prox = priv->acecadOldProximity;
834 int buttons = priv->acecadOldButtons;
835 int is_core_pointer = 1;
836 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
837 is_core_pointer = xf86IsCorePointer(local->dev);
839 /* Is autodev active? */
840 int autodev = priv->flags & AUTODEV_FLAG;
841 /* Was the device available last time we checked? */
842 int avail = priv->flags & AVAIL_FLAG;
844 SYSCALL(len = read(local->fd, eventbuf, sizeof(eventbuf)));
848 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
851 priv->flags &= ~AVAIL_FLAG;
853 if (AceCadAutoDevProbe(local, 4)) {
854 DeviceOff(local->dev);
855 DeviceOn(local->dev);
862 /* If the device wasn't available last time we checked */
863 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
864 priv->flags |= AVAIL_FLAG;
868 for (event = (struct input_event *)eventbuf;
869 event < (struct input_event *)(eventbuf+len); event++) {
871 switch (event->type) {
872 case EV_SYN: /* 2.6.x */
873 if (event->code != SYN_REPORT)
874 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
877 switch (event->code) {
897 switch (event->code) {
903 buttons = set_bit(buttons,0,event->value);
907 buttons = set_bit(buttons,1,event->value);
911 buttons = set_bit(buttons,2,event->value);
916 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
917 } /* switch event->type */
919 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
920 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
922 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
923 (event->type == EV_ABS && event->code == ABS_MISC)
930 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
931 if (!(priv->acecadOldProximity))
932 if (!is_core_pointer)
934 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
938 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
940 if (priv->acecadOldButtons != buttons)
942 int delta = buttons ^ priv->acecadOldButtons;
946 delta &= ~(1 << (id-1));
948 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
954 if (!is_core_pointer)
955 if (priv->acecadOldProximity)
957 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
959 priv->acecadOldProximity = 0;
962 priv->acecadOldButtons = buttons;
963 priv->acecadOldX = x;
964 priv->acecadOldY = y;
965 priv->acecadOldZ = z;
966 priv->acecadOldProximity = prox;
968 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
973 CloseProc (LocalDevicePtr local)
978 * The ConvertProc function may need to be tailored for your device.
979 * This function converts the device's valuator outputs to x and y coordinates
980 * to simulate mouse events.
983 ConvertProc (LocalDevicePtr local, int first, int num,
984 int v0, int v1, int v2, int v3, int v4, int v5,
987 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
989 /* TODO: should have a structure to hold which screen the
990 * pointer is attached to? */
991 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
992 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
993 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
994 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
1000 ReverseConvertProc (LocalDevicePtr local,
1004 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1006 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
1007 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
1013 #define WriteString(str)\
1014 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1018 QueryHardware (AceCadPrivatePtr priv)
1027 /* Prompt Mode in order to not be disturbed */
1028 WriteString(ACECAD_PROMPT_MODE);
1031 while (XisbRead(priv->buffer) >= 0);
1033 /* Ask for Config packet*/
1034 WriteString(ACECAD_CONFIG);
1036 /* Read the packet */
1037 XisbBlockDuration (priv->buffer, 1000000);
1040 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1042 if ((AceCadGetPacket (priv) == Success))
1044 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1045 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1046 priv->acecadMaxZ = 512;
1047 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1052 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1056 #define BITS_PER_LONG (sizeof(long) * 8)
1057 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1058 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1059 #define OFF(x) ((x)%BITS_PER_LONG)
1060 #define LONG(x) ((x)/BITS_PER_LONG)
1064 USBQueryHardware (LocalDevicePtr local)
1066 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1067 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1070 char name[256] = "Unknown";
1072 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1073 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1075 memset(bit, 0, sizeof(bit));
1076 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1078 for (i = 0; i < EV_MAX; i++)
1079 if (test_bit(i, bit[0])) {
1080 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1081 for (j = 0; j < KEY_MAX; j++)
1082 if (test_bit(j, bit[i])) {
1084 ioctl(local->fd, EVIOCGABS(j), abs);
1087 priv->acecadMaxX = abs[2];
1091 priv->acecadMaxY = abs[2];
1095 priv->acecadMaxZ = abs[2];
1102 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1108 NewPacket (AceCadPrivatePtr priv)
1114 AceCadGetPacket (AceCadPrivatePtr priv)
1119 while((c = XisbRead(priv->buffer)) >= 0 )
1123 * fail after 500 bytes so the server doesn't hang forever if a
1124 * device sends bad data.
1132 if (c & PHASING_BIT)
1136 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1137 XisbBlockDuration (priv->buffer, 10000);
1138 priv->packet[priv->packeti++] = c;
1139 count = ACECAD_PACKET_SIZE - 1;
1140 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1142 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1143 priv->packet[priv->packeti++] = c;
1145 XisbBlockDuration (priv->buffer, 0);