mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 08:43:19 -04:00
MFC r208012
Support getting signed and unsigned HID data.
This commit is contained in:
parent
300902e282
commit
1eeca0bf19
1 changed files with 10 additions and 6 deletions
|
|
@ -53,13 +53,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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue