[PATCH 1/3] Initial support for device autodetection.

Giuseppe Bilotta giuseppe.bilotta at gmail.com
Tue Apr 24 18:15:57 PDT 2007


When the "Device" option is missing or set to "auto-dev" the acecad module will now try all /dev/input/eventX nodes until one is found that reports a device name that begins with "ACECAD".
---
 src/acecad.c |   77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/src/acecad.c b/src/acecad.c
index c10aaf4..94b49aa 100644
--- a/src/acecad.c
+++ b/src/acecad.c
@@ -65,6 +65,7 @@
 
 #ifdef LINUX_INPUT
 #include <errno.h>
+#include <fcntl.h>
 #endif
 
 /*****************************************************************************
@@ -181,6 +182,69 @@ IsUSBLine(int fd)
 	return 0;
     }
 }
+
+static Bool
+fd_query_acecad(int fd) {
+	char name[256] = "Unknown";
+	char ace_name[7] = "ACECAD\0";
+	ioctl(fd, EVIOCGNAME(sizeof(name)), name);
+	name[6] = '\0';
+	if (xf86NameCmp(name, ace_name) == 0)
+		return TRUE;
+	return FALSE;
+}
+
+/* Shamelessly copied from synpatics/eventcomm.c */
+#define DEV_INPUT_EVENT "/dev/input"
+#define EVENT_DEV_NAME "event"
+
+static Bool
+AceCadAutoDevProbe(LocalDevicePtr local)
+{
+    /* We are trying to find the right eventX device */
+    int i;
+    Bool have_evdev = FALSE;
+    int noent_cnt = 0;
+    const int max_skip = 10;
+
+    for (i = 0; ; i++) {
+	char fname[64];
+	int fd = -1;
+	Bool is_acecad;
+
+	sprintf(fname, "%s/%s%d", DEV_INPUT_EVENT, EVENT_DEV_NAME, i);
+	SYSCALL(fd = open(fname, O_RDONLY));
+	if (fd < 0) {
+	    if (errno == ENOENT) {
+		if (++noent_cnt >= max_skip)
+		    break;
+		else
+		    continue;
+	    } else {
+		continue;
+	    }
+	}
+	noent_cnt = 0;
+	have_evdev = TRUE;
+	is_acecad = fd_query_acecad(fd);
+	SYSCALL(close(fd));
+	if (is_acecad) {
+	    xf86Msg(X_PROBED, "%s auto-dev sets device to %s\n",
+		    local->name, fname);
+	    xf86ReplaceStrOption(local->options, "Device", fname);
+	    return TRUE;
+	}
+    }
+    ErrorF("%s no acecad event device found (checked %d nodes)\n",
+	   local->name, i + 1);
+    if (i <= max_skip)
+	ErrorF("%s The /dev/input/event* device nodes seem to be missing\n",
+	       local->name);
+    if (i > max_skip && !have_evdev)
+	ErrorF("%s The evdev kernel module seems to be missing\n", local->name);
+    return FALSE;
+}
+
 #endif
 
 static InputInfoPtr
@@ -219,6 +283,19 @@ AceCadPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
 
 	priv->acecadInc = xf86SetIntOption(local->options, "Increment", 0 );
 
+#ifdef LINUX_INPUT
+	s = xf86FindOptionValue(local->options, "Device");
+	msgtype = s ? X_CONFIG : X_PROBED;
+	if (!s || (s && (xf86NameCmp(s, "auto-dev") == 0))) {
+		if (!AceCadAutoDevProbe(local))
+		{
+			xf86Msg(X_ERROR, "AceCad driver unable to find device\n");
+			goto SetupProc_fail;
+		}
+
+	}
+#endif
+
 	local->fd = xf86OpenSerial (local->options);
 	if (local->fd == -1)
 	{
-- 
1.5.1.2




More information about the xorg mailing list