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:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2009, Michael Lotz, [email protected].
|
* Copyright 2009-2011, Michael Lotz, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@ HIDReportItem::HIDReportItem(HIDReport *report, uint32 bitOffset,
|
|||||||
fByteOffset(bitOffset / 8),
|
fByteOffset(bitOffset / 8),
|
||||||
fShift(bitOffset % 8),
|
fShift(bitOffset % 8),
|
||||||
fMask(~(0xffffffff << bitLength)),
|
fMask(~(0xffffffff << bitLength)),
|
||||||
|
fBitCount(bitLength),
|
||||||
fHasData(hasData),
|
fHasData(hasData),
|
||||||
fArray(isArray),
|
fArray(isArray),
|
||||||
fRelative(isRelative),
|
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
|
void
|
||||||
HIDReportItem::PrintToStream(uint32 indentLevel)
|
HIDReportItem::PrintToStream(uint32 indentLevel)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2009, Michael Lotz, [email protected].
|
* Copyright 2009-2011, Michael Lotz, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef HID_REPORT_ITEM_H
|
#ifndef HID_REPORT_ITEM_H
|
||||||
@@ -36,6 +36,8 @@ public:
|
|||||||
status_t SetData(uint32 data);
|
status_t SetData(uint32 data);
|
||||||
uint32 Data() { return fData; };
|
uint32 Data() { return fData; };
|
||||||
|
|
||||||
|
uint32 ScaledData(uint8 scaleToBits, bool toBeSigned);
|
||||||
|
|
||||||
bool Valid() { return fValid; };
|
bool Valid() { return fValid; };
|
||||||
|
|
||||||
void PrintToStream(uint32 indentLevel = 0);
|
void PrintToStream(uint32 indentLevel = 0);
|
||||||
@@ -44,6 +46,7 @@ private:
|
|||||||
uint32 fByteOffset;
|
uint32 fByteOffset;
|
||||||
uint8 fShift;
|
uint8 fShift;
|
||||||
uint32 fMask;
|
uint32 fMask;
|
||||||
|
uint8 fBitCount;
|
||||||
bool fHasData;
|
bool fHasData;
|
||||||
bool fArray;
|
bool fArray;
|
||||||
bool fRelative;
|
bool fRelative;
|
||||||
|
|||||||
Reference in New Issue
Block a user