diff options
author | thompsa <thompsa@FreeBSD.org> | 2010-05-12 22:50:23 +0000 |
---|---|---|
committer | thompsa <thompsa@FreeBSD.org> | 2010-05-12 22:50:23 +0000 |
commit | f7f314b3e7a78435075395909cd58f38173acbcf (patch) | |
tree | 82be5c95a113342f861e9926b764dba4eb8684dd /lib/libusbhid | |
parent | f006c8aa860974e9c60cdb22c1d2c04dbc6d63f5 (diff) | |
download | FreeBSD-src-f7f314b3e7a78435075395909cd58f38173acbcf.zip FreeBSD-src-f7f314b3e7a78435075395909cd58f38173acbcf.tar.gz |
Support getting signed and unsigned HID data.
Submitted by: Alex Deiter
Reviewed by: Hans Petter Selaksy
Diffstat (limited to 'lib/libusbhid')
-rw-r--r-- | lib/libusbhid/data.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/libusbhid/data.c b/lib/libusbhid/data.c index 049c88b..afc5a21 100644 --- a/lib/libusbhid/data.c +++ b/lib/libusbhid/data.c @@ -63,13 +63,17 @@ hid_get_data(const void *p, const hid_item_t *h) data = 0; for (i = 0; i <= end; i++) data |= buf[offs + i] << (i*8); + + /* Correctly shift down data */ data >>= hpos % 8; - data &= (1 << hsize) - 1; - if (h->logical_minimum < 0) { - /* Need to sign extend */ - hsize = sizeof data * 8 - hsize; - data = (data << hsize) >> hsize; - } + hsize = 32 - hsize; + + /* Mask and sign extend in one */ + if ((h->logical_minimum < 0) || (h->logical_maximum < 0)) + data = (int32_t)((int32_t)data << hsize) >> hsize; + else + data = (uint32_t)((uint32_t)data << hsize) >> hsize; + return (data); } |