Subject: Re: accessing specific USB HID devices
To: Lennart Augustsson <lennart@augustsson.net>
From: Werner Backes <werner@bit-1.de>
List: current-users
Date: 04/23/2004 17:29:09
Lennart Augustsson wrote:
> I'll probably add what you want soon, it seems useful. :)

That's fine :). I think it will make NetBSD's uhid support
even more useful. Btw., what is the reason it was choosen
to attach an own device node for every report ID instead
of one device node for every physical device? Some HID devices
seem to have LOTS of report IDs (about 20 for a MS Sidewinder
Joystick). I have to admit that most of them belong to the
force feedback section which is of no use anyway :)

Another thing is the missing support for access to array
elements via usbhidctl (See BUGS section of usbhidctl(1)).
What do you think about the following patch to
usr.bin/usbhidctl/usbhid.c?
It works for me but I have only one device (IO-Warrior24)
which has reports with array items so I couldn't do much
testing.

69a70,71

 >> #define DELIM_ARRAY_LEFT '['
 >> #define DELIM_ARRAY_RIGHT ']'

76a79,80

 >> 	char const *index;
 >> 	size_t indexlen;

387a392,399

 >> 				/* check array index if present */
 >>                         	if (var->index != NULL) {
 >>                                 	if (item->report_count-1 < 
(int)strtol(var->index, NULL, 10)) {
 >> 						var->matchindex = -1;
 >>                                 		vlactive--;
 >>                                 		continue;
 >>                                 	}
 >>                         	}

475c487,488
< 	int val, i;
---

 >> 	int val, i,start,end;
 >> 	item->pos=0;

477c490,498
< 	for (i = 0; i < item->report_count; i++) {
---

 >>         if (var->index  == NULL) {
 >> 		start = item->pos = 0;
 >> 		end = item->report_count;
 >>         } else {
 >>                 start = item->pos = strtol(var->index, NULL, 10);
 >> 		end = start+1;
 >> 	}
 >>
 >> 	for (i = start; i < end; i++) {

509a531,533

 >> 	if (var->index  != NULL) {
 >> 		item->pos = strtol(var->index, NULL, 10);
 >> 	}

756,757c780,782
< 			warnx("Failed to match: %.*s", (int)var->varlen,
< 			      var->variable);
---

 >> 			warnx("Failed to match: %.*s", (int)var->varlen +
 >> 				((int)var->indexlen ? (int)var->indexlen+2 : 0),
 >> 			      	var->variable);

838c863
< 		char const *name, *valuesep;
---

 >> 		char const *name, *valuesep, *arraysep1, *arraysep2;

882a908,920

 >> 		arraysep1 = strchr(name, DELIM_ARRAY_LEFT);
 >> 		arraysep2 = strchr(name, DELIM_ARRAY_RIGHT);
 >> 		if (arraysep1 == NULL || arraysep2 == NULL) {
 >> 			svar->index = NULL;
 >> 			svar->indexlen = 0;
 >>
 >> 		} else {
 >> 			svar->varlen = arraysep1 - name;
 >> 			svar->index = arraysep1+1;
 >> 			svar->indexlen = arraysep2-arraysep1-1;
 >> 			if ((int)svar->indexlen < 1)
 >> 				errx(1, "Array index missing.");
 >> 		}