HID: samples/hidraw: make it possible to select device
authorPavel Machek <pavel@ucw.cz>
Sat, 14 Mar 2015 20:57:22 +0000 (21:57 +0100)
committerJiri Kosina <jkosina@suse.cz>
Sun, 15 Mar 2015 14:11:21 +0000 (10:11 -0400)
Makefile that can actually build the example, and allow selecting device to
work on.

Signed-off-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
samples/hidraw/Makefile
samples/hidraw/hid-example.c

index 382eeae77bd6437f30b2478a349a259e0434b444..a9ab96188fbe011ec3d3337d9dbd936023d0a3ec 100644 (file)
@@ -8,3 +8,5 @@ hostprogs-y := hid-example
 always := $(hostprogs-y)
 
 HOSTCFLAGS_hid-example.o += -I$(objtree)/usr/include
+
+all: hid-example
index 512a7e50bcae19dd3d7dc40edb3741198f0512ac..92e6c1511910d06547a59859827d2b6b0800589e 100644 (file)
@@ -46,10 +46,14 @@ int main(int argc, char **argv)
        char buf[256];
        struct hidraw_report_descriptor rpt_desc;
        struct hidraw_devinfo info;
+       char *device = "/dev/hidraw0";
+
+       if (argc > 1)
+               device = argv[1];
 
        /* Open the Device with non-blocking reads. In real life,
           don't use a hard coded path; use libudev instead. */
-       fd = open("/dev/hidraw0", O_RDWR|O_NONBLOCK);
+       fd = open(device, O_RDWR|O_NONBLOCK);
 
        if (fd < 0) {
                perror("Unable to open device");