2 * Copyright (c) 2001 Edouard TISSERANT <tissered@esstin.u-nancy.fr>
3 * Parts inspired from Shane Watts <shane@bofh.asn.au> XFree86 3 Acecad Driver
4 * Thanks to Emily, from AceCad, For giving me documents.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <xorgVersion.h>
30 #define XORG_VERSION_BOTCHED XORG_VERSION_NUMERIC(1,4,0,0,0)
31 #if XORG_VERSION_CURRENT >= XORG_VERSION_BOTCHED
32 #define XORG_BOTCHED_INPUT 1
34 #define XORG_BOTCHED_INPUT 0
37 /*****************************************************************************
39 ****************************************************************************/
42 #include <asm/types.h>
43 #include <linux/input.h>
58 #ifndef NEED_XF86_TYPES
59 #define NEED_XF86_TYPES
61 #include <xf86_OSproc.h>
63 #include <xf86Xinput.h>
65 #include <xf86Module.h>
74 #include <sysfs/libsysfs.h>
79 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
80 #include <X11/Xatom.h>
81 #include <xserver-properties.h>
84 /* Previously found in xf86Xinput.h */
88 #define DBG(lvl, f) {if ((lvl) <= xf86GetVerbosity()) f;}
90 /*****************************************************************************
92 ****************************************************************************/
95 /*****************************************************************************
96 * Variables without includable headers
97 ****************************************************************************/
99 /*****************************************************************************
101 ****************************************************************************/
104 #define read(a,b,c) xf86ReadSerial((a),(b),(c))
106 /* max number of input events to read in one read call */
107 #define MAX_EVENTS 50
109 _X_EXPORT InputDriverRec ACECAD =
120 static XF86ModuleVersionInfo VersionRec =
126 XORG_VERSION_CURRENT,
127 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
135 _X_EXPORT XF86ModuleData acecadModuleData = {
141 /*****************************************************************************
142 * Function Definitions
143 ****************************************************************************/
146 SetupProc( pointer module,
151 xf86AddInputDriver(&ACECAD, module, 0);
156 TearDownProc( pointer p )
159 LocalDevicePtr local = (LocalDevicePtr) p;
160 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
162 DeviceOff (local->dev);
164 xf86CloseSerial (local->fd);
165 XisbFree (priv->buffer);
172 static const char *default_options[] =
180 "FlowControl", "Xoff",
191 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
194 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
195 version >> 16, (version >> 8) & 0xff, version & 0xff);
198 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
203 /* Heavily inspired by synaptics/eventcomm.c */
205 #define DEV_INPUT_EVENT "/dev/input/event"
206 #define EV_DEV_NAME_MAXLEN 64
207 #define SET_EVENT_NUM(str, num) \
208 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
211 fd_query_acecad(int fd, char *ace_name) {
212 char name[256] = "Unknown";
213 int cmp_at = strlen(ace_name);
216 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
218 if (xf86NameCmp(name, ace_name) == 0)
223 static char ace_name_default[7] = "acecad";
226 static char usb_bus_name[4] = "usb";
227 static char acecad_driver_name[11] = "usb_acecad";
231 AceCadAutoDevProbe(LocalDevicePtr local, int verb)
233 /* We are trying to find the right eventX device */
235 Bool have_evdev = FALSE;
237 const int max_skip = 10;
238 char *ace_name = xf86FindOptionValue(local->options, "Name");
239 char fname[EV_DEV_NAME_MAXLEN];
243 struct sysfs_bus *usb_bus = NULL;
244 struct sysfs_driver *acecad_driver = NULL;
245 struct sysfs_device *candidate = NULL;
247 struct dlist *devs = NULL;
248 struct dlist *links = NULL;
250 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
251 usb_bus = sysfs_open_bus(usb_bus_name);
253 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
254 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
256 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
257 devs = sysfs_get_driver_devices(acecad_driver);
259 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
260 dlist_for_each_data(devs, candidate, struct sysfs_device) {
261 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
262 links = sysfs_open_link_list(candidate->path);
263 dlist_for_each_data(links, link, char) {
264 if (sscanf(link, "input:event%d", &i) == 1) {
265 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
269 sysfs_close_list(links);
270 if (i > 0) /* We found something */
274 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
276 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
278 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
279 sysfs_close_bus(usb_bus);
282 /* We found something */
283 np = SET_EVENT_NUM(fname, i);
284 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
285 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
290 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\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[] = {0, 1, 2, 3};
632 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
636 btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
637 btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
638 btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
640 if ((priv->flags & ABSOLUTE_FLAG))
642 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
643 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
644 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
647 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
648 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
649 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Z);
653 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
656 if (InitButtonClassDeviceStruct (dev, 3,
657 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
662 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
666 if (InitFocusClassDeviceStruct (dev) == FALSE)
668 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
672 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
673 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
679 if (InitValuatorClassDeviceStruct (dev, 3,
680 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
683 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
687 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
690 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
696 InitValuatorAxisStruct(dev,
698 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
702 #if XORG_BOTCHED_INPUT
703 screenInfo.screens[0]->width,
705 priv->acecadMaxX, /* max val */
707 1000, /* resolution */
710 InitValuatorAxisStruct(dev,
712 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
716 #if XORG_BOTCHED_INPUT
717 screenInfo.screens[0]->height,
719 priv->acecadMaxY, /* max val */
721 1000, /* resolution */
724 InitValuatorAxisStruct(dev,
726 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
730 priv->acecadMaxZ, /* max val */
731 1000, /* resolution */
737 if (InitProximityClassDeviceStruct (dev) == FALSE)
739 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
743 xf86MotionHistoryAllocate (local);
746 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
747 connaitre la taille... */
749 if (priv->acecadInc > 95)
750 priv->acecadInc = 95;
751 if (priv->acecadInc < 1)
753 /* guess the best increment value given video mode */
754 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
755 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
757 priv->acecadInc = rx;
759 priv->acecadInc = ry;
760 if (priv->acecadInc < 1)
764 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
770 ReadInput (LocalDevicePtr local)
774 int is_core_pointer = 0, is_absolute;
775 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
777 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
779 is_absolute = (priv->flags & ABSOLUTE_FLAG);
780 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
781 is_core_pointer = xf86IsCorePointer(local->dev);
785 * set blocking to -1 on the first call because we know there is data to
786 * read. Xisb automatically clears it after one successful read so that
787 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
788 * read from blocking indefinately.
790 XisbBlockDuration (priv->buffer, -1);
792 while (AceCadGetPacket (priv) == Success)
794 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
795 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
797 if (!(priv->flags & ABSOLUTE_FLAG))
799 x = priv->packet[0] & XSIGN_BIT? x:-x;
800 y = priv->packet[0] & YSIGN_BIT? y:-y;
804 y = priv->acecadMaxY - y ;
808 z = ((int)priv->packet[5] << 2) |
809 (((int)priv->packet[6] & 0x01) << 1) |
810 (((int)priv->packet[6] & 0x10) >> 4);
812 buttons = ((int)priv->packet[0] & 0x07) |
813 ((int)priv->packet[6] & 0x02 << 2);
815 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
819 if (!(priv->acecadOldProximity))
820 if (!is_core_pointer)
822 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
823 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
826 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
827 || (!is_absolute && (x || y)))
829 if (is_absolute || priv->acecadOldProximity)
831 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
832 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
836 if (priv->acecadOldButtons != buttons)
838 int delta = buttons ^ priv->acecadOldButtons;
842 delta &= ~(1 << (id-1));
844 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
845 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
849 priv->acecadOldButtons = buttons;
850 priv->acecadOldX = x;
851 priv->acecadOldY = y;
852 priv->acecadOldZ = z;
853 priv->acecadOldProximity = prox;
857 if (!is_core_pointer)
858 if (priv->acecadOldProximity)
860 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
861 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
863 priv->acecadOldProximity = 0;
866 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
870 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
872 USBReadInput (LocalDevicePtr local)
875 struct input_event * event;
876 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
877 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
878 int x = priv->acecadOldX;
879 int y = priv->acecadOldY;
880 int z = priv->acecadOldZ;
881 int report_x, report_y;
882 int prox = priv->acecadOldProximity;
883 int buttons = priv->acecadOldButtons;
884 int is_core_pointer = 0;
885 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
886 is_core_pointer = xf86IsCorePointer(local->dev);
888 /* Is autodev active? */
889 int autodev = priv->flags & AUTODEV_FLAG;
890 /* Was the device available last time we checked? */
891 int avail = priv->flags & AVAIL_FLAG;
893 SYSCALL(len = read(local->fd, eventbuf, sizeof(eventbuf)));
897 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
900 priv->flags &= ~AVAIL_FLAG;
902 if (AceCadAutoDevProbe(local, 4)) {
903 DeviceOff(local->dev);
904 DeviceOn(local->dev);
911 /* If the device wasn't available last time we checked */
912 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
913 priv->flags |= AVAIL_FLAG;
917 for (event = (struct input_event *)eventbuf;
918 event < (struct input_event *)(eventbuf+len); event++) {
920 switch (event->type) {
921 case EV_SYN: /* 2.6.x */
922 if (event->code != SYN_REPORT)
923 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
926 switch (event->code) {
946 switch (event->code) {
952 buttons = set_bit(buttons,0,event->value);
956 buttons = set_bit(buttons,1,event->value);
960 buttons = set_bit(buttons,2,event->value);
965 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
966 } /* switch event->type */
968 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
969 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
971 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
972 (event->type == EV_ABS && event->code == ABS_MISC)
979 #if XORG_BOTCHED_INPUT
980 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
985 if (!(priv->acecadOldProximity))
986 if (!is_core_pointer)
988 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
992 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
994 if (priv->acecadOldButtons != buttons)
996 int delta = buttons ^ priv->acecadOldButtons;
1000 delta &= ~(1 << (id-1));
1002 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
1008 if (!is_core_pointer)
1009 if (priv->acecadOldProximity)
1011 xf86PostProximityEvent(local->dev, 0, 0, 3, report_x, report_y, z);
1013 priv->acecadOldProximity = 0;
1016 priv->acecadOldButtons = buttons;
1017 priv->acecadOldX = x;
1018 priv->acecadOldY = y;
1019 priv->acecadOldZ = z;
1020 priv->acecadOldProximity = prox;
1022 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
1027 CloseProc (LocalDevicePtr local)
1032 * The ConvertProc function may need to be tailored for your device.
1033 * This function converts the device's valuator outputs to x and y coordinates
1034 * to simulate mouse events.
1037 ConvertProc (LocalDevicePtr local, int first, int num,
1038 int v0, int v1, int v2, int v3, int v4, int v5,
1041 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1043 /* TODO: should have a structure to hold which screen the
1044 * pointer is attached to? */
1045 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
1046 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
1047 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
1048 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
1054 ReverseConvertProc (LocalDevicePtr local,
1058 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1060 // xf86Msg(X_INFO, "%s: reverse coordinate conversion in : %d, %d\n", local->name, x, y);
1061 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
1062 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
1063 // xf86Msg(X_INFO, "%s: reverse coordinate conversion out: %d, %d\n", local->name, valuators[0], valuators[1]);
1069 #define WriteString(str)\
1070 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1074 QueryHardware (AceCadPrivatePtr priv)
1083 /* Prompt Mode in order to not be disturbed */
1084 WriteString(ACECAD_PROMPT_MODE);
1087 while (XisbRead(priv->buffer) >= 0);
1089 /* Ask for Config packet*/
1090 WriteString(ACECAD_CONFIG);
1092 /* Read the packet */
1093 XisbBlockDuration (priv->buffer, 1000000);
1096 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1098 if ((AceCadGetPacket (priv) == Success))
1100 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1101 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1102 priv->acecadMaxZ = 512;
1103 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1108 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1112 #define BITS_PER_LONG (sizeof(long) * 8)
1113 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1114 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1115 #define OFF(x) ((x)%BITS_PER_LONG)
1116 #define LONG(x) ((x)/BITS_PER_LONG)
1120 USBQueryHardware (LocalDevicePtr local)
1122 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1123 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1126 char name[256] = "Unknown";
1128 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1129 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1131 memset(bit, 0, sizeof(bit));
1132 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1134 for (i = 0; i < EV_MAX; i++)
1135 if (test_bit(i, bit[0])) {
1136 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1137 for (j = 0; j < KEY_MAX; j++)
1138 if (test_bit(j, bit[i])) {
1140 ioctl(local->fd, EVIOCGABS(j), abs);
1143 priv->acecadMaxX = abs[2];
1147 priv->acecadMaxY = abs[2];
1151 priv->acecadMaxZ = abs[2];
1158 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1164 NewPacket (AceCadPrivatePtr priv)
1170 AceCadGetPacket (AceCadPrivatePtr priv)
1175 while((c = XisbRead(priv->buffer)) >= 0 )
1179 * fail after 500 bytes so the server doesn't hang forever if a
1180 * device sends bad data.
1188 if (c & PHASING_BIT)
1192 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1193 XisbBlockDuration (priv->buffer, 10000);
1194 priv->packet[priv->packeti++] = c;
1195 count = ACECAD_PACKET_SIZE - 1;
1196 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1198 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1199 priv->packet[priv->packeti++] = c;
1201 XisbBlockDuration (priv->buffer, 0);