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: HIDGetNextButtonInfo.c
25 Contains: HIDGetNextButtonInfo 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 * HIDGetNextButtonInfo - Get report id and collection for a button. 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
69 *------------------------------------------------------------------------------
71 OSStatus HIDGetNextButtonInfo
72 (HIDReportType reportType
,
77 HIDPreparsedDataRef preparsedDataRef
)
79 HIDPreparsedDataPtr ptPreparsedData
= (HIDPreparsedDataPtr
)preparsedDataRef
;
80 HIDReportItem
*ptReportItem
;
82 UInt32 newCollection
= 0xFFFFFFFF;
84 UInt8 newReportID
= 0;
85 OSStatus iStatus
= kHIDUsageNotFoundErr
;
87 //Disallow Null Pointers
89 if ((ptPreparsedData
== NULL
) || (collection
== NULL
) || (reportID
== NULL
))
90 return kHIDNullPointerErr
;
91 if (ptPreparsedData
->hidTypeIfValid
!= kHIDOSType
)
92 return kHIDInvalidPreparsedDataErr
;
94 // The Collection must be in range
96 iCollection
= *collection
;
97 // Umm... an unsigned number can never be less than 0!
98 if ((iCollection
< 0) || (iCollection
>= ptPreparsedData
->collectionCount
))
99 return kHIDBadParameterErr
;
101 // HIDGetNextButtonInfo is different from HIDGetButton in how it treats
102 // the collection parameter. HIDGetButton will only look at report items that
103 // are within the collection and can therefore limit it's searches to starting at
104 // ptPreparsedData->collections[iCollection]->firstReportItem and only check
105 // ptPreparsedData->collections[iCollection]->reportItemCount. Since we want to
106 // find the NEXT collection as well, we need to cycle through all of the reports.
108 for (iR
= 0; iR
< ptPreparsedData
->reportItemCount
; iR
++)
112 HIDP_UsageItem thisUsage
;
114 ptReportItem
= &ptPreparsedData
->reportItems
[iR
];
116 thisUsage
= ptPreparsedData
->usageItems
[ptReportItem
->firstUsageItem
];
118 if (thisUsage
.isRange
)
120 minUsage
= thisUsage
.usageMinimum
;
121 maxUsage
= thisUsage
.usageMaximum
;
125 minUsage
= thisUsage
.usage
;
126 maxUsage
= thisUsage
.usage
;
129 if (ptReportItem
->reportType
== reportType
&&
130 (usagePage
== 0 || ptReportItem
->globals
.usagePage
== usagePage
) &&
131 (usage
>= minUsage
&& usage
<= maxUsage
) &&
132 ptReportItem
->parent
> iCollection
&&
133 HIDIsButton(ptReportItem
, preparsedDataRef
))
135 if (ptReportItem
->parent
< newCollection
)
137 newCollection
= ptReportItem
->parent
;
144 if (iStatus
== noErr
)
146 *reportID
= newReportID
;
147 *collection
= newCollection
;