Add a ScaledData() getter that scales the data to the desired bit width and
converts the signed-ness as specified. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41843 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
e761436dee
commit
d75a906285
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Michael Lotz, mmlr@mlotz.ch.
|
||||
* Copyright 2009-2011, Michael Lotz, mmlr@mlotz.ch.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@ -21,6 +21,7 @@ HIDReportItem::HIDReportItem(HIDReport *report, uint32 bitOffset,
|
||||
fByteOffset(bitOffset / 8),
|
||||
fShift(bitOffset % 8),
|
||||
fMask(~(0xffffffff << bitLength)),
|
||||
fBitCount(bitLength),
|
||||
fHasData(hasData),
|
||||
fArray(isArray),
|
||||
fRelative(isRelative),
|
||||
@ -114,6 +115,32 @@ HIDReportItem::SetData(uint32 data)
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
HIDReportItem::ScaledData(uint8 scaleToBits, bool toBeSigned)
|
||||
{
|
||||
uint32 source = fData;
|
||||
if (Signed() && !toBeSigned)
|
||||
source = (uint32)((int32)fData - (int32)fMinimum);
|
||||
|
||||
if (fBitCount == scaleToBits)
|
||||
return source;
|
||||
|
||||
int8 shift;
|
||||
uint32 result = 0;
|
||||
do {
|
||||
shift = scaleToBits - fBitCount;
|
||||
if (shift > 0) {
|
||||
result |= source << shift;
|
||||
scaleToBits = shift;
|
||||
} else
|
||||
result |= source >> -shift;
|
||||
|
||||
} while (shift > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HIDReportItem::PrintToStream(uint32 indentLevel)
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Michael Lotz, mmlr@mlotz.ch.
|
||||
* Copyright 2009-2011, Michael Lotz, mmlr@mlotz.ch.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef HID_REPORT_ITEM_H
|
||||
@ -36,6 +36,8 @@ public:
|
||||
status_t SetData(uint32 data);
|
||||
uint32 Data() { return fData; };
|
||||
|
||||
uint32 ScaledData(uint8 scaleToBits, bool toBeSigned);
|
||||
|
||||
bool Valid() { return fValid; };
|
||||
|
||||
void PrintToStream(uint32 indentLevel = 0);
|
||||
@ -44,6 +46,7 @@ private:
|
||||
uint32 fByteOffset;
|
||||
uint8 fShift;
|
||||
uint32 fMask;
|
||||
uint8 fBitCount;
|
||||
bool fHasData;
|
||||
bool fArray;
|
||||
bool fRelative;
|
||||
|
Loading…
Reference in New Issue
Block a user