From 6eabc833869d8181de827f07990068af672a8962 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sun, 5 Jun 2011 23:53:04 +0000 Subject: [PATCH] Add HIDReportItem::ScaledFloatData() which scales the data into a float range from 0.0 to 1.0. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41948 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/drivers/input/usb_hid/HIDReportItem.cpp | 12 ++++++++++++ .../kernel/drivers/input/usb_hid/HIDReportItem.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/add-ons/kernel/drivers/input/usb_hid/HIDReportItem.cpp b/src/add-ons/kernel/drivers/input/usb_hid/HIDReportItem.cpp index e014df2715..5f937a6c11 100644 --- a/src/add-ons/kernel/drivers/input/usb_hid/HIDReportItem.cpp +++ b/src/add-ons/kernel/drivers/input/usb_hid/HIDReportItem.cpp @@ -146,6 +146,18 @@ HIDReportItem::ScaledData(uint8 scaleToBits, bool toBeSigned) } +float +HIDReportItem::ScaledFloatData() +{ + if (Signed()) { + return (double)((int32)fData - (int32)fMinimum) + / (fMaximum - (int32)fMinimum); + } + + return (double)(fData - fMinimum) / (fMaximum - fMinimum); +} + + void HIDReportItem::PrintToStream(uint32 indentLevel) { diff --git a/src/add-ons/kernel/drivers/input/usb_hid/HIDReportItem.h b/src/add-ons/kernel/drivers/input/usb_hid/HIDReportItem.h index ed1cf63501..23238b5bec 100644 --- a/src/add-ons/kernel/drivers/input/usb_hid/HIDReportItem.h +++ b/src/add-ons/kernel/drivers/input/usb_hid/HIDReportItem.h @@ -37,6 +37,7 @@ public: uint32 Data() { return fData; }; uint32 ScaledData(uint8 scaleToBits, bool toBeSigned); + float ScaledFloatData(); bool Valid() { return fValid; };