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@
25 Contains: xxx put contents here xxx
27 Version: xxx put version here xxx
29 Copyright: © 1999-2000 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
44 Change History (most recent first):
46 <USB2> 12/12/00 KH range count off by 1.
47 <USB1> 3/5/99 BWS first checked in
53 *------------------------------------------------------------------------------
58 * ptPreparsedData - The Preparsed Data
59 * ptReportItem - The Report Item
60 * usagePage - The usage Page to find
61 * usage - The usage to find
62 * piIndex(optional) - The usage Index pointer (Can be used to tell
63 * which bits in an array correspond to that usage.)
64 * piCount(optional) - The usage Count pointer (Can be used to tell
65 * how many items will be in a report.)
67 * piIndex - The usage Index
71 *------------------------------------------------------------------------------
73 Boolean
HIDHasUsage (HIDPreparsedDataRef preparsedDataRef
,
74 HIDReportItem
*ptReportItem
,
75 HIDUsage usagePage
, HIDUsage usage
,
76 UInt32
*piIndex
, UInt32
*piCount
)
78 HIDPreparsedDataPtr ptPreparsedData
= (HIDPreparsedDataPtr
) preparsedDataRef
;
84 HIDP_UsageItem
*ptUsageItem
;
87 * Disallow Null Pointers
89 if ((ptPreparsedData
== NULL
)
90 || (ptReportItem
== NULL
))
92 if (ptPreparsedData
->hidTypeIfValid
!= kHIDOSType
)
95 * Look through the usage Items for this usage
97 iUsageItem
= ptReportItem
->firstUsageItem
;
99 for (i
=0; i
<ptReportItem
->usageItemCount
; i
++)
102 * Each usage Item is either a usage or a usage range
104 ptUsageItem
= &ptPreparsedData
->usageItems
[iUsageItem
++];
105 bOnPage
= ((usagePage
== 0) || (usagePage
== ptUsageItem
->usagePage
));
106 if (ptUsageItem
->isRange
)
110 * If the index is in the range
111 * then return the usage
112 * Otherwise adjust the index by the size of the range
114 if ((usage
>= ptUsageItem
->usageMinimum
)
115 && (usage
<= ptUsageItem
->usageMaximum
))
118 *piIndex
= iUsageIndex
+ (ptUsageItem
->usageMinimum
- usage
);
120 * If this usage is the last one for this ReportItem
121 * then it gets all of the remaining reportCount
125 // piCount is going to be used to find which element in a button array is
126 // the one that returns the value for that usage.
127 if (((i
+1) == ptReportItem
->usageItemCount
)
128 && (usage
== ptUsageItem
->usageMaximum
))
130 // Hmm, the same logic in the non-range case below was wrong. But things
131 // seem to be working for finding buttons, so i am not changing it here.
132 // However, we have made some changes to range calculations that may no
133 // longer require that -1 here either. Heads up!
134 iCountsLeft
= ptReportItem
->globals
.reportCount
- iUsageIndex
- 1;
136 *piCount
= iCountsLeft
;
146 iUsages
= ptUsageItem
->usageMaximum
- ptUsageItem
->usageMinimum
;
149 iUsages
++; // Add off by one adjustment AFTER sign correction.
150 iUsageIndex
+= iUsages
;
156 * If the index is zero
157 * then return this usage
158 * Otherwise one less to index through
160 if (usage
== ptUsageItem
->usage
)
163 *piIndex
= iUsageIndex
;
166 if ((i
+1) == ptReportItem
->usageItemCount
)
168 // Keithen does not understand the logic of iCountsLeft.
169 // In Radar #2579612 we come through here for HIDGetUsageValueArray
170 // and HIDGetSpecificValueCaps. In both cases piCount that is returned
171 // should be the reportCount without the -1.
172 // iCountsLeft = ptReportItem->globals.reportCount - iUsageIndex - 1;
173 iCountsLeft
= ptReportItem
->globals
.reportCount
- iUsageIndex
;
175 *piCount
= iCountsLeft
;