svn commit: r224482 - projects/hid/usr.bin/usbhidctl

Alexander Motin mav at FreeBSD.org
Thu Jul 28 17:46:00 UTC 2011


Author: mav
Date: Thu Jul 28 17:45:59 2011
New Revision: 224482
URL: http://svn.freebsd.org/changeset/base/224482

Log:
  - Make usbhidctl work with devices with multiple Report IDs.
  - Report Array items as such, and fix printing of their values.

Modified:
  projects/hid/usr.bin/usbhidctl/usbhid.c

Modified: projects/hid/usr.bin/usbhidctl/usbhid.c
==============================================================================
--- projects/hid/usr.bin/usbhidctl/usbhid.c	Thu Jul 28 17:31:49 2011	(r224481)
+++ projects/hid/usr.bin/usbhidctl/usbhid.c	Thu Jul 28 17:45:59 2011	(r224482)
@@ -46,7 +46,6 @@ int verbose = 0;
 int all = 0;
 int noname = 0;
 int hexdump = 0;
-static int reportid;
 
 char **names;
 int nnames;
@@ -101,11 +100,12 @@ dumpitem(const char *label, struct hid_i
 {
 	if ((h->flags & HIO_CONST) && !verbose)
 		return;
-	printf("%s rid=%d size=%d count=%d page=%s usage=%s%s", label,
+	printf("%s rid=%d size=%d count=%d page=%s usage=%s%s%s", label,
 	       h->report_ID, h->report_size, h->report_count,
 	       hid_usage_page(HID_PAGE(h->usage)),
 	       hid_usage_in_page(h->usage),
-	       h->flags & HIO_CONST ? " Const" : "");
+	       h->flags & HIO_CONST ? " Const" : "",
+	       h->flags & HIO_VARIABLE ? "" : " Array");
 	printf(", logical range %d..%d",
 	       h->logical_minimum, h->logical_maximum);
 	if (h->physical_minimum != h->physical_maximum)
@@ -141,7 +141,7 @@ dumpitems(report_desc_t r)
 	struct hid_item h;
 	int size;
 
-	for (d = hid_start_parse(r, ~0, reportid); hid_get_item(d, &h); ) {
+	for (d = hid_start_parse(r, ~0, -1); hid_get_item(d, &h); ) {
 		switch (h.kind) {
 		case hid_collection:
 			printf("Collection type=%s page=%s usage=%s\n",
@@ -164,13 +164,13 @@ dumpitems(report_desc_t r)
 		}
 	}
 	hid_end_parse(d);
-	size = hid_report_size(r, hid_input, 0);
+	size = hid_report_size(r, hid_input, -1);
 	printf("Total   input size %d bytes\n", size);
 
-	size = hid_report_size(r, hid_output, 0);
+	size = hid_report_size(r, hid_output, -1);
 	printf("Total  output size %d bytes\n", size);
 
-	size = hid_report_size(r, hid_feature, 0);
+	size = hid_report_size(r, hid_feature, -1);
 	printf("Total feature size %d bytes\n", size);
 }
 
@@ -199,14 +199,17 @@ prdata(u_char *buf, struct hid_item *h)
 	pos = h->pos;
 	for (i = 0; i < h->report_count; i++) {
 		data = hid_get_data(buf, h);
+		if (i > 0)
+			printf(" ");
 		if (h->logical_minimum < 0)
 			printf("%d", (int)data);
 		else
 			printf("%u", data);
                 if (hexdump)
 			printf(" [0x%x]", data);
-		pos += h->report_size;
+		h->pos += h->report_size;
 	}
+	h->pos = pos;
 }
 
 void
@@ -221,7 +224,7 @@ dumpdata(int f, report_desc_t rd, int lo
 	char namebuf[10000], *namep;
 
 	hids = 0;
-	for (d = hid_start_parse(rd, 1<<hid_input, reportid);
+	for (d = hid_start_parse(rd, 1<<hid_input, -1);
 	     hid_get_item(d, &h); ) {
 		if (h.kind == hid_collection)
 			colls[++sp] = h.usage;
@@ -236,7 +239,7 @@ dumpdata(int f, report_desc_t rd, int lo
 	}
 	hid_end_parse(d);
 	rev(&hids);
-	dlen = hid_report_size(rd, hid_input, 0);
+	dlen = hid_report_size(rd, hid_input, -1);
 	dbuf = malloc(dlen);
 	if (!loop)
 		if (hid_set_immed(f, 1) < 0) {
@@ -247,10 +250,12 @@ dumpdata(int f, report_desc_t rd, int lo
 		}
 	do {
 		r = read(f, dbuf, dlen);
-		if (r != dlen) {
-			err(1, "bad read %d != %d", r, dlen);
+		if (r < 1) {
+			err(1, "read error");
 		}
 		for (n = hids; n; n = n->next) {
+			if (n->report_ID != 0 && dbuf[0] != n->report_ID)
+				continue;
 			namep = namebuf;
 			namep += sprintf(namep, "%s:%s.",
 					 hid_usage_page(HID_PAGE(n->collection)),
@@ -261,7 +266,7 @@ dumpdata(int f, report_desc_t rd, int lo
 			if (all || gotname(namebuf)) {
 				if (!noname)
 					printf("%s=", namebuf);
-				prdata(dbuf + (reportid != 0), n);
+				prdata(dbuf, n);
 				printf("\n");
 			}
 		}


More information about the svn-src-projects mailing list