Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin Update for libusbhid(3) changes.



details:   https://anonhg.NetBSD.org/src/rev/8486696959fe
branches:  trunk
changeset: 519841:8486696959fe
user:      augustss <augustss%NetBSD.org@localhost>
date:      Fri Dec 28 17:49:31 2001 +0000

description:
Update for libusbhid(3) changes.

diffstat:

 usr.bin/usbhidaction/Makefile       |   4 +-
 usr.bin/usbhidaction/usbhidaction.1 |   4 +-
 usr.bin/usbhidaction/usbhidaction.c |  15 +++--
 usr.bin/usbhidctl/Makefile          |   4 +-
 usr.bin/usbhidctl/usbhid.c          |  92 +++++++++++++++++++++---------------
 usr.bin/usbhidctl/usbhidctl.1       |   4 +-
 6 files changed, 70 insertions(+), 53 deletions(-)

diffs (truncated from 336 to 300 lines):

diff -r 13a093b75fb9 -r 8486696959fe usr.bin/usbhidaction/Makefile
--- a/usr.bin/usbhidaction/Makefile     Fri Dec 28 17:45:25 2001 +0000
+++ b/usr.bin/usbhidaction/Makefile     Fri Dec 28 17:49:31 2001 +0000
@@ -1,11 +1,11 @@
-#      $NetBSD: Makefile,v 1.1 2000/12/30 13:07:48 augustss Exp $
+#      $NetBSD: Makefile,v 1.2 2001/12/28 17:49:31 augustss Exp $
 
 .include <bsd.own.mk>
 
 PROG=  usbhidaction
 SRCS=  usbhidaction.c
 
-LDADD+=        -lusb -lutil
+LDADD+=        -lusbhid -lutil
 DPADD+=        ${LIBUSB} ${LIBUTIL}
 
 .include <bsd.prog.mk>
diff -r 13a093b75fb9 -r 8486696959fe usr.bin/usbhidaction/usbhidaction.1
--- a/usr.bin/usbhidaction/usbhidaction.1       Fri Dec 28 17:45:25 2001 +0000
+++ b/usr.bin/usbhidaction/usbhidaction.1       Fri Dec 28 17:49:31 2001 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: usbhidaction.1,v 1.4 2001/12/09 22:53:30 augustss Exp $
+.\" $NetBSD: usbhidaction.1,v 1.5 2001/12/28 17:49:31 augustss Exp $
 .\"
 .\" Copyright (c) 2000 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -124,7 +124,7 @@
 .Ed
 .Sh SEE ALSO
 .Xr usbhidctl 1 ,
-.Xr usb 3 ,
+.Xr usbhid 3 ,
 .Xr uhid 4 ,
 .Xr usb 4
 .Sh HISTORY
diff -r 13a093b75fb9 -r 8486696959fe usr.bin/usbhidaction/usbhidaction.c
--- a/usr.bin/usbhidaction/usbhidaction.c       Fri Dec 28 17:45:25 2001 +0000
+++ b/usr.bin/usbhidaction/usbhidaction.c       Fri Dec 28 17:49:31 2001 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: usbhidaction.c,v 1.3 2001/02/20 23:55:42 cgd Exp $ */
+/*      $NetBSD: usbhidaction.c,v 1.4 2001/12/28 17:49:31 augustss Exp $ */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
 #include <sys/ioctl.h>
 #include <dev/usb/usb.h>
 #include <dev/usb/usbhid.h>
-#include <usb.h>
+#include <usbhid.h>
 #include <util.h>
 
 int verbose = 0;
@@ -67,7 +67,7 @@
 #define SIZE 4000
 
 void usage(void);
-void parse_conf(const char *conf, report_desc_t repd, int ignore);
+void parse_conf(const char *conf, report_desc_t repd, int reportid, int ignore);
 void docmd(struct command *cmd, int value, const char *hid,
           int argc, char **argv);
 
@@ -81,6 +81,7 @@
        report_desc_t repd;
        char buf[100];
        struct command *cmd;
+       int reportid;
 
        demon = 1;
        ignore = 0;
@@ -118,11 +119,13 @@
        fd = open(hid, O_RDWR);
        if (fd < 0)
                err(1, "%s", hid);
+       if (ioctl(fd, USB_GET_REPORT_ID, &reportid) < 0)
+               reportid = -1;
        repd = hid_get_report_desc(fd);
        if (repd == NULL)
                err(1, "hid_get_report_desc() failed\n");
 
-       parse_conf(conf, repd, ignore);
+       parse_conf(conf, repd, reportid, ignore);
 
        sz = hid_report_size(repd, hid_input, NULL);
        hid_dispose_report_desc(repd);
@@ -179,7 +182,7 @@
 }
 
 void
-parse_conf(const char *conf, report_desc_t repd, int ignore)
+parse_conf(const char *conf, report_desc_t repd, int reportid, int ignore)
 {
        FILE *f;
        char *p;
@@ -229,7 +232,7 @@
                }
 
                coll[0] = 0;
-               for (d = hid_start_parse(repd, 1 << hid_input);
+               for (d = hid_start_parse(repd, 1 << hid_input, reportid);
                     hid_get_item(d, &h); ) {
                        if (verbose > 2)
                                printf("kind=%d usage=%x\n", h.kind, h.usage);
diff -r 13a093b75fb9 -r 8486696959fe usr.bin/usbhidctl/Makefile
--- a/usr.bin/usbhidctl/Makefile        Fri Dec 28 17:45:25 2001 +0000
+++ b/usr.bin/usbhidctl/Makefile        Fri Dec 28 17:49:31 2001 +0000
@@ -1,11 +1,11 @@
-#      $NetBSD: Makefile,v 1.6 2001/12/22 19:39:42 augustss Exp $
+#      $NetBSD: Makefile,v 1.7 2001/12/28 17:49:32 augustss Exp $
 
 .include <bsd.own.mk>
 
 PROG=  usbhidctl
 SRCS=  usbhid.c
 
-LDADD+=        -lusb
+LDADD+=        -lusbhid
 DPADD+=        ${LIBUSB}
 
 .include <bsd.prog.mk>
diff -r 13a093b75fb9 -r 8486696959fe usr.bin/usbhidctl/usbhid.c
--- a/usr.bin/usbhidctl/usbhid.c        Fri Dec 28 17:45:25 2001 +0000
+++ b/usr.bin/usbhidctl/usbhid.c        Fri Dec 28 17:49:31 2001 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: usbhid.c,v 1.19 2001/12/22 12:34:41 augustss Exp $ */
+/*      $NetBSD: usbhid.c,v 1.20 2001/12/28 17:49:32 augustss Exp $ */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -50,13 +50,21 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <usb.h>
+#include <usbhid.h>
+
+/*
+ * Zero if not in a verbose mode.  Greater levels of verbosity
+ * are indicated by values larger than one.
+ */
+unsigned int verbose;
 
 /* Parser tokens */
 #define DELIM_USAGE '.'
 #define DELIM_PAGE ':'
 #define DELIM_SET '='
 
+static int reportid;
+
 struct Susbvar {
        /* Variable name, not NUL terminated */
        char const *variable;
@@ -386,8 +394,7 @@
 {
        int reptsize;
 
-       reptsize = hid_report_size(rd, reptoparam[repindex].hid_kind,
-                                  &report->report_id);
+       reptsize = hid_report_size(rd, reptoparam[repindex].hid_kind, reportid);
        if (reptsize < 0)
                errx(1, "Negative report size");
        report->size = reptsize;
@@ -426,7 +433,8 @@
 
                report->buffer->report = reptoparam[repindex].uhid_report;
                if (ioctl(hidfd, USB_GET_REPORT, report->buffer) < 0)
-                       err(1, "USB_GET_REPORT");
+                       err(1, "USB_GET_REPORT (probably not supported by "
+                           "device)");
        }
 }
 
@@ -496,14 +504,28 @@
 static void
 reportitem(char const *label, struct hid_item const *item, unsigned int mflags)
 {
-       printf("%s size=%d count=%d page=%s usage=%s%s", label,
+       int isconst = item->flags & HIO_CONST,
+           isvar = item->flags & HIO_VARIABLE;
+       printf("%s size=%d count=%d%s%s page=%s", label,
               item->report_size, item->report_count,
-              hid_usage_page(HID_PAGE(item->usage)),
-              hid_usage_in_page(item->usage),
-              item->flags & HIO_CONST ? " Const" : "");
-       if (mflags & MATCH_SHOWNUMERIC)
-               printf(" (%u:0x%x)",
-                      HID_PAGE(item->usage), HID_USAGE(item->usage));
+              isconst ? " Const" : "",
+              !isvar && !isconst ? " Array" : "",
+              hid_usage_page(HID_PAGE(item->usage)));
+       if (item->usage_minimum != 0 || item->usage_maximum != 0) {
+               printf(" usage=%s..%s", hid_usage_in_page(item->usage_minimum),
+                      hid_usage_in_page(item->usage_maximum));
+               if (mflags & MATCH_SHOWNUMERIC)
+                       printf(" (%u:0x%x..%u:0x%x)",
+                              HID_PAGE(item->usage_minimum),
+                              HID_USAGE(item->usage_minimum),
+                              HID_PAGE(item->usage_maximum),
+                              HID_USAGE(item->usage_maximum));
+       } else {
+               printf(" usage=%s", hid_usage_in_page(item->usage));
+               if (mflags & MATCH_SHOWNUMERIC)
+                       printf(" (%u:0x%x)",
+                              HID_PAGE(item->usage), HID_USAGE(item->usage));
+       }
        printf(", logical range %d..%d",
               item->logical_minimum, item->logical_maximum);
        if (item->physical_minimum != item->physical_maximum)
@@ -577,7 +599,7 @@
                             (unsigned long)readlen, (unsigned long)dlen);
 
                collind = 0;
-               hdata = hid_start_parse(rd, 1 << hid_input);
+               hdata = hid_start_parse(rd, 1 << hid_input, reportid);
                if (hdata == NULL)
                        errx(1, "Failed to start parser");
 
@@ -602,6 +624,9 @@
                                errx(1, "Unexpected non-input item returned");
                        }
 
+                       if (reportid != -1 && hitem.report_ID != reportid)
+                               continue;
+
                        matchvar = hidmatch(colls, collind, &hitem,
                                            varlist, vlsize);
 
@@ -634,9 +659,7 @@
        }
 
        collind = 0;
-       hdata = hid_start_parse(rd, kindset |
-                               (1 << hid_collection) |
-                               (1 << hid_endcollection));
+       hdata = hid_start_parse(rd, kindset, reportid);
        if (hdata == NULL)
                errx(1, "Failed to start parser");
 
@@ -644,6 +667,9 @@
                struct Susbvar *matchvar;
                int repindex;
 
+               if (verbose > 3)
+                       printf("item: kind=%d repid=%d usage=0x%x\n",
+                              hitem.kind, hitem.report_ID, hitem.usage);
                repindex = -1;
                switch (hitem.kind) {
                case hid_collection:
@@ -667,6 +693,9 @@
                        break;
                }
 
+               if (reportid != -1 && hitem.report_ID != reportid)
+                       continue;
+
                matchvar = hidmatch(colls, collind, &hitem, varlist, vlsize);
 
                if (matchvar != NULL) {
@@ -743,12 +772,6 @@
        char devnamebuf[PATH_MAX];
        struct Susbvar variables[128];
 
-       /*
-        * Zero if not in a verbose mode.  Greater levels of verbosity
-        * are indicated by values larger than one.
-        */
-       unsigned int verbose;
-
        wflag = aflag = nflag = verbose = rflag = lflag = 0;
        dev = NULL;
        table = NULL;
@@ -909,6 +932,10 @@
        if (hidfd < 0)
                err(1, "%s", dev);
 
+       if (ioctl(hidfd, USB_GET_REPORT_ID, &reportid) < 0)
+               reportid = -1;
+       if (verbose > 1)
+               printf("report ID=%d\n", reportid);
        repdesc = hid_get_report_desc(hidfd);
        if (repdesc == 0)
                errx(1, "USB_GET_REPORT_DESC");
@@ -927,31 +954,18 @@
                1 << hid_output |
                1 << hid_feature);
 
-#if 0
-       {
-               size_t repindex;
-               for (repindex = 0;
-                    repindex < (sizeof(reptoparam) / sizeof(*reptoparam));
-                    repindex++)
-                       devshow(hidfd, repdesc, variables, varnum,
-                               1 << reptoparam[repindex].hid_kind);
-       }
-#endif
-
        if (rflag) {
                /* Report mode trailer */
                size_t repindex;



Home | Main Index | Thread Index | Old Index