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
39 /*****************************************************************************
41 ****************************************************************************/
44 #include <asm/types.h>
45 #include <linux/input.h>
60 #ifndef NEED_XF86_TYPES
61 #define NEED_XF86_TYPES
63 #include <xf86_OSproc.h>
65 #include <xf86Xinput.h>
67 #include <xf86Module.h>
76 #include <sysfs/libsysfs.h>
81 /* Previously found in xf86Xinput.h */
85 #define DBG(lvl, f) {if ((lvl) <= xf86GetVerbosity()) f;}
87 /*****************************************************************************
89 ****************************************************************************/
92 /*****************************************************************************
93 * Variables without includable headers
94 ****************************************************************************/
96 /*****************************************************************************
98 ****************************************************************************/
101 #define read(a,b,c) xf86ReadSerial((a),(b),(c))
103 /* max number of input events to read in one read call */
104 #define MAX_EVENTS 50
106 _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 )
157 LocalDevicePtr local = (LocalDevicePtr) p;
158 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
160 DeviceOff (local->dev);
162 xf86CloseSerial (local->fd);
163 XisbFree (priv->buffer);
171 static const char *default_options[] =
179 "FlowControl", "Xoff",
190 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
193 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
194 version >> 16, (version >> 8) & 0xff, version & 0xff);
197 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
202 /* Heavily inspired by synaptics/eventcomm.c */
204 #define DEV_INPUT_EVENT "/dev/input/event"
205 #define EV_DEV_NAME_MAXLEN 64
206 #define SET_EVENT_NUM(str, num) \
207 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
210 fd_query_acecad(int fd, char *ace_name) {
211 char name[256] = "Unknown";
212 int cmp_at = strlen(ace_name);
215 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
217 if (xf86NameCmp(name, ace_name) == 0)
222 static char ace_name_default[7] = "acecad";
225 static char usb_bus_name[4] = "usb";
226 static char acecad_driver_name[11] = "usb_acecad";
230 AceCadAutoDevProbe(LocalDevicePtr local, int verb)
232 /* We are trying to find the right eventX device */
234 Bool have_evdev = FALSE;
236 const int max_skip = 10;
237 char *ace_name = xf86FindOptionValue(local->options, "Name");
238 char fname[EV_DEV_NAME_MAXLEN];
242 struct sysfs_bus *usb_bus = NULL;
243 struct sysfs_driver *acecad_driver = NULL;
244 struct sysfs_device *candidate = NULL;
246 struct dlist *devs = NULL;
247 struct dlist *links = NULL;
248 void *libsysfs = NULL;
250 if ((libsysfs = dlopen("libsysfs.so", RTLD_NOW | RTLD_GLOBAL))) {
251 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
252 usb_bus = sysfs_open_bus(usb_bus_name);
254 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
255 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
257 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
258 devs = sysfs_get_driver_devices(acecad_driver);
260 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
261 dlist_for_each_data(devs, candidate, struct sysfs_device) {
262 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
263 links = sysfs_open_link_list(candidate->path);
264 dlist_for_each_data(links, link, char) {
265 if (sscanf(link, "input:event%d", &i) == 1) {
266 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
270 sysfs_close_list(links);
271 if (i > 0) /* We found something */
275 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
277 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
279 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
280 sysfs_close_bus(usb_bus);
284 /* We found something */
285 np = SET_EVENT_NUM(fname, i);
286 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
287 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
292 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
294 xf86MsgVerb(X_WARNING, 4, "%s: libsysfs not found\n", local->name);
299 ace_name = ace_name_default;
301 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
306 np = SET_EVENT_NUM(fname, i);
307 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
308 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
311 SYSCALL(fd = open(fname, O_RDONLY));
313 if (errno == ENOENT) {
314 if (++noent_cnt >= max_skip)
324 is_acecad = fd_query_acecad(fd, ace_name);
330 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
331 local->name, i + 1, ace_name);
333 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
335 if (i > max_skip && !have_evdev)
336 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
340 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
342 xf86ReplaceStrOption(local->options, "Device", fname);
349 AceCadPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
351 LocalDevicePtr local = xf86AllocateInput(drv, 0);
352 AceCadPrivatePtr priv = xcalloc (1, sizeof(AceCadPrivateRec));
357 if ((!local) || (!priv))
360 memset(priv, 0, sizeof(AceCadPrivateRec));
362 local->name = dev->identifier;
363 local->type_name = XI_TABLET;
364 local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
365 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
366 local->motion_history_proc = xf86GetMotionEvents;
368 local->control_proc = NULL;
369 local->close_proc = CloseProc;
370 local->switch_mode = NULL;
371 local->conversion_proc = ConvertProc;
372 local->reverse_conversion_proc = ReverseConvertProc;
374 local->private = priv;
375 local->private_flags = 0;
376 local->conf_idev = dev;
377 local->device_control = DeviceControl;
378 /*local->always_core_feedback = 0;*/
380 xf86CollectInputOptions(local, default_options, NULL);
382 xf86OptionListReport(local->options);
384 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
386 s = xf86FindOptionValue(local->options, "Device");
387 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
389 priv->flags |= AUTODEV_FLAG;
390 if (!AceCadAutoDevProbe(local, 0))
392 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
396 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
401 local->fd = xf86OpenSerial (local->options);
404 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
407 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
410 if (IsUSBLine(local->fd)) {
411 priv->flags |= USB_FLAG;
413 local->read_input = USBReadInput;
415 if (USBQueryHardware(local) != Success)
417 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
423 local->read_input = ReadInput;
426 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
428 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
436 priv->acecadReportSpeed = 'Q';
439 priv->acecadReportSpeed = 'R';
442 priv->acecadReportSpeed = 'S';
445 priv->acecadReportSpeed = 'T';
448 priv->acecadReportSpeed = 'R';
450 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
454 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
456 priv->buffer = XisbNew (local->fd, 200);
459 * Verify that hardware is attached and fuctional
461 if (QueryHardware(priv) != Success)
463 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
468 s = xf86FindOptionValue(local->options, "Mode");
469 msgtype = s ? X_CONFIG : X_DEFAULT;
470 if (!(s && (xf86NameCmp(s, "relative") == 0)))
472 priv->flags |= ABSOLUTE_FLAG;
475 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
476 DBG (9, XisbTrace (priv->buffer, 1));
478 local->history_size = xf86SetIntOption(local->options , "HistorySize", 0);
480 xf86ProcessCommonOptions(local, local->options);
482 local->flags |= XI86_CONFIGURED;
486 RemoveEnabledDevice (local->fd);
489 XisbFree(priv->buffer);
492 xf86CloseSerial(local->fd);
494 RemoveEnabledDevice (local->fd);
499 * If something went wrong, cleanup and return NULL
502 if ((local) && (local->fd))
503 xf86CloseSerial (local->fd);
504 if ((priv) && (priv->buffer))
505 XisbFree (priv->buffer);
509 local->private = NULL;
511 xf86DeleteInput(local, 0);
516 DeviceControl (DeviceIntPtr dev, int mode)
527 RetValue = DeviceOn(dev);
530 RetValue = DeviceOff(dev);
533 RetValue = DeviceClose(dev);
543 DeviceOn (DeviceIntPtr dev)
546 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
547 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
549 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
551 local->fd = xf86OpenSerial(local->options);
554 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
555 priv->flags &= ~AVAIL_FLAG;
557 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
558 local->fd = xf86OpenSerial(local->options);
563 priv->flags |= AVAIL_FLAG;
566 if (!(priv->flags & USB_FLAG)) {
567 priv->buffer = XisbNew(local->fd, 200);
570 xf86CloseSerial(local->fd);
575 /* Rets qu'a l'envoyer a la tablette */
576 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
577 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
580 xf86FlushInput(local->fd);
581 xf86AddEnabledDevice (local);
582 dev->public.on = TRUE;
587 DeviceOff (DeviceIntPtr dev)
589 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
590 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
592 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
596 RemoveEnabledDevice (local->fd);
599 XisbFree(priv->buffer);
602 xf86CloseSerial(local->fd);
606 xf86RemoveEnabledDevice (local);
607 dev->public.on = FALSE;
612 DeviceClose (DeviceIntPtr dev)
614 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
616 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
622 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
624 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
626 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
630 DeviceInit (DeviceIntPtr dev)
633 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
634 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
635 unsigned char map[] =
638 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
641 if (InitButtonClassDeviceStruct (dev, 3, map) == FALSE)
643 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
647 if (InitFocusClassDeviceStruct (dev) == FALSE)
649 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
653 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
654 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
660 if (InitValuatorClassDeviceStruct (dev, 3, xf86GetMotionEvents,
662 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
665 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
671 InitValuatorAxisStruct(dev,
674 #if XORG_BOTCHED_INPUT
675 screenInfo.screens[0]->width,
677 priv->acecadMaxX, /* max val */
679 1000, /* resolution */
682 InitValuatorAxisStruct(dev,
685 #if XORG_BOTCHED_INPUT
686 screenInfo.screens[0]->height,
688 priv->acecadMaxY, /* max val */
690 1000, /* resolution */
693 InitValuatorAxisStruct(dev,
696 priv->acecadMaxZ, /* max val */
697 1000, /* resolution */
703 if (InitProximityClassDeviceStruct (dev) == FALSE)
705 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
709 xf86MotionHistoryAllocate (local);
712 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
713 connaitre la taille... */
715 if (priv->acecadInc > 95)
716 priv->acecadInc = 95;
717 if (priv->acecadInc < 1)
719 /* guess the best increment value given video mode */
720 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
721 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
723 priv->acecadInc = rx;
725 priv->acecadInc = ry;
726 if (priv->acecadInc < 1)
730 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
736 ReadInput (LocalDevicePtr local)
740 int is_core_pointer = 0, is_absolute;
741 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
743 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
745 is_absolute = (priv->flags & ABSOLUTE_FLAG);
746 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
747 is_core_pointer = xf86IsCorePointer(local->dev);
751 * set blocking to -1 on the first call because we know there is data to
752 * read. Xisb automatically clears it after one successful read so that
753 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
754 * read from blocking indefinately.
756 XisbBlockDuration (priv->buffer, -1);
758 while (AceCadGetPacket (priv) == Success)
760 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
761 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
763 if (!(priv->flags & ABSOLUTE_FLAG))
765 x = priv->packet[0] & XSIGN_BIT? x:-x;
766 y = priv->packet[0] & YSIGN_BIT? y:-y;
770 y = priv->acecadMaxY - y ;
774 z = ((int)priv->packet[5] << 2) |
775 (((int)priv->packet[6] & 0x01) << 1) |
776 (((int)priv->packet[6] & 0x10) >> 4);
778 buttons = ((int)priv->packet[0] & 0x07) |
779 ((int)priv->packet[6] & 0x02 << 2);
781 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
785 if (!(priv->acecadOldProximity))
786 if (!is_core_pointer)
788 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
789 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
792 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
793 || (!is_absolute && (x || y)))
795 if (is_absolute || priv->acecadOldProximity)
797 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
798 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
802 if (priv->acecadOldButtons != buttons)
804 int delta = buttons ^ priv->acecadOldButtons;
808 delta &= ~(1 << (id-1));
810 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
811 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
815 priv->acecadOldButtons = buttons;
816 priv->acecadOldX = x;
817 priv->acecadOldY = y;
818 priv->acecadOldZ = z;
819 priv->acecadOldProximity = prox;
823 if (!is_core_pointer)
824 if (priv->acecadOldProximity)
826 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
827 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
829 priv->acecadOldProximity = 0;
832 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
836 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
838 USBReadInput (LocalDevicePtr local)
841 struct input_event * event;
842 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
843 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
844 int x = priv->acecadOldX;
845 int y = priv->acecadOldY;
846 int z = priv->acecadOldZ;
847 int report_x, report_y;
848 int prox = priv->acecadOldProximity;
849 int buttons = priv->acecadOldButtons;
850 int is_core_pointer = 0;
851 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
852 is_core_pointer = xf86IsCorePointer(local->dev);
854 /* Is autodev active? */
855 int autodev = priv->flags & AUTODEV_FLAG;
856 /* Was the device available last time we checked? */
857 int avail = priv->flags & AVAIL_FLAG;
859 SYSCALL(len = read(local->fd, eventbuf, sizeof(eventbuf)));
863 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
866 priv->flags &= ~AVAIL_FLAG;
868 if (AceCadAutoDevProbe(local, 4)) {
869 DeviceOff(local->dev);
870 DeviceOn(local->dev);
877 /* If the device wasn't available last time we checked */
878 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
879 priv->flags |= AVAIL_FLAG;
883 for (event = (struct input_event *)eventbuf;
884 event < (struct input_event *)(eventbuf+len); event++) {
886 switch (event->type) {
887 case EV_SYN: /* 2.6.x */
888 if (event->code != SYN_REPORT)
889 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
892 switch (event->code) {
912 switch (event->code) {
918 buttons = set_bit(buttons,0,event->value);
922 buttons = set_bit(buttons,1,event->value);
926 buttons = set_bit(buttons,2,event->value);
931 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
932 } /* switch event->type */
934 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
935 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
937 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
938 (event->type == EV_ABS && event->code == ABS_MISC)
945 #if XORG_BOTCHED_INPUT
946 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
951 if (!(priv->acecadOldProximity))
952 if (!is_core_pointer)
954 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
958 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
960 if (priv->acecadOldButtons != buttons)
962 int delta = buttons ^ priv->acecadOldButtons;
966 delta &= ~(1 << (id-1));
968 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
974 if (!is_core_pointer)
975 if (priv->acecadOldProximity)
977 xf86PostProximityEvent(local->dev, 0, 0, 3, report_x, report_y, z);
979 priv->acecadOldProximity = 0;
982 priv->acecadOldButtons = buttons;
983 priv->acecadOldX = x;
984 priv->acecadOldY = y;
985 priv->acecadOldZ = z;
986 priv->acecadOldProximity = prox;
988 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
993 CloseProc (LocalDevicePtr local)
998 * The ConvertProc function may need to be tailored for your device.
999 * This function converts the device's valuator outputs to x and y coordinates
1000 * to simulate mouse events.
1003 ConvertProc (LocalDevicePtr local, int first, int num,
1004 int v0, int v1, int v2, int v3, int v4, int v5,
1007 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1009 /* TODO: should have a structure to hold which screen the
1010 * pointer is attached to? */
1011 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
1012 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
1013 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
1014 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
1020 ReverseConvertProc (LocalDevicePtr local,
1024 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1026 // xf86Msg(X_INFO, "%s: reverse coordinate conversion in : %d, %d\n", local->name, x, y);
1027 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
1028 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
1029 // xf86Msg(X_INFO, "%s: reverse coordinate conversion out: %d, %d\n", local->name, valuators[0], valuators[1]);
1035 #define WriteString(str)\
1036 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1040 QueryHardware (AceCadPrivatePtr priv)
1049 /* Prompt Mode in order to not be disturbed */
1050 WriteString(ACECAD_PROMPT_MODE);
1053 while (XisbRead(priv->buffer) >= 0);
1055 /* Ask for Config packet*/
1056 WriteString(ACECAD_CONFIG);
1058 /* Read the packet */
1059 XisbBlockDuration (priv->buffer, 1000000);
1062 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1064 if ((AceCadGetPacket (priv) == Success))
1066 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1067 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1068 priv->acecadMaxZ = 512;
1069 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1074 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1078 #define BITS_PER_LONG (sizeof(long) * 8)
1079 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1080 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1081 #define OFF(x) ((x)%BITS_PER_LONG)
1082 #define LONG(x) ((x)/BITS_PER_LONG)
1086 USBQueryHardware (LocalDevicePtr local)
1088 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1089 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1092 char name[256] = "Unknown";
1094 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1095 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1097 memset(bit, 0, sizeof(bit));
1098 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1100 for (i = 0; i < EV_MAX; i++)
1101 if (test_bit(i, bit[0])) {
1102 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1103 for (j = 0; j < KEY_MAX; j++)
1104 if (test_bit(j, bit[i])) {
1106 ioctl(local->fd, EVIOCGABS(j), abs);
1109 priv->acecadMaxX = abs[2];
1113 priv->acecadMaxY = abs[2];
1117 priv->acecadMaxZ = abs[2];
1124 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1130 NewPacket (AceCadPrivatePtr priv)
1136 AceCadGetPacket (AceCadPrivatePtr priv)
1141 while((c = XisbRead(priv->buffer)) >= 0 )
1145 * fail after 500 bytes so the server doesn't hang forever if a
1146 * device sends bad data.
1154 if (c & PHASING_BIT)
1158 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1159 XisbBlockDuration (priv->buffer, 10000);
1160 priv->packet[priv->packeti++] = c;
1161 count = ACECAD_PACKET_SIZE - 1;
1162 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1164 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1165 priv->packet[priv->packeti++] = c;
1167 XisbBlockDuration (priv->buffer, 0);