aboutsummaryrefslogtreecommitdiff
path: root/lib/libusbhid
diff options
context:
space:
mode:
authorAndrew Thompson <thompsa@FreeBSD.org>2010-05-12 22:50:23 +0000
committerAndrew Thompson <thompsa@FreeBSD.org>2010-05-12 22:50:23 +0000
commit5fdb3a67ac91cf5f46c38fe9b2b11eb28ee55fed (patch)
tree82be5c95a113342f861e9926b764dba4eb8684dd /lib/libusbhid
parentc68e91c3a4f7111a622b55a167bfee9152dfbf05 (diff)
Support getting signed and unsigned HID data.
Submitted by: Alex Deiter Reviewed by: Hans Petter Selaksy
Notes
Notes: svn path=/head/; revision=208012
Diffstat (limited to 'lib/libusbhid')
-rw-r--r--lib/libusbhid/data.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/libusbhid/data.c b/lib/libusbhid/data.c
index 049c88b634bf..afc5a211ddc0 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);
}