OSDN Git Service

auto-detect event id for touchscreen
authorChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 15 Jan 2010 10:33:44 +0000 (18:33 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 15 Jan 2010 10:36:48 +0000 (18:36 +0800)
Currently it only works for input-raw, but may be extended
to other plugins.

plugins/input-raw.c
tests/fbutils.c
tests/fbutils.h
tests/ts_calibrate.c

index c38ffab..d58d8e4 100644 (file)
@@ -341,6 +341,7 @@ TSAPI struct tslib_module_info *mod_init(struct tsdev *dev, const char *params)
                return NULL;
 
        i->module.ops = &__ts_input_ops;
+       i->module.dev = dev;
        i->current_x = 0;
        i->current_y = 0;
        i->current_p = 0;
@@ -348,7 +349,7 @@ TSAPI struct tslib_module_info *mod_init(struct tsdev *dev, const char *params)
        i->using_syn = 0;
        i->grab_events = 0;
 
-       if (tslib_parse_vars(&i->module, raw_vars, NR_VARS, params)) {
+       if (check_fd(i) || tslib_parse_vars(&i->module, raw_vars, NR_VARS, params)) {
                free(i);
                return NULL;
        }
index b7067aa..0b01e64 100644 (file)
@@ -51,6 +51,20 @@ static char *defaultconsoledevice = "/dev/tty";
 static char *fbdevice = NULL;
 static char *consoledevice = NULL;
 
+struct tsdev *open_touchdev(const char *dev)
+{
+       struct tsdev *ts = ts_open(dev, 0);
+       if (!ts) {
+               perror("ts_open");
+               return NULL;
+       }
+       if (ts_config(ts)) {
+               ts_close(ts);
+               return NULL;
+       }
+       return ts;
+}
+
 int open_framebuffer(void)
 {
        struct vt_stat vts;
index 48890f7..3d612c9 100644 (file)
@@ -23,6 +23,7 @@
 
 extern __u32 xres, yres;
 
+struct tsdev *open_touchdev(const char *dev);
 int open_framebuffer(void);
 void close_framebuffer(void);
 void setcolor(unsigned colidx, unsigned value);
index fa29fa7..8e26ad7 100644 (file)
@@ -207,19 +207,23 @@ int main()
        tset = ts_setting(TS_ENV);
 
        if( (tsdevice = getenv("TSLIB_TSDEVICE")) != NULL ) {
-               ts = ts_open(tsdevice,0);
+               ts = open_touchdev(tsdevice);
        } else if (tset != NULL) {
-               ts = ts_open(tset->tsdev, 0);
-       } else {
-               if (!(ts = ts_open("/dev/input/event0", 0)))
-                       ts = ts_open("/dev/touchscreen/ucb1x00", 0);
+               ts = open_touchdev(tset->tsdev);
        }
-
        if (!ts) {
-               perror("ts_open");
-               exit(1);
+               char tsdevice[20];
+               /* CW: a lazy way to go through all events.. is 99 enough? */
+               for (i = 0; i <= 99; ++i) {
+                       sprintf(tsdevice, "/dev/input/event%d", i);
+                       if ((ts = open_touchdev(tsdevice)))
+                               break;
+               }
+               if (!ts)
+                       ts = open_touchdev("/dev/touchscreen/ucb1x00");
        }
-       if (ts_config(ts)) {
+
+       if (!ts) {
                perror("ts_config");
                exit(1);
        }