]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDScaleUsageValue.c
842453e8e7f33be29e35a5f9b9ca92662fd2086c
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 File: HIDScaleUsageValue.c
25 Contains: xxx put contents here xxx
27 Version: xxx put version here xxx
29 Copyright: © 1999 by Apple Computer, Inc., all rights reserved.
33 DRI: xxx put dri here xxx
35 Other Contact: xxx put other contact here xxx
37 Technology: xxx put technology here xxx
43 Change History (most recent first):
45 <USB1> 3/5/99 BWS first checked in
51 *------------------------------------------------------------------------------
53 * HIDScaleUsageValueIn
56 * ptReportItem - The ReportItem in which the data resides
57 * iValue - The unscaled data
58 * piScaledValue - The scaled value
60 * piScaledValue - The scaled value
64 *------------------------------------------------------------------------------
66 OSStatus
HIDScaleUsageValueIn (HIDReportItem
*ptReportItem
, UInt32 iValue
, SInt32
*piScaledValue
)
73 long int lLMin
, lLMax
;
75 * Disallow Null Pointers
77 if ((ptReportItem
== NULL
) || (piScaledValue
== NULL
))
78 return kHIDNullPointerErr
;
80 * Convert the data to Long Integer
84 * range check the Logical Value
86 lLMax
= ptReportItem
->globals
.logicalMaximum
;
87 lLMin
= ptReportItem
->globals
.logicalMinimum
;
88 if ((lData
< lLMin
) || (lData
> lLMax
))
90 if ((ptReportItem
->dataModes
& kHIDDataNullStateBit
) == kHIDDataNullState
)
91 return kHIDNullStateErr
;
92 return kHIDValueOutOfRangeErr
;
95 * (PhysicalValue - PhysicalMinimum)/(PhysicalMaximum - PhysicalMinimum)
96 * = (LogicalValue - LogicalMinimum)/(LogicalMaximum - LogicalMinimum)
98 * Calculate the ranges
99 * Zero ranges are invalid!
100 * lDeltaL = (LogicalMaximum - LogicalMinimum)
101 * lDeltaP = (PhysicalMaximum - PhysicalMinimum)
103 lDeltaL
= lLMax
- lLMin
;
104 lDeltaP
= ptReportItem
->globals
.physicalMaximum
- ptReportItem
->globals
.physicalMinimum
;
105 if ((lDeltaL
== 0) || (lDeltaP
== 0))
106 return kHIDBadLogPhysValuesErr
;
108 * (PhysicalValue - PhysicalMinimum)/lDeltaP
109 * = (LogicalValue - LogicalMinimum)/lDeltaL
110 * lL = (LogicalValue - LogicalMinimum)
112 lL
= lData
- ptReportItem
->globals
.logicalMinimum
;
114 * (PhysicalValue - PhysicalMinimum)/lDeltaP = lL/lDeltaL
115 * (PhysicalValue - PhysicalMinimum) = (lDeltaP * lL)/lDeltaL
116 * lP = (PhysicalValue - PhysicalMinimum) = (lDeltaP * lL)/lDeltaL
118 lP
= (lL
* lDeltaP
)/lDeltaL
;
120 * lP = (PhysicalValue - PhysicalMinimum)
121 * PhysicalValue = lP + PhysicalMinimum;
123 lScaledData
= lP
+ ptReportItem
->globals
.physicalMinimum
;
124 *piScaledValue
= (int) lScaledData
;
129 *------------------------------------------------------------------------------
131 * HIDScaleUsageValueOut
134 * ptReportItem - The ReportItem in which the data will go
135 * iValue - The unscaled data
136 * piScaledValue - The scaled value
138 * piScaledValue - The scaled value
142 *------------------------------------------------------------------------------
144 OSStatus
HIDScaleUsageValueOut (HIDReportItem
*ptReportItem
, UInt32 iValue
, SInt32
*piScaledValue
)
150 long int lPMax
, lPMin
;
152 * Convert the data to Long Integer
156 * range check the Logical Value
158 lPMax
= ptReportItem
->globals
.physicalMaximum
;
159 lPMin
= ptReportItem
->globals
.physicalMinimum
;
160 if ((lData
< lPMin
) || (lData
> lPMax
))
162 if ((ptReportItem
->dataModes
& kHIDDataNullStateBit
) == kHIDDataNullState
)
163 return kHIDNullStateErr
;
164 return kHIDValueOutOfRangeErr
;
167 * (PhysicalValue - PhysicalMinimum)/(PhysicalMaximum - PhysicalMinimum)
168 * = (LogicalValue - LogicalMinimum)/(LogicalMaximum - LogicalMinimum)
170 * Calculate the ranges
171 * Zero ranges are invalid!
172 * lDeltaL = (LogicalMaximum - LogicalMinimum)
173 * lDeltaP = (PhysicalMaximum - PhysicalMinimum)
175 lDeltaL
= ptReportItem
->globals
.logicalMaximum
- ptReportItem
->globals
.logicalMinimum
;
176 lDeltaP
= ptReportItem
->globals
.physicalMaximum
- ptReportItem
->globals
.physicalMinimum
;
177 if ((lDeltaL
== 0) || (lDeltaP
== 0))
178 return kHIDBadLogPhysValuesErr
;
180 * (PhysicalValue - PhysicalMinimum)/lDeltaP
181 * = (LogicalValue - LogicalMinimum)/lDeltaL
182 * lP = (PhysicalValue - PhysicalMinimum)
184 lP
= lData
- ptReportItem
->globals
.physicalMinimum
;
186 * (LogicalValue - LogicalMinimum)/lDeltaL = lP/lDeltaP
187 * (LogicalValue - LogicalMinimum)/lDeltaL = (lDeltaL * lP)/lDeltaP
188 * lL = (LogicalValue - LogicalMinimum) = (lDeltaL * lP)/lDeltaP
190 lL
= (lP
* lDeltaL
)/lDeltaP
;
192 * lL = (LogicalValue - LogicalMinimum)
193 * LogicalValue = lL + LogicalMinimum;
195 lData
= lL
+ ptReportItem
->globals
.logicalMinimum
;
196 *piScaledValue
= (int) lData
;