Date: Mon, 17 May 2010 23:57:34 +0000 (UTC) From: Andrew Thompson <thompsa@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r208236 - stable/8/lib/libusbhid Message-ID: <201005172357.o4HNvYvY077964@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005172357.o4HNvYvY077964>