svn commit: r208236 - stable/8/lib/libusbhid
Andrew Thompson
thompsa at FreeBSD.org
Mon May 17 23:57:34 UTC 2010
Author: thompsa
Date: Mon May 17 23:57:34 2010
New Revision: 208236
URL: http://svn.freebsd.org/changeset/base/208236
Log:
MFC r208012
Support getting signed and unsigned HID data.
Modified:
stable/8/lib/libusbhid/data.c
Directory Properties:
stable/8/lib/libusbhid/ (props changed)
Modified: stable/8/lib/libusbhid/data.c
==============================================================================
--- stable/8/lib/libusbhid/data.c Mon May 17 23:56:17 2010 (r208235)
+++ stable/8/lib/libusbhid/data.c Mon May 17 23:57:34 2010 (r208236)
@@ -53,13 +53,17 @@ hid_get_data(const void *p, const hid_it
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);
}
More information about the svn-src-stable-8
mailing list