Change the API a little to allow positions to be determined correctly
for multiple kinds. From Dave Sainty <dave@dtsp.co.nz>.
This commit is contained in:
parent
cb9f491cfe
commit
0c0b8fd77c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: parse.c,v 1.10 2000/08/20 15:57:02 augustss Exp $ */
|
||||
/* $NetBSD: parse.c,v 1.11 2000/09/24 02:19:54 augustss Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
|
||||
@ -49,6 +49,11 @@ struct hid_data {
|
||||
int multi;
|
||||
int multimax;
|
||||
int kindset;
|
||||
|
||||
/* Absolute data position (bits) for input/output/feature.
|
||||
Assumes that hid_input, hid_output and hid_feature have
|
||||
values 0, 1 and 2. */
|
||||
unsigned int kindpos[3];
|
||||
};
|
||||
|
||||
static int min(int x, int y) { return x < y ? x : y; }
|
||||
@ -104,12 +109,13 @@ int
|
||||
hid_get_item(hid_data_t s, hid_item_t *h)
|
||||
{
|
||||
hid_item_t *c;
|
||||
unsigned int bTag = 0, bType = 0, bSize, oldpos;
|
||||
unsigned int bTag = 0, bType = 0, bSize;
|
||||
unsigned char *data;
|
||||
int dval;
|
||||
unsigned char *p;
|
||||
hid_item_t *hi;
|
||||
int i;
|
||||
hid_kind_t retkind;
|
||||
|
||||
_DIAGASSERT(s != NULL);
|
||||
_DIAGASSERT(h != NULL);
|
||||
@ -122,7 +128,11 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
||||
c->usage = s->usages[min(s->multi, s->nusage-1)];
|
||||
s->multi++;
|
||||
*h = *c;
|
||||
c->pos += c->report_size;
|
||||
|
||||
/* 'multimax' is only non-zero if the current
|
||||
item kind is input/output/feature */
|
||||
h->pos = s->kindpos[c->kind];
|
||||
s->kindpos[c->kind] += c->report_size;
|
||||
h->next = 0;
|
||||
return (1);
|
||||
} else {
|
||||
@ -184,11 +194,15 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
||||
case 0: /* Main */
|
||||
switch (bTag) {
|
||||
case 8: /* Input */
|
||||
if (!(s->kindset & (1 << hid_input)))
|
||||
continue;
|
||||
c->kind = hid_input;
|
||||
c->flags = dval;
|
||||
retkind = hid_input;
|
||||
ret:
|
||||
if (!(s->kindset & (1 << retkind))) {
|
||||
/* Drop the items of this kind */
|
||||
s->nusage = 0;
|
||||
continue;
|
||||
}
|
||||
c->kind = retkind;
|
||||
c->flags = dval;
|
||||
if (c->flags & HIO_VARIABLE) {
|
||||
s->multimax = c->report_count;
|
||||
s->multi = 0;
|
||||
@ -209,16 +223,14 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
||||
c->usage = c->usage_minimum;
|
||||
*h = *c;
|
||||
h->next = 0;
|
||||
c->pos += c->report_size * c->report_count;
|
||||
h->pos = s->kindpos[c->kind];
|
||||
s->kindpos[c->kind] += c->report_size * c->report_count;
|
||||
hid_clear_local(c);
|
||||
s->minset = 0;
|
||||
return (1);
|
||||
}
|
||||
case 9: /* Output */
|
||||
if (!(s->kindset & (1 << hid_output)))
|
||||
continue;
|
||||
c->kind = hid_output;
|
||||
c->flags = dval;
|
||||
retkind = hid_output;
|
||||
goto ret;
|
||||
case 10: /* Collection */
|
||||
c->kind = hid_collection;
|
||||
@ -230,10 +242,7 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
||||
s->nusage = 0;
|
||||
return (1);
|
||||
case 11: /* Feature */
|
||||
if (!(s->kindset & (1 << hid_feature)))
|
||||
continue;
|
||||
c->kind = hid_feature;
|
||||
c->flags = dval;
|
||||
retkind = hid_feature;
|
||||
goto ret;
|
||||
case 12: /* End collection */
|
||||
c->kind = hid_endcollection;
|
||||
@ -285,9 +294,7 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
||||
break;
|
||||
case 11: /* Pop */
|
||||
hi = c->next;
|
||||
oldpos = c->pos;
|
||||
s->cur = *hi;
|
||||
c->pos = oldpos;
|
||||
free(hi);
|
||||
break;
|
||||
default:
|
||||
@ -373,8 +380,9 @@ hid_report_size(report_desc_t r, enum hid_kind k, int *idp)
|
||||
id = 8;
|
||||
}
|
||||
}
|
||||
|
||||
size = d->kindpos[k] + id;
|
||||
hid_end_parse(d);
|
||||
size = h.pos + id;
|
||||
return ((size + 7) / 8);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user