]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDGetNextButtonInfo.c
26adbec86c3595cf40765c7d2276246a7fa587a5
[apple/xnu.git] / iokit / Families / IOHIDSystem / IOHIDDescriptorParser / HIDGetNextButtonInfo.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 File: HIDGetNextButtonInfo.c
24
25 Contains: HIDGetNextButtonInfo call for HID Library
26
27 Version: 1.0d1
28
29 Copyright: © 2000 by Apple Computer, Inc., all rights reserved.
30
31 File Ownership:
32
33 DRI: David Ferguson
34
35 Other Contact: Keithen Hayenga
36
37 Technology: technologies, usb
38
39 Writers:
40
41 (KH) Keithen Hayenga
42
43 Change History (most recent first):
44
45 <USB1> 2/14/00 KH first checked in
46 */
47
48 #include "HIDLib.h"
49
50 /*
51 *------------------------------------------------------------------------------
52 *
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.
57 *
58 * Input:
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
64 * Output:
65 * collection - Final Collection Criteria or no change
66 * reportID - Report ID or no change
67 * Returns:
68 *
69 *------------------------------------------------------------------------------
70 */
71 OSStatus HIDGetNextButtonInfo
72 (HIDReportType reportType,
73 HIDUsage usagePage,
74 HIDUsage usage,
75 UInt32 * collection,
76 UInt8 * reportID,
77 HIDPreparsedDataRef preparsedDataRef)
78 {
79 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr)preparsedDataRef;
80 HIDReportItem *ptReportItem;
81 UInt32 iCollection;
82 UInt32 newCollection = 0xFFFFFFFF;
83 int iR;
84 UInt8 newReportID = 0;
85 OSStatus iStatus = kHIDUsageNotFoundErr;
86
87 //Disallow Null Pointers
88
89 if ((ptPreparsedData == NULL) || (collection == NULL) || (reportID == NULL))
90 return kHIDNullPointerErr;
91 if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
92 return kHIDInvalidPreparsedDataErr;
93
94 // The Collection must be in range
95
96 iCollection = *collection;
97 // Umm... an unsigned number can never be less than 0!
98 if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount))
99 return kHIDBadParameterErr;
100
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.
107
108 for (iR = 0; iR < ptPreparsedData->reportItemCount; iR++)
109 {
110 SInt32 minUsage;
111 SInt32 maxUsage;
112 HIDP_UsageItem thisUsage;
113
114 ptReportItem = &ptPreparsedData->reportItems[iR];
115
116 thisUsage = ptPreparsedData->usageItems[ptReportItem->firstUsageItem];
117
118 if (thisUsage.isRange)
119 {
120 minUsage = thisUsage.usageMinimum;
121 maxUsage = thisUsage.usageMaximum;
122 }
123 else
124 {
125 minUsage = thisUsage.usage;
126 maxUsage = thisUsage.usage;
127 }
128
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))
134 {
135 if (ptReportItem->parent < newCollection)
136 {
137 newCollection = ptReportItem->parent;
138 newReportID = iR;
139 iStatus = noErr;
140 }
141 }
142 }
143
144 if (iStatus == noErr)
145 {
146 *reportID = newReportID;
147 *collection = newCollection;
148 }
149
150 return iStatus;
151 }