Make usbhidctl more like other *ctl commands.

This commit is contained in:
augustss 1998-07-13 20:56:28 +00:00
parent c9b3b5ba88
commit 262a9daf93
2 changed files with 53 additions and 23 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: usbhid.c,v 1.2 1998/07/13 20:44:04 augustss Exp $ */
/* $NetBSD: usbhid.c,v 1.3 1998/07/13 20:56:28 augustss Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -51,6 +51,11 @@
#define USBDEV "/dev/uhid0"
int verbose = 0;
int all = 0;
int noname = 0;
char **names;
int nnames;
void prbits(int bits, char **strs, int n);
void usage(void);
@ -59,6 +64,18 @@ void rev(struct hid_item **p);
u_long getdata(u_char *buf, int hpos, int hsize, int sign);
void prdata(u_char *buf, struct hid_item *h);
void dumpdata(int f, u_char *buf, int len, int loop);
int gotname(char *n);
int
gotname(char *n)
{
int i;
for (i = 0; i < nnames; i++)
if (strcmp(names[i], n) == 0)
return 1;
return 0;
}
void
prbits(int bits, char **strs, int n)
@ -75,7 +92,7 @@ usage(void)
{
extern char *__progname;
fprintf(stderr, "Usage: %s -f device [-l] [-n] [-r] [-t tablefile] [-v]\n", __progname);
fprintf(stderr, "Usage: %s [-a] -f device [-l] [-n] [-r] [-t tablefile] [-v] [name ...]\n", __progname);
exit(1);
}
@ -190,6 +207,7 @@ dumpdata(int f, u_char *buf, int len, int loop)
static int one = 1;
u_int32_t colls[100];
int sp = 0;
char namebuf[10000], *namep;
hids = 0;
for (d = hid_start_parse(buf, len, 1<<hid_input);
@ -218,17 +236,23 @@ dumpdata(int f, u_char *buf, int len, int loop)
err(1, "bad read %d != %d", r, dlen);
}
for (n = hids; n; n = n->next) {
printf("%s:%s.",
usage_page(HID_PAGE(n->collection)),
usage_in_page(n->collection));
printf("%s:%s=",
usage_page(HID_PAGE(n->usage)),
usage_in_page(n->usage));
prdata(dbuf, n);
if (verbose)
printf(" [%d - %d]",
n->logical_minimum, n->logical_maximum);
printf("\n");
namep = namebuf;
namep += sprintf(namep, "%s:%s.",
usage_page(HID_PAGE(n->collection)),
usage_in_page(n->collection));
namep += sprintf(namep, "%s:%s",
usage_page(HID_PAGE(n->usage)),
usage_in_page(n->usage));
if (all || gotname(namebuf)) {
if (!noname)
printf("%s=", namebuf);
prdata(dbuf, n);
if (verbose)
printf(" [%d - %d]",
n->logical_minimum,
n->logical_maximum);
printf("\n");
}
}
if (loop)
printf("\n");
@ -247,11 +271,13 @@ main(int argc, char **argv)
struct usb_ctl_report_desc rep;
int repdump = 0;
int loop = 0;
int nothing = 0;
char *table = HIDTABLE;
while ((ch = getopt(argc, argv, "f:lnrt:v")) != -1) {
while ((ch = getopt(argc, argv, "af:lnrt:v")) != -1) {
switch(ch) {
case 'a':
all++;
break;
case 'f':
dev = optarg;
break;
@ -259,7 +285,7 @@ main(int argc, char **argv)
loop ^= 1;
break;
case 'n':
nothing++;
noname++;
break;
case 'r':
repdump++;
@ -277,8 +303,10 @@ main(int argc, char **argv)
}
argc -= optind;
argv += optind;
if (argc != 0 || dev == 0)
if (dev == 0)
usage();
names = argv;
nnames = argc;
init_hid(table);
@ -295,8 +323,7 @@ main(int argc, char **argv)
printf("Report descriptor\n");
dumpitems(rep.data, rep.size);
}
if (!nothing)
dumpdata(f, rep.data, rep.size, loop);
dumpdata(f, rep.data, rep.size, loop);
exit(0);
}

View File

@ -1,4 +1,4 @@
.\" $NetBSD: usbhidctl.1,v 1.2 1998/07/13 20:44:04 augustss Exp $
.\" $NetBSD: usbhidctl.1,v 1.3 1998/07/13 20:56:28 augustss Exp $
.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
@ -40,24 +40,29 @@
.Nd manipulate USB HID devices
.Sh SYNOPSIS
.Nm
.Op Fl a
.Fl f Ar device
.Op Fl l
.Op Fl n
.Op Fl r
.Op Fl t Ar table
.Op Fl v
.Op name ...
.Sh DESCRIPTION
.Nm
can be used to dump the state of a USB HID (Human Interface Device).
The named variables are printed.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl a
Show all settings.
.It Fl f Ar device
Specify a path name for device to operate on.
.It Fl l
Loop and dump the device data every time it changes.
.It Fl n
Do not dump any data.
Suppresses printing of the variable name.
.It Fl r
Dump the report descriptor.
.It Fl t Ar table
@ -68,8 +73,6 @@ Be verbose.
.Sh FILES
.Pa /usr/share/misc/usb_hid_usages
The default HID usage table.
.Sh BUGS
The HID usage table is very incomplete.
.Sh SEE ALSO
.Xr usb 4 ,
.Xr uhid 4