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 ****************************************************************************/
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>
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 _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 )
160 static const char *default_options[] =
168 "FlowControl", "Xoff",
179 SYSCALL(err = ioctl(fd, EVIOCGVERSION, &version));
182 xf86MsgVerb(X_PROBED, 4, "Kernel Input driver version is %d.%d.%d\n",
183 version >> 16, (version >> 8) & 0xff, version & 0xff);
186 xf86MsgVerb(X_PROBED, 4, "No Kernel Input driver found\n");
191 /* Heavily inspired by synaptics/eventcomm.c */
193 #define DEV_INPUT_EVENT "/dev/input/event"
194 #define EV_DEV_NAME_MAXLEN 64
195 #define SET_EVENT_NUM(str, num) \
196 snprintf(str, EV_DEV_NAME_MAXLEN, "%s%d", DEV_INPUT_EVENT, num)
199 fd_query_acecad(int fd, char *ace_name) {
200 char name[256] = "Unknown";
201 int cmp_at = strlen(ace_name);
204 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
206 if (xf86NameCmp(name, ace_name) == 0)
211 static char ace_name_default[7] = "acecad";
214 static char usb_bus_name[4] = "usb";
215 static char acecad_driver_name[11] = "usb_acecad";
219 AceCadAutoDevProbe(LocalDevicePtr local, int verb)
221 /* We are trying to find the right eventX device */
223 Bool have_evdev = FALSE;
225 const int max_skip = 10;
226 char *ace_name = xf86FindOptionValue(local->options, "Name");
227 char fname[EV_DEV_NAME_MAXLEN];
231 struct sysfs_bus *usb_bus = NULL;
232 struct sysfs_driver *acecad_driver = NULL;
233 struct sysfs_device *candidate = NULL;
235 struct dlist *devs = NULL;
236 struct dlist *links = NULL;
238 xf86MsgVerb(X_INFO, verb, "%s: querying sysfs for Acecad tablets\n", local->name);
239 usb_bus = sysfs_open_bus(usb_bus_name);
241 xf86MsgVerb(X_PROBED, 4, "%s: usb bus opened\n", local->name);
242 acecad_driver = sysfs_get_bus_driver(usb_bus, acecad_driver_name);
244 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad driver opened\n", local->name);
245 devs = sysfs_get_driver_devices(acecad_driver);
247 xf86MsgVerb(X_PROBED, 4, "%s: usb_acecad devices retrieved\n", local->name);
248 dlist_for_each_data(devs, candidate, struct sysfs_device) {
249 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s\n", local->name, candidate->name, candidate->path);
250 links = sysfs_open_link_list(candidate->path);
251 dlist_for_each_data(links, link, char) {
252 if (sscanf(link, "input:event%d", &i) == 1) {
253 xf86MsgVerb(X_PROBED, 4, "%s: device %s at %s: %s\n", local->name, candidate->name, candidate->path, link);
257 sysfs_close_list(links);
258 if (i > 0) /* We found something */
262 xf86MsgVerb(X_WARNING, 4, "%s: no usb_acecad devices found\n", local->name);
264 xf86MsgVerb(X_WARNING, 4, "%s: usb_acecad driver not found\n", local->name);
266 xf86MsgVerb(X_WARNING, 4, "%s: usb bus not found\n", local->name);
267 sysfs_close_bus(usb_bus);
270 /* We found something */
271 np = SET_EVENT_NUM(fname, i);
272 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
273 xf86MsgVerb(X_WARNING, verb, "%s: unable to manage event device %d\n", local->name, i);
278 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad devices found via sysfs\n", local->name);
283 ace_name = ace_name_default;
285 xf86MsgVerb(X_INFO, verb, "%s: probing event devices for Acecad tablets\n", local->name);
290 np = SET_EVENT_NUM(fname, i);
291 if (np < 0 || np >= EV_DEV_NAME_MAXLEN) {
292 xf86MsgVerb(X_WARNING, verb, "%s: too many devices, giving up %d\n", local->name, i);
295 SYSCALL(fd = open(fname, O_RDONLY));
297 if (errno == ENOENT) {
298 if (++noent_cnt >= max_skip)
308 is_acecad = fd_query_acecad(fd, ace_name);
314 xf86MsgVerb(X_WARNING, verb, "%s: no Acecad event device found (checked %d nodes, no device name started with '%s')\n",
315 local->name, i + 1, ace_name);
317 xf86MsgVerb(X_WARNING, verb, "%s: The /dev/input/event* device nodes seem to be missing\n",
319 if (i > max_skip && !have_evdev)
320 xf86MsgVerb(X_WARNING, verb, "%s: The evdev kernel module seems to be missing\n", local->name);
324 xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
326 xf86ReplaceStrOption(local->options, "Device", fname);
333 AceCadPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
335 LocalDevicePtr local = xf86AllocateInput(drv, 0);
336 AceCadPrivatePtr priv = xcalloc (1, sizeof(AceCadPrivateRec));
341 if ((!local) || (!priv))
344 memset(priv, 0, sizeof(AceCadPrivateRec));
346 local->name = dev->identifier;
347 local->type_name = XI_TABLET;
348 local->flags = XI86_POINTER_CAPABLE | 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->close_proc = CloseProc;
354 local->switch_mode = NULL;
355 local->conversion_proc = ConvertProc;
356 local->reverse_conversion_proc = ReverseConvertProc;
358 local->private = priv;
359 local->private_flags = 0;
360 local->conf_idev = dev;
361 local->device_control = DeviceControl;
362 /*local->always_core_feedback = 0;*/
364 xf86CollectInputOptions(local, default_options, NULL);
366 xf86OptionListReport(local->options);
368 priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
370 s = xf86FindOptionValue(local->options, "Device");
371 if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
373 priv->flags |= AUTODEV_FLAG;
374 if (!AceCadAutoDevProbe(local, 0))
376 xf86Msg(X_ERROR, "%s: unable to find device\n", local->name);
380 xf86Msg(X_NOT_IMPLEMENTED, "%s: device autodetection not implemented, sorry\n", local->name);
385 local->fd = xf86OpenSerial (local->options);
388 xf86Msg(X_ERROR, "%s: unable to open device\n", local->name);
391 xf86ErrorFVerb( 6, "tty port opened successfully\n" );
394 if (IsUSBLine(local->fd)) {
395 priv->flags |= USB_FLAG;
397 local->read_input = USBReadInput;
399 if (USBQueryHardware(local) != Success)
401 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
407 local->read_input = ReadInput;
410 if (xf86FindOptionValue(local->options, "ReportSpeed")) {
412 speed = xf86SetIntOption(local->options, "ReportSpeed", 85 );
420 priv->acecadReportSpeed = 'Q';
423 priv->acecadReportSpeed = 'R';
426 priv->acecadReportSpeed = 'S';
429 priv->acecadReportSpeed = 'T';
432 priv->acecadReportSpeed = 'R';
434 xf86Msg(X_ERROR, "%s: ReportSpeed value %d invalid. Possible values: 120, 85, 10, 2. Defaulting to 85\n", local->name, speed);
438 xf86Msg(msgtype, "%s report %d points/s\n", local->name, speed);
440 priv->buffer = XisbNew (local->fd, 200);
443 * Verify that hardware is attached and fuctional
445 if (QueryHardware(priv) != Success)
447 xf86Msg(X_ERROR, "%s: unable to query/initialize hardware (not an %s?).\n", local->name, local->type_name);
452 s = xf86FindOptionValue(local->options, "Mode");
453 msgtype = s ? X_CONFIG : X_DEFAULT;
454 if (!(s && (xf86NameCmp(s, "relative") == 0)))
456 priv->flags |= ABSOLUTE_FLAG;
459 xf86Msg(msgtype, "%s is in %s mode\n", local->name, (priv->flags & ABSOLUTE_FLAG) ? "absolute" : "relative");
460 DBG (9, XisbTrace (priv->buffer, 1));
462 local->history_size = xf86SetIntOption(local->options , "HistorySize", 0);
464 xf86ProcessCommonOptions(local, local->options);
466 local->flags |= XI86_CONFIGURED;
470 RemoveEnabledDevice (local->fd);
473 XisbFree(priv->buffer);
476 xf86CloseSerial(local->fd);
478 RemoveEnabledDevice (local->fd);
483 * If something went wrong, cleanup and return NULL
486 if ((local) && (local->fd))
487 xf86CloseSerial (local->fd);
488 if ((priv) && (priv->buffer))
489 XisbFree (priv->buffer);
493 local->private = NULL;
495 xf86DeleteInput(local, 0);
500 DeviceControl (DeviceIntPtr dev, int mode)
511 RetValue = DeviceOn(dev);
514 RetValue = DeviceOff(dev);
517 RetValue = DeviceClose(dev);
527 DeviceOn (DeviceIntPtr dev)
530 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
531 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
533 xf86MsgVerb(X_INFO, 4, "%s Device On\n", local->name);
535 local->fd = xf86OpenSerial(local->options);
538 xf86Msg(X_WARNING, "%s: cannot open input device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
539 priv->flags &= ~AVAIL_FLAG;
541 if ((priv->flags & AUTODEV_FLAG) && AceCadAutoDevProbe(local, 4))
542 local->fd = xf86OpenSerial(local->options);
547 priv->flags |= AVAIL_FLAG;
550 if (!(priv->flags & USB_FLAG)) {
551 priv->buffer = XisbNew(local->fd, 200);
554 xf86CloseSerial(local->fd);
559 /* Rets qu'a l'envoyer a la tablette */
560 sprintf(buffer, "%s%c%c%c%c", acecad_initstr, priv->acecadReportSpeed, ACECAD_INCREMENT, 32 + priv->acecadInc, (priv->flags & ABSOLUTE_FLAG)? ACECAD_ABSOLUTE: ACECAD_RELATIVE);
561 XisbWrite (priv->buffer, (unsigned char *)buffer, strlen(buffer));
564 xf86FlushInput(local->fd);
565 xf86AddEnabledDevice (local);
566 dev->public.on = TRUE;
571 DeviceOff (DeviceIntPtr dev)
573 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
574 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
576 xf86MsgVerb(X_INFO, 4, "%s Device Off\n", local->name);
580 RemoveEnabledDevice (local->fd);
583 XisbFree(priv->buffer);
586 xf86CloseSerial(local->fd);
590 xf86RemoveEnabledDevice (local);
591 dev->public.on = FALSE;
596 DeviceClose (DeviceIntPtr dev)
598 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
600 xf86MsgVerb(X_INFO, 4, "%s Device Close\n", local->name);
606 ControlProc(DeviceIntPtr dev, PtrCtrl *ctrl)
608 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
610 xf86MsgVerb(X_INFO, 4, "%s Control Proc\n", local->name);
614 DeviceInit (DeviceIntPtr dev)
617 LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
618 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
619 unsigned char map[] = {0, 1, 2, 3};
620 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
624 btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
625 btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
626 btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
628 if ((priv->flags & ABSOLUTE_FLAG))
630 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
631 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
632 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
635 axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
636 axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
637 axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Z);
641 xf86MsgVerb(X_INFO, 4, "%s Init\n", local->name);
644 if (InitButtonClassDeviceStruct (dev, 3,
645 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
650 xf86Msg(X_ERROR, "%s: unable to allocate ButtonClassDeviceStruct\n", local->name);
654 if (InitFocusClassDeviceStruct (dev) == FALSE)
656 xf86Msg(X_ERROR, "%s: unable to allocate FocusClassDeviceStruct\n", local->name);
660 if (InitPtrFeedbackClassDeviceStruct(dev, ControlProc) == FALSE) {
661 xf86Msg(X_ERROR, "%s: unable to init ptr feedback\n", local->name);
667 if (InitValuatorClassDeviceStruct (dev, 3,
668 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
671 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
675 ((priv->flags & ABSOLUTE_FLAG)? Absolute: Relative)|OutOfProximity)
678 xf86Msg(X_ERROR, "%s: unable to allocate ValuatorClassDeviceStruct\n", local->name);
684 InitValuatorAxisStruct(dev,
686 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
690 #if XORG_BOTCHED_INPUT
691 screenInfo.screens[0]->width,
693 priv->acecadMaxX, /* max val */
695 1000, /* resolution */
698 InitValuatorAxisStruct(dev,
700 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
704 #if XORG_BOTCHED_INPUT
705 screenInfo.screens[0]->height,
707 priv->acecadMaxY, /* max val */
709 1000, /* resolution */
712 InitValuatorAxisStruct(dev,
714 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
718 priv->acecadMaxZ, /* max val */
719 1000, /* resolution */
725 if (InitProximityClassDeviceStruct (dev) == FALSE)
727 xf86Msg(X_ERROR, "%s: unable to allocate ProximityClassDeviceStruct\n", local->name);
731 xf86MotionHistoryAllocate (local);
734 /* On ne peut pas calculer l'increment avant, faute d'ecran pour
735 connaitre la taille... */
737 if (priv->acecadInc > 95)
738 priv->acecadInc = 95;
739 if (priv->acecadInc < 1)
741 /* guess the best increment value given video mode */
742 rx = priv->acecadMaxX / screenInfo.screens[0]->width;
743 ry = priv->acecadMaxY / screenInfo.screens[0]->height;
745 priv->acecadInc = rx;
747 priv->acecadInc = ry;
748 if (priv->acecadInc < 1)
752 xf86Msg(X_INFO, "%s Increment: %d\n", local->name, priv->acecadInc);
758 ReadInput (LocalDevicePtr local)
762 int is_core_pointer = 0, is_absolute;
763 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
765 /*xf86Msg(X_INFO, "ACECAD Tablet Read Input\n");*/
767 is_absolute = (priv->flags & ABSOLUTE_FLAG);
768 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
769 is_core_pointer = xf86IsCorePointer(local->dev);
773 * set blocking to -1 on the first call because we know there is data to
774 * read. Xisb automatically clears it after one successful read so that
775 * succeeding reads are preceeded buy a select with a 0 timeout to prevent
776 * read from blocking indefinately.
778 XisbBlockDuration (priv->buffer, -1);
780 while (AceCadGetPacket (priv) == Success)
782 x = (int)priv->packet[1] | ((int)priv->packet[2] << 7);
783 y = (int)priv->packet[3] | ((int)priv->packet[4] << 7);
785 if (!(priv->flags & ABSOLUTE_FLAG))
787 x = priv->packet[0] & XSIGN_BIT? x:-x;
788 y = priv->packet[0] & YSIGN_BIT? y:-y;
792 y = priv->acecadMaxY - y ;
796 z = ((int)priv->packet[5] << 2) |
797 (((int)priv->packet[6] & 0x01) << 1) |
798 (((int)priv->packet[6] & 0x10) >> 4);
800 buttons = ((int)priv->packet[0] & 0x07) |
801 ((int)priv->packet[6] & 0x02 << 2);
803 prox = (priv->packet[0] & PROXIMITY_BIT)? 0: 1;
807 if (!(priv->acecadOldProximity))
808 if (!is_core_pointer)
810 /*xf86Msg(X_INFO, "ACECAD Tablet ProxIN %d %d %d\n",x, y, z);*/
811 xf86PostProximityEvent(local->dev, 1, 0, 3 , x, y, z);
814 if ((is_absolute && ((priv->acecadOldX != x) || (priv->acecadOldY != y) || (priv->acecadOldZ != z)))
815 || (!is_absolute && (x || y)))
817 if (is_absolute || priv->acecadOldProximity)
819 /*xf86Msg(X_INFO, "ACECAD Tablet Motion %d %d %d\n", x, y, z);*/
820 xf86PostMotionEvent(local->dev, is_absolute, 0, 3, x, y, z);
824 if (priv->acecadOldButtons != buttons)
826 int delta = buttons ^ priv->acecadOldButtons;
830 delta &= ~(1 << (id-1));
832 /*xf86Msg(X_INFO, "ACECAD Tablet Button %d 0x%x\n",id,(buttons&(1<<(id-1))));*/
833 xf86PostButtonEvent(local->dev, is_absolute, id, (buttons&(1<<(id-1))), 0, 3, x, y,z);
837 priv->acecadOldButtons = buttons;
838 priv->acecadOldX = x;
839 priv->acecadOldY = y;
840 priv->acecadOldZ = z;
841 priv->acecadOldProximity = prox;
845 if (!is_core_pointer)
846 if (priv->acecadOldProximity)
848 /*xf86Msg(X_INFO, "ACECAD Tablet ProxOUT %d %d %d\n",x, y, z);*/
849 xf86PostProximityEvent(local->dev, 0, 0, 3, x,y,z);
851 priv->acecadOldProximity = 0;
854 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
858 #define set_bit(byte,nb,bit) (bit ? byte | (1<<nb) : byte & (~(1<<nb)))
860 USBReadInput (LocalDevicePtr local)
863 struct input_event * event;
864 char eventbuf[sizeof(struct input_event) * MAX_EVENTS];
865 AceCadPrivatePtr priv = (AceCadPrivatePtr) (local->private);
866 int x = priv->acecadOldX;
867 int y = priv->acecadOldY;
868 int z = priv->acecadOldZ;
869 int report_x, report_y;
870 int prox = priv->acecadOldProximity;
871 int buttons = priv->acecadOldButtons;
872 int is_core_pointer = 0;
873 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
874 is_core_pointer = xf86IsCorePointer(local->dev);
876 /* Is autodev active? */
877 int autodev = priv->flags & AUTODEV_FLAG;
878 /* Was the device available last time we checked? */
879 int avail = priv->flags & AVAIL_FLAG;
881 SYSCALL(len = xf86ReadSerial(local->fd, eventbuf, sizeof(eventbuf)));
885 xf86Msg(X_ERROR, "%s: error reading device %s: %s\n", local->name, xf86FindOptionValue(local->options, "Device"), strerror(errno));
888 priv->flags &= ~AVAIL_FLAG;
890 if (AceCadAutoDevProbe(local, 4)) {
891 DeviceOff(local->dev);
892 DeviceOn(local->dev);
899 /* If the device wasn't available last time we checked */
900 xf86Msg(X_INFO, "%s: device %s is available again\n", local->name, xf86FindOptionValue(local->options, "Device"));
901 priv->flags |= AVAIL_FLAG;
905 for (event = (struct input_event *)eventbuf;
906 event < (struct input_event *)(eventbuf+len); event++) {
908 switch (event->type) {
909 case EV_SYN: /* 2.6.x */
910 if (event->code != SYN_REPORT)
911 xf86Msg(X_ERROR, "%s: unknown EV_SYN code %d\n", local->name, event->code);
914 switch (event->code) {
934 switch (event->code) {
940 buttons = set_bit(buttons,0,event->value);
944 buttons = set_bit(buttons,1,event->value);
948 buttons = set_bit(buttons,2,event->value);
953 xf86Msg(X_ERROR, "%s: unknown event type/code %d/%d\n", local->name, event->type, event->code);
954 } /* switch event->type */
956 /* Linux Kernel 2.6.x sends EV_SYN/SYN_REPORT as an event terminator,
957 * whereas 2.4.x sends EV_ABS/ABS_MISC. We have to support both.
959 if (!( (event->type == EV_SYN && event->code == SYN_REPORT) ||
960 (event->type == EV_ABS && event->code == ABS_MISC)
967 #if XORG_BOTCHED_INPUT
968 ConvertProc(local, 0, 3, x, y, 0, 0, 0, 0, &report_x, &report_y);
973 if (!(priv->acecadOldProximity))
974 if (!is_core_pointer)
976 xf86PostProximityEvent(local->dev, 1, 0, 3 , report_x, report_y, z);
980 xf86PostMotionEvent(local->dev, 1, 0, 3, report_x, report_y, z);
982 if (priv->acecadOldButtons != buttons)
984 int delta = buttons ^ priv->acecadOldButtons;
988 delta &= ~(1 << (id-1));
990 xf86PostButtonEvent(local->dev, 1, id, (buttons&(1<<(id-1))), 0, 3, report_x, report_y, z);
996 if (!is_core_pointer)
997 if (priv->acecadOldProximity)
999 xf86PostProximityEvent(local->dev, 0, 0, 3, report_x, report_y, z);
1001 priv->acecadOldProximity = 0;
1004 priv->acecadOldButtons = buttons;
1005 priv->acecadOldX = x;
1006 priv->acecadOldY = y;
1007 priv->acecadOldZ = z;
1008 priv->acecadOldProximity = prox;
1010 /*xf86Msg(X_INFO, "ACECAD Tablet Sortie Read Input\n");*/
1015 CloseProc (LocalDevicePtr local)
1020 * The ConvertProc function may need to be tailored for your device.
1021 * This function converts the device's valuator outputs to x and y coordinates
1022 * to simulate mouse events.
1025 ConvertProc (LocalDevicePtr local, int first, int num,
1026 int v0, int v1, int v2, int v3, int v4, int v5,
1029 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1031 /* TODO: should have a structure to hold which screen the
1032 * pointer is attached to? */
1033 // xf86Msg(X_INFO, "%s: coordinate conversion in : %d, %d\n", local->name, v0, v1);
1034 *x = v0 * screenInfo.screens[0]->width / priv->acecadMaxX;
1035 *y = v1 * screenInfo.screens[0]->height / priv->acecadMaxY;
1036 // xf86Msg(X_INFO, "%s: coordinate conversion out: %d, %d\n", local->name, *x, *y);
1042 ReverseConvertProc (LocalDevicePtr local,
1046 AceCadPrivatePtr priv = (AceCadPrivatePtr)(local->private);
1048 // xf86Msg(X_INFO, "%s: reverse coordinate conversion in : %d, %d\n", local->name, x, y);
1049 valuators[0] = x * priv->acecadMaxX / screenInfo.screens[0]->width;
1050 valuators[1] = y * priv->acecadMaxY / screenInfo.screens[0]->height;
1051 // xf86Msg(X_INFO, "%s: reverse coordinate conversion out: %d, %d\n", local->name, valuators[0], valuators[1]);
1057 #define WriteString(str)\
1058 XisbWrite (priv->buffer, (unsigned char *)(str), strlen(str))
1062 QueryHardware (AceCadPrivatePtr priv)
1071 /* Prompt Mode in order to not be disturbed */
1072 WriteString(ACECAD_PROMPT_MODE);
1075 while (XisbRead(priv->buffer) >= 0);
1077 /* Ask for Config packet*/
1078 WriteString(ACECAD_CONFIG);
1080 /* Read the packet */
1081 XisbBlockDuration (priv->buffer, 1000000);
1084 /*xf86Msg(X_CONFIG, "ACECAD Tablet init envoyé \n");*/
1086 if ((AceCadGetPacket (priv) == Success))
1088 priv->acecadMaxX = (int)priv->packet[1] + ((int)priv->packet[2] << 7);
1089 priv->acecadMaxY = (int)priv->packet[3] + ((int)priv->packet[4] << 7);
1090 priv->acecadMaxZ = 512;
1091 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d\n", priv->acecadMaxX, priv->acecadMaxY);
1096 /*xf86Msg(X_INFO, "ACECAD Tablet query hardware fini \n");*/
1100 #define BITS_PER_LONG (sizeof(long) * 8)
1101 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
1102 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
1103 #define OFF(x) ((x)%BITS_PER_LONG)
1104 #define LONG(x) ((x)/BITS_PER_LONG)
1108 USBQueryHardware (LocalDevicePtr local)
1110 AceCadPrivatePtr priv = (AceCadPrivatePtr) local->private;
1111 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
1114 char name[256] = "Unknown";
1116 ioctl(local->fd, EVIOCGNAME(sizeof(name)), name);
1117 xf86MsgVerb(X_PROBED, 4, "Kernel Input device name: \"%s\"\n", name);
1119 memset(bit, 0, sizeof(bit));
1120 ioctl(local->fd, EVIOCGBIT(0, EV_MAX), bit[0]);
1122 for (i = 0; i < EV_MAX; i++)
1123 if (test_bit(i, bit[0])) {
1124 ioctl(local->fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
1125 for (j = 0; j < KEY_MAX; j++)
1126 if (test_bit(j, bit[i])) {
1128 ioctl(local->fd, EVIOCGABS(j), abs);
1131 priv->acecadMaxX = abs[2];
1135 priv->acecadMaxY = abs[2];
1139 priv->acecadMaxZ = abs[2];
1146 xf86Msg(X_PROBED, "ACECAD Tablet MaxX:%d MaxY:%d MaxZ:%d\n", priv->acecadMaxX, priv->acecadMaxY, priv->acecadMaxZ);
1152 NewPacket (AceCadPrivatePtr priv)
1158 AceCadGetPacket (AceCadPrivatePtr priv)
1163 while((c = XisbRead(priv->buffer)) >= 0 )
1167 * fail after 500 bytes so the server doesn't hang forever if a
1168 * device sends bad data.
1176 if (c & PHASING_BIT)
1180 /*xf86Msg(X_CONFIG, "Push %2.2x\n",(char) c);*/
1181 XisbBlockDuration (priv->buffer, 10000);
1182 priv->packet[priv->packeti++] = c;
1183 count = ACECAD_PACKET_SIZE - 1;
1184 while (count-- && (c = XisbRead(priv->buffer)) >= 0)
1186 /*xf86Msg(X_INFO, "Push %2.2x\n",(char) c);*/
1187 priv->packet[priv->packeti++] = c;
1189 XisbBlockDuration (priv->buffer, 0);