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
31 #include <xorg-server.h>
32 #include <xorgVersion.h>
33 #define XORG_VERSION_BOTCHED XORG_VERSION_NUMERIC(1,4,0,0,0)
34 #if XORG_VERSION_CURRENT >= XORG_VERSION_BOTCHED
35 #define XORG_BOTCHED_INPUT 1
37 #define XORG_BOTCHED_INPUT 0
40 /*****************************************************************************
42 ****************************************************************************/
44 #ifdef HAVE_LINUX_INPUT_H
45 #include <asm/types.h>
46 #include <linux/input.h>
61 #ifndef NEED_XF86_TYPES
62 #define NEED_XF86_TYPES
64 #include <xf86_OSproc.h>
66 #include <xf86Xinput.h>
68 #include <xf86Module.h>
74 #ifdef HAVE_LINUX_INPUT_H
76 #ifdef HAVE_SYSFS_LIBSYSFS_H
77 #include <sysfs/libsysfs.h>
82 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
83 #include <X11/Xatom.h>
84 #include <xserver-properties.h>
87 /* Previously found in xf86Xinput.h */
91 #define DBG(lvl, f) {if ((lvl) <= xf86GetVerbosity()) f;}
93 /*****************************************************************************
95 ****************************************************************************/
98 /*****************************************************************************
99 * Variables without includable headers
100 ****************************************************************************/
102 /*****************************************************************************
104 ****************************************************************************/
106 /* max number of input events to read in one read call */
107 #define MAX_EVENTS 50
109 static char *default_options[] =
117 "FlowControl", "Xoff",
121 _X_EXPORT InputDriverRec ACECAD =
129 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
134 static XF86ModuleVersionInfo VersionRec =
140 XORG_VERSION_CURRENT,
141 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
149 _X_EXPORT XF86ModuleData acecadModuleData = {
155 /*****************************************************************************
156 * Function Definitions
157 ****************************************************************************/
160 SetupProc( pointer module,
165 xf86AddInputDriver(&ACECAD, module, 0);
170 TearDownProc( pointer p )
174 #ifdef HAVE_LINUX_INPUT_H
181 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
184 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
185 version >> 16, (version >> 8) & 0xff, version & 0xff);
188 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
193 /* Heavily inspired by synaptics/eventcomm.c */
195 #define DEV_INPUT_EVENT "/dev/input/event"
196 #define EV_DEV_NAME_MAXLEN 64
197 #define SET_EVENT_NUM(str, num) \
198 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
201 fd_query_acecad(int fd, char *ace_name) {
202 char name[256] = "Unknown";
203 int cmp_at = strlen(ace_name);
206 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
208 if (xf86NameCmp(name, ace_name) == 0)
213 static char ace_name_default[7] = "acecad";
215 #ifdef HAVE_SYSFS_LIBSYSFS_H
216 static char usb_bus_name[4] = "usb";
217 static char acecad_driver_name[11] = "usb_acecad";
221 AceCadAutoDevProbe(InputInfoPtr local, int verb)
223 /* We are trying to find the right eventX device */
225 Bool have_evdev = FALSE;
227 const int max_skip = 10;
228 char *ace_name = xf86FindOptionValue(local->options, "Name");
229 char fname[EV_DEV_NAME_MAXLEN];
232 #ifdef HAVE_SYSFS_LIBSYSFS_H
233 struct sysfs_bus *usb_bus = NULL;
234 struct sysfs_driver *acecad_driver = NULL;
235 struct sysfs_device *candidate = NULL;
237 struct dlist *devs = NULL;
238 struct dlist *links = NULL;
240 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
241 usb_bus = sysfs_open_bus(usb_bus_name);
243 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
244 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
246 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
247 devs = sysfs_get_driver_devices(acecad_driver);
249 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
250 dlist_for_each_data(devs, candidate, struct sysfs_device) {
251 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
252 links = sysfs_open_link_list(candidate->path);
253 dlist_for_each_data(links, link, char) {
254 if (sscanf(link, "input:event%d", &i) == 1) {
255 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
259 sysfs_close_list(links);
260 if (i > 0) /* We found something */
264 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
266 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
268 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
269 sysfs_close_bus(usb_bus);
272 /* We found something */
273 np = SET_EVENT_NUM(fname, i);
274 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
275 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
280 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
285 ace_name = ace_name_default;
287 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
292 np = SET_EVENT_NUM(fname, i);
293 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
294 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
297 SYSCALL(fd = open(fname, O_RDONLY));
299 if (errno == ENOENT) {
300 if (++noent_cnt >= max_skip)
310 is_acecad = fd_query_acecad(fd, ace_name);
316 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
317 local->name, i + 1, ace_name);
319 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
321 if (i > max_skip && !have_evdev)
322 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
326 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
328 xf86ReplaceStrOption(local->options, "Device", fname);
334 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
335 static int NewAceCadPreInit(InputDriverPtr drv, InputInfoPtr dev, int flags);
338 AceCadPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
340 InputInfoPtr local = xf86AllocateInput(drv, 0);
341 AceCadPrivatePtr priv = calloc (1, sizeof(AceCadPrivateRec));
346 local->name = dev->identifier;
347 local->type_name = XI_TABLET;
348 local->flags = XI86_SEND_DRAG_EVENTS;
349 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
350 local->motion_history_proc = xf86GetMotionEvents;
352 local->control_proc = NULL;
353 local->switch_mode = NULL;
354 local->conversion_proc = ConvertProc;
355 local->reverse_conversion_proc = ReverseConvertProc;
357 local->private = priv;
358 local->private_flags = 0;
359 local->conf_idev = dev;
360 /*local->always_core_feedback = 0;*/
362 xf86CollectInputOptions(local, default_options, NULL);
364 xf86OptionListReport(local->options);
366 if (NewAceCadPreInit(drv, local, flags) == Success)
374 ReverseConvertProc (InputInfoPtr local,
378 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
380 // xf86Msg(X_INFO, "%s: reverse coordinate conversion in : %d, %d\n", local->name, x, y);
381 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
382 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
383 // xf86Msg(X_INFO, "%s: reverse coordinate conversion out: %d, %d\n", local->name, valuators[0], valuators[1]);
389 NewAceCadPreInit(InputDriverPtr drv, InputInfoPtr local, int flags)
392 AceCadPreInit(InputDriverPtr drv, InputInfoPtr local, int flags)
395 AceCadPrivatePtr priv = calloc (1, sizeof(AceCadPrivateRec));
403 memset(priv, 0, sizeof(AceCadPrivateRec));
405 local->device_control = DeviceControl;
407 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
409 s = xf86FindOptionValue(local->options, "Device");
410 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
411 #ifdef HAVE_LINUX_INPUT_H
412 priv->flags |= AUTODEV_FLAG;
413 if (!AceCadAutoDevProbe(local, 0))
415 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
419 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
424 local->fd = xf86OpenSerial (local->options);
427 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
430 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
432 #ifdef HAVE_LINUX_INPUT_H
433 if (IsUSBLine(local->fd)) {
434 priv->flags |= USB_FLAG;
436 local->read_input = USBReadInput;
438 if (USBQueryHardware(local) != Success)
440 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
446 local->read_input = ReadInput;
449 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
451 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
459 priv->acecadReportSpeed = 'Q';
462 priv->acecadReportSpeed = 'R';
465 priv->acecadReportSpeed = 'S';
468 priv->acecadReportSpeed = 'T';
471 priv->acecadReportSpeed = 'R';
473 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
477 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
479 priv->buffer = XisbNew (local->fd, 200);
482 * Verify that hardware is attached and fuctional
484 if (QueryHardware(priv) != Success)
486 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
491 s = xf86FindOptionValue(local->options, "Mode");
492 msgtype = s ? X_CONFIG : X_DEFAULT;
493 if (!(s && (xf86NameCmp(s, "relative") == 0)))
495 priv->flags |= ABSOLUTE_FLAG;
498 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
499 DBG (9, XisbTrace (priv->buffer, 1));
501 xf86ProcessCommonOptions(local, local->options);
503 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
504 local->flags |= XI86_CONFIGURED;
509 RemoveEnabledDevice (local->fd);
512 XisbFree(priv->buffer);
515 xf86CloseSerial(local->fd);
517 RemoveEnabledDevice (local->fd);
522 * If something went wrong, cleanup and return NULL
525 if ((local) && (local->fd))
526 xf86CloseSerial (local->fd);
527 if ((priv) && (priv->buffer))
528 XisbFree (priv->buffer);
532 local->private = NULL;
534 xf86DeleteInput(local, 0);
539 DeviceControl (DeviceIntPtr dev, int mode)
550 RetValue = DeviceOn(dev);
553 RetValue = DeviceOff(dev);
556 RetValue = DeviceClose(dev);
566 DeviceOn (DeviceIntPtr dev)
569 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
570 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
572 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
574 local->fd = xf86OpenSerial(local->options);
577 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
578 priv->flags &= ~AVAIL_FLAG;
579 #ifdef HAVE_LINUX_INPUT_H
580 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
581 local->fd = xf86OpenSerial(local->options);
586 priv->flags |= AVAIL_FLAG;
589 if (!(priv->flags & USB_FLAG)) {
590 priv->buffer = XisbNew(local->fd, 200);
593 xf86CloseSerial(local->fd);
598 /* Rets qu'a l'envoyer a la tablette */
599 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
600 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
603 xf86FlushInput(local->fd);
604 xf86AddEnabledDevice (local);
605 dev->public.on = TRUE;
610 DeviceOff (DeviceIntPtr dev)
612 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
613 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
615 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
619 RemoveEnabledDevice (local->fd);
622 XisbFree(priv->buffer);
625 xf86CloseSerial(local->fd);
629 xf86RemoveEnabledDevice (local);
630 dev->public.on = FALSE;
635 DeviceClose (DeviceIntPtr dev)
637 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
639 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
645 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
647 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
649 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
653 DeviceInit (DeviceIntPtr dev)
656 InputInfoPtr local = (InputInfoPtr) dev->public.devicePrivate;
657 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
658 unsigned char map[] = {0, 1, 2, 3};
660 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
664 btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
665 btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
666 btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
668 if ((priv->flags & ABSOLUTE_FLAG))
670 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
671 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
672 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
675 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
676 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
677 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Z);
681 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
684 if (InitButtonClassDeviceStruct (dev, 3,
685 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
690 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
694 if (InitFocusClassDeviceStruct (dev) == FALSE)
696 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
700 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
701 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
705 history_size = xf86SetIntOption(local->options , "HistorySize", 0);
708 if (InitValuatorClassDeviceStruct (dev, 3,
709 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
712 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
716 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
719 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
725 InitValuatorAxisStruct(dev,
727 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
731 #if XORG_BOTCHED_INPUT
732 screenInfo.screens[0]->width,
734 priv->acecadMaxX, /* max val */
736 1000, /* resolution */
739 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
743 InitValuatorAxisStruct(dev,
745 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
749 #if XORG_BOTCHED_INPUT
750 screenInfo.screens[0]->height,
752 priv->acecadMaxY, /* max val */
754 1000, /* resolution */
757 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
761 InitValuatorAxisStruct(dev,
763 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
767 priv->acecadMaxZ, /* max val */
768 1000, /* resolution */
771 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
778 if (InitProximityClassDeviceStruct (dev) == FALSE)
780 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
784 xf86MotionHistoryAllocate (local);
787 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
788 connaitre la taille... */
790 if (priv->acecadInc > 95)
791 priv->acecadInc = 95;
792 if (priv->acecadInc < 1)
794 /* guess the best increment value given video mode */
795 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
796 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
798 priv->acecadInc = rx;
800 priv->acecadInc = ry;
801 if (priv->acecadInc < 1)
805 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
811 ReadInput (InputInfoPtr local)
815 int is_core_pointer = 0, is_absolute;
816 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
818 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
820 is_absolute = (priv->flags & ABSOLUTE_FLAG);
821 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
822 is_core_pointer = xf86IsCorePointer(local->dev);
826 * set blocking to -1 on the first call because we know there is data to
827 * read. Xisb automatically clears it after one successful read so that
828 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
829 * read from blocking indefinately.
831 XisbBlockDuration (priv->buffer, -1);
833 while (AceCadGetPacket (priv) == Success)
835 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
836 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
838 if (!(priv->flags & ABSOLUTE_FLAG))
840 x = priv->packet[0] & XSIGN_BIT? x:-x;
841 y = priv->packet[0] & YSIGN_BIT? y:-y;
845 y = priv->acecadMaxY - y ;
849 z = ((int)priv->packet[5] << 2) |
850 (((int)priv->packet[6] & 0x01) << 1) |
851 (((int)priv->packet[6] & 0x10) >> 4);
853 buttons = ((int)priv->packet[0] & 0x07) |
854 ((int)priv->packet[6] & 0x02 << 2);
856 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
860 if (!(priv->acecadOldProximity))
861 if (!is_core_pointer)
863 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
864 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
867 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
868 || (!is_absolute && (x || y)))
870 if (is_absolute || priv->acecadOldProximity)
872 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
873 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
877 if (priv->acecadOldButtons != buttons)
879 int delta = buttons ^ priv->acecadOldButtons;
883 delta &= ~(1 << (id-1));
885 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
886 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
890 priv->acecadOldButtons = buttons;
891 priv->acecadOldX = x;
892 priv->acecadOldY = y;
893 priv->acecadOldZ = z;
894 priv->acecadOldProximity = prox;
898 if (!is_core_pointer)
899 if (priv->acecadOldProximity)
901 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
902 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
904 priv->acecadOldProximity = 0;
907 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
910 #ifdef HAVE_LINUX_INPUT_H
911 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
913 USBReadInput (InputInfoPtr local)
916 struct input_event * event;
917 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
918 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
919 int x = priv->acecadOldX;
920 int y = priv->acecadOldY;
921 int z = priv->acecadOldZ;
922 int report_x = 0, report_y = 0;
923 int prox = priv->acecadOldProximity;
924 int buttons = priv->acecadOldButtons;
925 int is_core_pointer = 0;
926 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
927 is_core_pointer = xf86IsCorePointer(local->dev);
929 /* Is autodev active? */
930 int autodev = priv->flags & AUTODEV_FLAG;
931 /* Was the device available last time we checked? */
932 int avail = priv->flags & AVAIL_FLAG;
934 SYSCALL(len = xf86ReadSerial(local->fd, eventbuf, sizeof(eventbuf)));
938 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
941 priv->flags &= ~AVAIL_FLAG;
943 if (AceCadAutoDevProbe(local, 4)) {
944 DeviceOff(local->dev);
945 DeviceOn(local->dev);
952 /* If the device wasn't available last time we checked */
953 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
954 priv->flags |= AVAIL_FLAG;
958 for (event = (struct input_event *)eventbuf;
959 event < (struct input_event *)(eventbuf+len); event++) {
961 switch (event->type) {
962 case EV_SYN: /* 2.6.x */
963 if (event->code != SYN_REPORT)
964 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
967 switch (event->code) {
987 switch (event->code) {
993 buttons = set_bit(buttons,0,event->value);
997 buttons = set_bit(buttons,1,event->value);
1001 buttons = set_bit(buttons,2,event->value);
1006 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
1007 } /* switch event->type */
1009 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
1010 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
1012 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
1013 (event->type == EV_ABS && event->code == ABS_MISC)
1020 #if XORG_BOTCHED_INPUT
1021 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
1026 if (!(priv->acecadOldProximity))
1027 if (!is_core_pointer)
1029 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
1033 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
1035 if (priv->acecadOldButtons != buttons)
1037 int delta = buttons ^ priv->acecadOldButtons;
1040 int id = ffs(delta);
1041 delta &= ~(1 << (id-1));
1043 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
1049 if (!is_core_pointer)
1050 if (priv->acecadOldProximity)
1052 xf86PostProximityEvent(local->dev, 0, 0, 3, report_x, report_y, z);
1054 priv->acecadOldProximity = 0;
1057 priv->acecadOldButtons = buttons;
1058 priv->acecadOldX = x;
1059 priv->acecadOldY = y;
1060 priv->acecadOldZ = z;
1061 priv->acecadOldProximity = prox;
1063 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
1068 * The ConvertProc function may need to be tailored for your device.
1069 * This function converts the device's valuator outputs to x and y coordinates
1070 * to simulate mouse events.
1073 ConvertProc (InputInfoPtr local, int first, int num,
1074 int v0, int v1, int v2, int v3, int v4, int v5,
1077 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1079 /* TODO: should have a structure to hold which screen the
1080 * pointer is attached to? */
1081 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
1082 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
1083 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
1084 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
1089 #define WriteString(str)\
1090 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1094 QueryHardware (AceCadPrivatePtr priv)
1103 /* Prompt Mode in order to not be disturbed */
1104 WriteString(ACECAD_PROMPT_MODE);
1107 while (XisbRead(priv->buffer) >= 0);
1109 /* Ask for Config packet*/
1110 WriteString(ACECAD_CONFIG);
1112 /* Read the packet */
1113 XisbBlockDuration (priv->buffer, 1000000);
1116 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1118 if ((AceCadGetPacket (priv) == Success))
1120 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1121 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1122 priv->acecadMaxZ = 512;
1123 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1128 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1132 #define BITS_PER_LONG (sizeof(long) * 8)
1133 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1134 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1135 #define OFF(x) ((x)%BITS_PER_LONG)
1136 #define LONG(x) ((x)/BITS_PER_LONG)
1138 #ifdef HAVE_LINUX_INPUT_H
1140 USBQueryHardware (InputInfoPtr local)
1142 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1143 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1146 char name[256] = "Unknown";
1148 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1149 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1151 memset(bit, 0, sizeof(bit));
1152 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1154 for (i = 0; i < EV_MAX; i++)
1155 if (test_bit(i, bit[0])) {
1156 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1157 for (j = 0; j < KEY_MAX; j++)
1158 if (test_bit(j, bit[i])) {
1160 ioctl(local->fd, EVIOCGABS(j), abs);
1163 priv->acecadMaxX = abs[2];
1167 priv->acecadMaxY = abs[2];
1171 priv->acecadMaxZ = abs[2];
1178 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1184 NewPacket (AceCadPrivatePtr priv)
1190 AceCadGetPacket (AceCadPrivatePtr priv)
1195 while((c = XisbRead(priv->buffer)) >= 0 )
1199 * fail after 500 bytes so the server doesn't hang forever if a
1200 * device sends bad data.
1208 if (c & PHASING_BIT)
1212 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1213 XisbBlockDuration (priv->buffer, 10000);
1214 priv->packet[priv->packeti++] = c;
1215 count = ACECAD_PACKET_SIZE - 1;
1216 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1218 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1219 priv->packet[priv->packeti++] = c;
1221 XisbBlockDuration (priv->buffer, 0);