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, 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 is_core_pointer = xf86IsCorePointer(local->dev);
734 * set blocking to -1 on the first call because we know there is data to
735 * read. Xisb automatically clears it after one successful read so that
736 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
737 * read from blocking indefinately.
739 XisbBlockDuration (priv->buffer, -1);
741 while (AceCadGetPacket (priv) == Success)
743 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
744 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
746 if (!(priv->flags & ABSOLUTE_FLAG))
748 x = priv->packet[0] & XSIGN_BIT? x:-x;
749 y = priv->packet[0] & YSIGN_BIT? y:-y;
753 y = priv->acecadMaxY - y ;
757 z = ((int)priv->packet[5] << 2) |
758 (((int)priv->packet[6] & 0x01) << 1) |
759 (((int)priv->packet[6] & 0x10) >> 4);
761 buttons = ((int)priv->packet[0] & 0x07) |
762 ((int)priv->packet[6] & 0x02 << 2);
764 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
768 if (!(priv->acecadOldProximity))
769 if (!is_core_pointer)
771 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
772 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
775 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
776 || (!is_absolute && (x || y)))
778 if (is_absolute || priv->acecadOldProximity)
780 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
781 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
785 if (priv->acecadOldButtons != buttons)
787 int delta = buttons ^ priv->acecadOldButtons;
791 delta &= ~(1 << (id-1));
793 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
794 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
798 priv->acecadOldButtons = buttons;
799 priv->acecadOldX = x;
800 priv->acecadOldY = y;
801 priv->acecadOldZ = z;
802 priv->acecadOldProximity = prox;
806 if (!is_core_pointer)
807 if (priv->acecadOldProximity)
809 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
810 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
812 priv->acecadOldProximity = 0;
815 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
819 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
821 USBReadInput (LocalDevicePtr local)
824 struct input_event * event;
825 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
826 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
827 int x = priv->acecadOldX;
828 int y = priv->acecadOldY;
829 int z = priv->acecadOldZ;
830 int prox = priv->acecadOldProximity;
831 int buttons = priv->acecadOldButtons;
832 int is_core_pointer = xf86IsCorePointer(local->dev);
833 /* Is autodev active? */
834 int autodev = priv->flags & AUTODEV_FLAG;
835 /* Was the device available last time we checked? */
836 int avail = priv->flags & AVAIL_FLAG;
838 SYSCALL(len = read(local->fd, eventbuf, sizeof(eventbuf)));
842 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
845 priv->flags &= ~AVAIL_FLAG;
847 if (AceCadAutoDevProbe(local, 4)) {
848 DeviceOff(local->dev);
849 DeviceOn(local->dev);
856 /* If the device wasn't available last time we checked */
857 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
858 priv->flags |= AVAIL_FLAG;
862 for (event = (struct input_event *)eventbuf;
863 event < (struct input_event *)(eventbuf+len); event++) {
865 switch (event->type) {
866 case EV_SYN: /* 2.6.x */
867 if (event->code != SYN_REPORT)
868 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
871 switch (event->code) {
891 switch (event->code) {
897 buttons = set_bit(buttons,0,event->value);
901 buttons = set_bit(buttons,1,event->value);
905 buttons = set_bit(buttons,2,event->value);
910 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
911 } /* switch event->type */
913 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
914 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
916 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
917 (event->type == EV_ABS && event->code == ABS_MISC)
924 if (!(priv->acecadOldProximity))
925 if (!is_core_pointer)
927 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
931 xf86PostMotionEvent(local->dev, 1, 0, 3, x, y, z);
933 if (priv->acecadOldButtons != buttons)
935 int delta = buttons ^ priv->acecadOldButtons;
939 delta &= ~(1 << (id-1));
941 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
947 if (!is_core_pointer)
948 if (priv->acecadOldProximity)
950 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
952 priv->acecadOldProximity = 0;
955 priv->acecadOldButtons = buttons;
956 priv->acecadOldX = x;
957 priv->acecadOldY = y;
958 priv->acecadOldZ = z;
959 priv->acecadOldProximity = prox;
961 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
966 CloseProc (LocalDevicePtr local)
971 * The ConvertProc function may need to be tailored for your device.
972 * This function converts the device's valuator outputs to x and y coordinates
973 * to simulate mouse events.
976 ConvertProc (LocalDevicePtr local, int first, int num,
977 int v0, int v1, int v2, int v3, int v4, int v5,
980 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
982 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
983 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
989 ReverseConvertProc (LocalDevicePtr local,
993 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
995 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
996 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
1002 #define WriteString(str)\
1003 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1007 QueryHardware (AceCadPrivatePtr priv)
1016 /* Prompt Mode in order to not be disturbed */
1017 WriteString(ACECAD_PROMPT_MODE);
1020 while (XisbRead(priv->buffer) >= 0);
1022 /* Ask for Config packet*/
1023 WriteString(ACECAD_CONFIG);
1025 /* Read the packet */
1026 XisbBlockDuration (priv->buffer, 1000000);
1029 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1031 if ((AceCadGetPacket (priv) == Success))
1033 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1034 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1035 priv->acecadMaxZ = 512;
1036 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1041 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1045 #define BITS_PER_LONG (sizeof(long) * 8)
1046 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1047 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1048 #define OFF(x) ((x)%BITS_PER_LONG)
1049 #define LONG(x) ((x)/BITS_PER_LONG)
1053 USBQueryHardware (LocalDevicePtr local)
1055 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1056 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1059 char name[256] = "Unknown";
1061 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1062 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1064 memset(bit, 0, sizeof(bit));
1065 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1067 for (i = 0; i < EV_MAX; i++)
1068 if (test_bit(i, bit[0])) {
1069 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1070 for (j = 0; j < KEY_MAX; j++)
1071 if (test_bit(j, bit[i])) {
1073 ioctl(local->fd, EVIOCGABS(j), abs);
1076 priv->acecadMaxX = abs[2];
1080 priv->acecadMaxY = abs[2];
1084 priv->acecadMaxZ = abs[2];
1091 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1097 NewPacket (AceCadPrivatePtr priv)
1103 AceCadGetPacket (AceCadPrivatePtr priv)
1108 while((c = XisbRead(priv->buffer)) >= 0 )
1112 * fail after 500 bytes so the server doesn't hang forever if a
1113 * device sends bad data.
1121 if (c & PHASING_BIT)
1125 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1126 XisbBlockDuration (priv->buffer, 10000);
1127 priv->packet[priv->packeti++] = c;
1128 count = ACECAD_PACKET_SIZE - 1;
1129 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1131 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1132 priv->packet[priv->packeti++] = c;
1134 XisbBlockDuration (priv->buffer, 0);