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)
34 /*****************************************************************************
36 ****************************************************************************/
39 #include <asm/types.h>
40 #include <linux/input.h>
55 #ifndef NEED_XF86_TYPES
56 #define NEED_XF86_TYPES
58 #include <xf86_OSproc.h>
60 #include <xf86Xinput.h>
62 #include <xf86Module.h>
71 #include <sysfs/libsysfs.h>
76 /* Previously found in xf86Xinput.h */
80 #define DBG(lvl, f) {if ((lvl) <= xf86GetVerbosity()) f;}
82 /*****************************************************************************
84 ****************************************************************************/
87 /*****************************************************************************
88 * Variables without includable headers
89 ****************************************************************************/
91 /*****************************************************************************
93 ****************************************************************************/
96 #define read(a,b,c) xf86ReadSerial((a),(b),(c))
98 /* max number of input events to read in one read call */
101 _X_EXPORT InputDriverRec ACECAD =
113 static XF86ModuleVersionInfo VersionRec =
119 XORG_VERSION_CURRENT,
120 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
128 _X_EXPORT XF86ModuleData acecadModuleData = {
134 /*****************************************************************************
135 * Function Definitions
136 ****************************************************************************/
139 SetupProc( pointer module,
144 xf86AddInputDriver(&ACECAD, module, 0);
149 TearDownProc( pointer p )
152 LocalDevicePtr local = (LocalDevicePtr) p;
153 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
155 DeviceOff (local->dev);
157 xf86CloseSerial (local->fd);
158 XisbFree (priv->buffer);
166 static const char *default_options[] =
174 "FlowControl", "Xoff",
185 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
188 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
189 version >> 16, (version >> 8) & 0xff, version & 0xff);
192 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
197 /* Heavily inspired by synaptics/eventcomm.c */
199 #define DEV_INPUT_EVENT "/dev/input/event"
200 #define EV_DEV_NAME_MAXLEN 64
201 #define SET_EVENT_NUM(str, num) \
202 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
205 fd_query_acecad(int fd, char *ace_name) {
206 char name[256] = "Unknown";
207 int cmp_at = strlen(ace_name);
210 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
212 if (xf86NameCmp(name, ace_name) == 0)
217 static char ace_name_default[7] = "acecad";
220 static char usb_bus_name[4] = "usb";
221 static char acecad_driver_name[11] = "usb_acecad";
225 AceCadAutoDevProbe(LocalDevicePtr local, int verb)
227 /* We are trying to find the right eventX device */
229 Bool have_evdev = FALSE;
231 const int max_skip = 10;
232 char *ace_name = xf86FindOptionValue(local->options, "Name");
233 char fname[EV_DEV_NAME_MAXLEN];
237 struct sysfs_bus *usb_bus = NULL;
238 struct sysfs_driver *acecad_driver = NULL;
239 struct sysfs_device *candidate = NULL;
241 struct dlist *devs = NULL;
242 struct dlist *links = NULL;
243 unsigned int major = 0, minor = 0;
244 void *libsysfs = NULL;
246 if (libsysfs = dlopen("libsysfs.so", RTLD_NOW | RTLD_GLOBAL)) {
247 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
248 usb_bus = sysfs_open_bus(usb_bus_name);
250 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
251 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
253 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
254 devs = sysfs_get_driver_devices(acecad_driver);
256 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
257 dlist_for_each_data(devs, candidate, struct sysfs_device) {
258 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
259 links = sysfs_open_link_list(candidate->path);
260 dlist_for_each_data(links, link, char) {
261 if (sscanf(link, "input:event%d", &i) == 1) {
262 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
266 sysfs_close_list(links);
267 if (i > 0) /* We found something */
271 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
273 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
275 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
276 sysfs_close_bus(usb_bus);
280 /* We found something */
281 np = SET_EVENT_NUM(fname, i);
282 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
283 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
288 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
290 xf86MsgVerb(X_WARNING, 4, "%s: libsysfs not found\n", local->name);
295 ace_name = ace_name_default;
297 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
302 np = SET_EVENT_NUM(fname, i);
303 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
304 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
307 SYSCALL(fd = open(fname, O_RDONLY));
309 if (errno == ENOENT) {
310 if (++noent_cnt >= max_skip)
320 is_acecad = fd_query_acecad(fd, ace_name);
326 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
327 local->name, i + 1, ace_name);
329 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
331 if (i > max_skip && !have_evdev)
332 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
336 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
338 xf86ReplaceStrOption(local->options, "Device", fname);
345 AceCadPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
347 LocalDevicePtr local = xf86AllocateInput(drv, 0);
348 AceCadPrivatePtr priv = xcalloc (1, sizeof(AceCadPrivateRec));
353 if ((!local) || (!priv))
356 memset(priv, 0, sizeof(AceCadPrivateRec));
358 local->name = dev->identifier;
359 local->type_name = XI_TABLET;
360 local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
361 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
362 local->motion_history_proc = xf86GetMotionEvents;
364 local->control_proc = NULL;
365 local->close_proc = CloseProc;
366 local->switch_mode = NULL;
367 local->conversion_proc = ConvertProc;
368 local->reverse_conversion_proc = ReverseConvertProc;
370 local->private = priv;
371 local->private_flags = 0;
372 local->conf_idev = dev;
373 local->device_control = DeviceControl;
374 /*local->always_core_feedback = 0;*/
376 xf86CollectInputOptions(local, default_options, NULL);
378 xf86OptionListReport(local->options);
380 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
382 s = xf86FindOptionValue(local->options, "Device");
383 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
385 priv->flags |= AUTODEV_FLAG;
386 if (!AceCadAutoDevProbe(local, 0))
388 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
392 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
397 local->fd = xf86OpenSerial (local->options);
400 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
403 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
406 if (IsUSBLine(local->fd)) {
407 priv->flags |= USB_FLAG;
409 local->read_input = USBReadInput;
411 if (USBQueryHardware(local) != Success)
413 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
419 local->read_input = ReadInput;
422 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
424 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
432 priv->acecadReportSpeed = 'Q';
435 priv->acecadReportSpeed = 'R';
438 priv->acecadReportSpeed = 'S';
441 priv->acecadReportSpeed = 'T';
444 priv->acecadReportSpeed = 'R';
446 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
450 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
452 priv->buffer = XisbNew (local->fd, 200);
455 * Verify that hardware is attached and fuctional
457 if (QueryHardware(priv) != Success)
459 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
464 s = xf86FindOptionValue(local->options, "Mode");
465 msgtype = s ? X_CONFIG : X_DEFAULT;
466 if (!(s && (xf86NameCmp(s, "relative") == 0)))
468 priv->flags |= ABSOLUTE_FLAG;
471 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
472 DBG (9, XisbTrace (priv->buffer, 1));
474 local->history_size = xf86SetIntOption(local->options , "HistorySize", 0);
476 xf86ProcessCommonOptions(local, local->options);
478 local->flags |= XI86_CONFIGURED;
482 RemoveEnabledDevice (local->fd);
485 XisbFree(priv->buffer);
488 xf86CloseSerial(local->fd);
490 RemoveEnabledDevice (local->fd);
495 * If something went wrong, cleanup and return NULL
498 if ((local) && (local->fd))
499 xf86CloseSerial (local->fd);
500 if ((priv) && (priv->buffer))
501 XisbFree (priv->buffer);
505 local->private = NULL;
507 xf86DeleteInput(local, 0);
512 DeviceControl (DeviceIntPtr dev, int mode)
523 RetValue = DeviceOn(dev);
526 RetValue = DeviceOff(dev);
529 RetValue = DeviceClose(dev);
539 DeviceOn (DeviceIntPtr dev)
542 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
543 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
545 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
547 local->fd = xf86OpenSerial(local->options);
550 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
551 priv->flags &= ~AVAIL_FLAG;
553 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
554 local->fd = xf86OpenSerial(local->options);
559 priv->flags |= AVAIL_FLAG;
562 if (!(priv->flags & USB_FLAG)) {
563 priv->buffer = XisbNew(local->fd, 200);
566 xf86CloseSerial(local->fd);
571 /* Rets qu'a l'envoyer a la tablette */
572 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
573 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
576 xf86FlushInput(local->fd);
577 xf86AddEnabledDevice (local);
578 dev->public.on = TRUE;
583 DeviceOff (DeviceIntPtr dev)
585 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
586 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
588 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
592 RemoveEnabledDevice (local->fd);
595 XisbFree(priv->buffer);
598 xf86CloseSerial(local->fd);
602 xf86RemoveEnabledDevice (local);
603 dev->public.on = FALSE;
608 DeviceClose (DeviceIntPtr dev)
610 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
612 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
618 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
620 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
622 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
626 DeviceInit (DeviceIntPtr dev)
629 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
630 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
631 unsigned char map[] =
634 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
637 if (InitButtonClassDeviceStruct (dev, 3, map) == FALSE)
639 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
643 if (InitFocusClassDeviceStruct (dev) == FALSE)
645 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
649 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
650 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
656 if (InitValuatorClassDeviceStruct (dev, 3, xf86GetMotionEvents,
658 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
661 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
667 InitValuatorAxisStruct(dev,
670 #if XORG_VERSION_CURRENT == XORG_VERSION_BOTCHED
671 screenInfo.screens[0]->width,
673 priv->acecadMaxX, /* max val */
675 1000, /* resolution */
678 InitValuatorAxisStruct(dev,
681 #if XORG_VERSION_CURRENT == XORG_VERSION_BOTCHED
682 screenInfo.screens[0]->height,
684 priv->acecadMaxY, /* max val */
686 1000, /* resolution */
689 InitValuatorAxisStruct(dev,
692 priv->acecadMaxZ, /* max val */
693 1000, /* resolution */
699 if (InitProximityClassDeviceStruct (dev) == FALSE)
701 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
705 xf86MotionHistoryAllocate (local);
708 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
709 connaitre la taille... */
711 if (priv->acecadInc > 95)
712 priv->acecadInc = 95;
713 if (priv->acecadInc < 1)
715 /* guess the best increment value given video mode */
716 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
717 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
719 priv->acecadInc = rx;
721 priv->acecadInc = ry;
722 if (priv->acecadInc < 1)
726 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
732 ReadInput (LocalDevicePtr local)
736 int is_core_pointer = 1, is_absolute;
737 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
739 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
741 is_absolute = (priv->flags & ABSOLUTE_FLAG);
742 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
743 is_core_pointer = xf86IsCorePointer(local->dev);
747 * set blocking to -1 on the first call because we know there is data to
748 * read. Xisb automatically clears it after one successful read so that
749 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
750 * read from blocking indefinately.
752 XisbBlockDuration (priv->buffer, -1);
754 while (AceCadGetPacket (priv) == Success)
756 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
757 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
759 if (!(priv->flags & ABSOLUTE_FLAG))
761 x = priv->packet[0] & XSIGN_BIT? x:-x;
762 y = priv->packet[0] & YSIGN_BIT? y:-y;
766 y = priv->acecadMaxY - y ;
770 z = ((int)priv->packet[5] << 2) |
771 (((int)priv->packet[6] & 0x01) << 1) |
772 (((int)priv->packet[6] & 0x10) >> 4);
774 buttons = ((int)priv->packet[0] & 0x07) |
775 ((int)priv->packet[6] & 0x02 << 2);
777 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
781 if (!(priv->acecadOldProximity))
782 if (!is_core_pointer)
784 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
785 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
788 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
789 || (!is_absolute && (x || y)))
791 if (is_absolute || priv->acecadOldProximity)
793 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
794 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
798 if (priv->acecadOldButtons != buttons)
800 int delta = buttons ^ priv->acecadOldButtons;
804 delta &= ~(1 << (id-1));
806 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
807 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
811 priv->acecadOldButtons = buttons;
812 priv->acecadOldX = x;
813 priv->acecadOldY = y;
814 priv->acecadOldZ = z;
815 priv->acecadOldProximity = prox;
819 if (!is_core_pointer)
820 if (priv->acecadOldProximity)
822 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
823 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
825 priv->acecadOldProximity = 0;
828 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
832 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
834 USBReadInput (LocalDevicePtr local)
837 struct input_event * event;
838 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
839 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
840 int x = priv->acecadOldX;
841 int y = priv->acecadOldY;
842 int z = priv->acecadOldZ;
843 int report_x, report_y;
844 int prox = priv->acecadOldProximity;
845 int buttons = priv->acecadOldButtons;
846 int is_core_pointer = 1;
847 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
848 is_core_pointer = xf86IsCorePointer(local->dev);
850 /* Is autodev active? */
851 int autodev = priv->flags & AUTODEV_FLAG;
852 /* Was the device available last time we checked? */
853 int avail = priv->flags & AVAIL_FLAG;
855 SYSCALL(len = read(local->fd, eventbuf, sizeof(eventbuf)));
859 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
862 priv->flags &= ~AVAIL_FLAG;
864 if (AceCadAutoDevProbe(local, 4)) {
865 DeviceOff(local->dev);
866 DeviceOn(local->dev);
873 /* If the device wasn't available last time we checked */
874 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
875 priv->flags |= AVAIL_FLAG;
879 for (event = (struct input_event *)eventbuf;
880 event < (struct input_event *)(eventbuf+len); event++) {
882 switch (event->type) {
883 case EV_SYN: /* 2.6.x */
884 if (event->code != SYN_REPORT)
885 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
888 switch (event->code) {
908 switch (event->code) {
914 buttons = set_bit(buttons,0,event->value);
918 buttons = set_bit(buttons,1,event->value);
922 buttons = set_bit(buttons,2,event->value);
927 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
928 } /* switch event->type */
930 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
931 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
933 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
934 (event->type == EV_ABS && event->code == ABS_MISC)
941 #if XORG_VERSION_CURRENT == XORG_VERSION_BOTCHED
942 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
947 if (!(priv->acecadOldProximity))
948 if (!is_core_pointer)
950 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
954 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
956 if (priv->acecadOldButtons != buttons)
958 int delta = buttons ^ priv->acecadOldButtons;
962 delta &= ~(1 << (id-1));
964 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
970 if (!is_core_pointer)
971 if (priv->acecadOldProximity)
973 xf86PostProximityEvent(local->dev, 0, 0, 3, report_x, report_y, z);
975 priv->acecadOldProximity = 0;
978 priv->acecadOldButtons = buttons;
979 priv->acecadOldX = x;
980 priv->acecadOldY = y;
981 priv->acecadOldZ = z;
982 priv->acecadOldProximity = prox;
984 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
989 CloseProc (LocalDevicePtr local)
994 * The ConvertProc function may need to be tailored for your device.
995 * This function converts the device's valuator outputs to x and y coordinates
996 * to simulate mouse events.
999 ConvertProc (LocalDevicePtr local, int first, int num,
1000 int v0, int v1, int v2, int v3, int v4, int v5,
1003 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1005 /* TODO: should have a structure to hold which screen the
1006 * pointer is attached to? */
1007 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
1008 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
1009 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
1010 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
1016 ReverseConvertProc (LocalDevicePtr local,
1020 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1022 // xf86Msg(X_INFO, "%s: reverse coordinate conversion in : %d, %d\n", local->name, x, y);
1023 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
1024 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
1025 // xf86Msg(X_INFO, "%s: reverse coordinate conversion out: %d, %d\n", local->name, valuators[0], valuators[1]);
1031 #define WriteString(str)\
1032 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1036 QueryHardware (AceCadPrivatePtr priv)
1045 /* Prompt Mode in order to not be disturbed */
1046 WriteString(ACECAD_PROMPT_MODE);
1049 while (XisbRead(priv->buffer) >= 0);
1051 /* Ask for Config packet*/
1052 WriteString(ACECAD_CONFIG);
1054 /* Read the packet */
1055 XisbBlockDuration (priv->buffer, 1000000);
1058 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1060 if ((AceCadGetPacket (priv) == Success))
1062 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1063 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1064 priv->acecadMaxZ = 512;
1065 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1070 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1074 #define BITS_PER_LONG (sizeof(long) * 8)
1075 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1076 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1077 #define OFF(x) ((x)%BITS_PER_LONG)
1078 #define LONG(x) ((x)/BITS_PER_LONG)
1082 USBQueryHardware (LocalDevicePtr local)
1084 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1085 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1088 char name[256] = "Unknown";
1090 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1091 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1093 memset(bit, 0, sizeof(bit));
1094 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1096 for (i = 0; i < EV_MAX; i++)
1097 if (test_bit(i, bit[0])) {
1098 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1099 for (j = 0; j < KEY_MAX; j++)
1100 if (test_bit(j, bit[i])) {
1102 ioctl(local->fd, EVIOCGABS(j), abs);
1105 priv->acecadMaxX = abs[2];
1109 priv->acecadMaxY = abs[2];
1113 priv->acecadMaxZ = abs[2];
1120 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1126 NewPacket (AceCadPrivatePtr priv)
1132 AceCadGetPacket (AceCadPrivatePtr priv)
1137 while((c = XisbRead(priv->buffer)) >= 0 )
1141 * fail after 500 bytes so the server doesn't hang forever if a
1142 * device sends bad data.
1150 if (c & PHASING_BIT)
1154 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1155 XisbBlockDuration (priv->buffer, 10000);
1156 priv->packet[priv->packeti++] = c;
1157 count = ACECAD_PACKET_SIZE - 1;
1158 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1160 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1161 priv->packet[priv->packeti++] = c;
1163 XisbBlockDuration (priv->buffer, 0);