2 * Copyright (c) 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: HIDGetNextUsageValueInfo.c
25 Contains: HIDGetNextUsageValueInfo call for HID Library
29 Copyright: © 2000 by Apple Computer, Inc., all rights reserved.
35 Other Contact: Keithen Hayenga
37 Technology: technologies, usb
43 Change History (most recent first):
45 <USB1> 2/14/00 KH first checked in
51 *------------------------------------------------------------------------------
53 * HIDGetNextUsageValueInfo - Get report id and collection for a usage. In keeping
54 * with USBGetNextInterface, we find the usage in the
55 * next collection, so that you can find usages that
56 * have the same usage and usage page.
59 * reportType - HIDP_Input, HIDP_Output, HIDP_Feature
60 * usagePage - Page Criteria or zero
61 * usage - The usage to get the information for
62 * collection - Starting Collection Criteria or zero
63 * preparsedDataRef - Pre-Parsed Data
65 * collection - Final Collection Criteria or no change
66 * reportID - Report ID or no change
68 * kHIDBadParameterErr when there are no more collections to search.
70 *------------------------------------------------------------------------------
72 OSStatus HIDGetNextUsageValueInfo
73 (HIDReportType reportType
,
78 HIDPreparsedDataRef preparsedDataRef
)
80 HIDPreparsedDataPtr ptPreparsedData
= (HIDPreparsedDataPtr
)preparsedDataRef
;
81 HIDReportItem
*ptReportItem
;
83 UInt32 newCollection
= 0xFFFFFFFF;
85 UInt8 newReportID
= 0;
86 OSStatus iStatus
= kHIDUsageNotFoundErr
;
88 //Disallow Null Pointers
90 if ((ptPreparsedData
== NULL
) || (collection
== NULL
) || (reportID
== NULL
))
91 return kHIDNullPointerErr
;
92 if (ptPreparsedData
->hidTypeIfValid
!= kHIDOSType
)
93 return kHIDInvalidPreparsedDataErr
;
95 // The Collection must be in range
97 iCollection
= *collection
;
98 // Umm... an unsigned number can never be less than 0!
99 if ((iCollection
< 0) || (iCollection
>= ptPreparsedData
->collectionCount
))
100 return kHIDBadParameterErr
;
102 // HIDGetNextUsageValueInfo is different from HIDGetUsageValue in how it treats
103 // the collection parameter. HIDGetUsageValue will only look at report items that
104 // are within the collection and can therefore limit it's searches to starting at
105 // ptPreparsedData->collections[iCollection]->firstReportItem and only check
106 // ptPreparsedData->collections[iCollection]->reportItemCount. Since we want to
107 // find the NEXT collection as well, we need to cycle through all of the reports.
109 for (iR
= 0; iR
< ptPreparsedData
->reportItemCount
; iR
++)
113 HIDP_UsageItem thisUsage
;
115 ptReportItem
= &ptPreparsedData
->reportItems
[iR
];
117 thisUsage
= ptPreparsedData
->usageItems
[ptReportItem
->firstUsageItem
];
119 if (thisUsage
.isRange
)
121 minUsage
= thisUsage
.usageMinimum
;
122 maxUsage
= thisUsage
.usageMaximum
;
126 minUsage
= thisUsage
.usage
;
127 maxUsage
= thisUsage
.usage
;
130 if (ptReportItem
->reportType
== reportType
&&
131 (usagePage
== 0 || ptReportItem
->globals
.usagePage
== usagePage
) &&
132 (usage
>= minUsage
&& usage
<= maxUsage
) &&
133 ptReportItem
->parent
> iCollection
&&
134 HIDIsVariable(ptReportItem
, preparsedDataRef
))
136 if (ptReportItem
->parent
< newCollection
)
138 newCollection
= ptReportItem
->parent
;
145 if (iStatus
== noErr
)
147 *reportID
= newReportID
;
148 *collection
= newCollection
;