|
|
1.1 root 1: /*
2: * Copyright (c) 1998-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: HIDGetButtonCaps.c
24:
25: Contains: xxx put contents here xxx
26:
27: Version: xxx put version here xxx
28:
29: Copyright: � 1999 by Apple Computer, Inc., all rights reserved.
30:
31: File Ownership:
32:
33: DRI: xxx put dri here xxx
34:
35: Other Contact: xxx put other contact here xxx
36:
37: Technology: xxx put technology here xxx
38:
39: Writers:
40:
41: (BWS) Brent Schorsch
42:
43: Change History (most recent first):
44:
45: <USB4> 11/1/99 BWS [2405720] We need a better check for 'bit padding' items,
46: rather than just is constant. We will check to make sure the
47: item is constant, and has no usage, or zero usage. This means we
48: need to pass an additional parameter to some internal functions
49: <USB3> 5/3/99 BWS We were not setting isStringRange, isDesignatorRange, and
50: isAbsolute
51: <USB2> 3/7/99 BWS When range/notRange were made a union, we missed this case where
52: they were both being set indescriminately
53: <USB1> 3/5/99 BWS first checked in
54: */
55:
56: #include "HIDLib.h"
57:
58: /*
59: *------------------------------------------------------------------------------
60: *
61: * HIDGetSpecificButtonCaps - Get the binary values for a report type
62: *
63: * Input:
64: * reportType - HIDP_Input, HIDP_Output, HIDP_Feature
65: * usagePage - Page Criteria or zero
66: * iCollection - Collection Criteria or zero
67: * usage - usage Criteria or zero
68: * buttonCaps - ButtonCaps Array
69: * piButtonCapsLength - Maximum Entries
70: * ptPreparsedData - Pre-Parsed Data
71: * Output:
72: * piButtonCapsLength - Entries Populated
73: * Returns:
74: *
75: *------------------------------------------------------------------------------
76: */
77: OSStatus HIDGetSpecificButtonCaps(HIDReportType reportType,
78: HIDUsage usagePage,
79: UInt32 iCollection,
80: HIDUsage usage,
81: HIDButtonCapsPtr buttonCaps,
82: UInt32 *piButtonCapsLength,
83: HIDPreparsedDataRef preparsedDataRef)
84: {
85: HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
86: HIDCollection *ptCollection;
87: HIDCollection *ptParent;
88: HIDReportItem *ptReportItem;
89: HIDP_UsageItem *ptUsageItem;
90: HIDStringItem *ptStringItem;
91: HIDDesignatorItem *ptDesignatorItem;
92: HIDP_UsageItem *ptFirstCollectionUsageItem;
93: HIDButtonCaps *ptCapability;
94: int iR, iU;
95: int parent;
96: int iReportItem, iUsageItem;
97: int iMaxCaps;
98: UInt32 startBit;
99: /*
100: * Disallow Null Pointers
101: */
102: if ((buttonCaps == NULL)
103: || (piButtonCapsLength == NULL)
104: || (ptPreparsedData == NULL))
105: return kHIDNullPointerErr;
106: if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
107: return kHIDInvalidPreparsedDataErr;
108: /*
109: * Save the buffer size
110: */
111: iMaxCaps = *piButtonCapsLength;
112: *piButtonCapsLength = 0;
113: /*
114: * The Collection must be in range
115: */
116: if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount))
117: return kHIDBadParameterErr;
118: /*
119: * Search only the scope of the Collection specified
120: */
121: ptCollection = &ptPreparsedData->collections[iCollection];
122: for (iR=0; iR<ptCollection->reportItemCount; iR++)
123: {
124: iReportItem = ptCollection->firstReportItem + iR;
125: ptReportItem = &ptPreparsedData->reportItems[iReportItem];
126: /*
127: * Search only reports of the proper type
128: */
129: if ((ptReportItem->reportType == reportType)
130: && HIDIsButton(ptReportItem, preparsedDataRef))
131: {
132: startBit = ptReportItem->startBit;
133: /*
134: * Search the usages
135: */
136: for (iU=0; iU<ptReportItem->usageItemCount; iU++)
137: {
138: /*
139: * Copy all usages if the usage above is zero
140: * or copy all that are "match"
141: */
142: iUsageItem = ptReportItem->firstUsageItem + iU;
143: ptUsageItem = &ptPreparsedData->usageItems[iUsageItem];
144:
145: // �� we assume there is a 1-1 corresponence between usage items, string items, and designator items
146: // ���this is not necessarily the case, but its better than nothing
147: ptStringItem = &ptPreparsedData->stringItems[ptReportItem->firstStringItem + iU];
148: ptDesignatorItem = &ptPreparsedData->desigItems[ptReportItem->firstDesigItem + iU];
149:
150: if (HIDUsageInRange(ptUsageItem,usagePage,usage))
151: {
152: /*
153: * Only copy if there's room
154: */
155: if (*piButtonCapsLength >= iMaxCaps)
156: return kHIDBufferTooSmallErr;
157: ptCapability = &buttonCaps[(*piButtonCapsLength)++];
158: /*
159: * Populate the Capability Structure
160: */
161: parent = ptReportItem->parent;
162: ptParent = &ptPreparsedData->collections[parent];
163: ptFirstCollectionUsageItem
164: = &ptPreparsedData->usageItems[ptParent->firstUsageItem];
165: ptCapability->collection = parent;
166: ptCapability->collectionUsagePage = ptParent->usagePage;
167: ptCapability->collectionUsage = ptFirstCollectionUsageItem->usage;
168: ptCapability->bitField = ptReportItem->dataModes;
169: ptCapability->reportID = ptReportItem->globals.reportID;
170: ptCapability->usagePage = ptUsageItem->usagePage;
171:
172: ptCapability->isStringRange = false; // �� todo: set this and stringMin,stringMax,stringIndex
173: ptCapability->isDesignatorRange = false; // �� todo: set this and designatorMin,designatorMax,designatorIndex
174: ptCapability->isAbsolute = !(ptReportItem->dataModes & kHIDDataRelative);
175:
176: ptCapability->isRange = ptUsageItem->isRange;
177: if (ptUsageItem->isRange)
178: {
179: ptCapability->u.range.usageMin = ptUsageItem->usageMinimum;
180: ptCapability->u.range.usageMax = ptUsageItem->usageMaximum;
181: }
182: else
183: ptCapability->u.notRange.usage = ptUsageItem->usage;
184:
185: // if there really are that many items
186: if (iU < ptReportItem->stringItemCount)
187: {
188: ptCapability->isStringRange = ptStringItem->isRange;
189:
190: if (ptStringItem->isRange)
191: {
192: ptCapability->u.range.stringMin = ptStringItem->minimum;
193: ptCapability->u.range.stringMax = ptStringItem->maximum;
194: }
195: else
196: ptCapability->u.notRange.stringIndex = ptStringItem->index;
197: }
198: // default, clear it
199: else
200: {
201: ptCapability->isStringRange = false;
202: ptCapability->u.notRange.stringIndex = 0;
203: }
204:
205: // if there really are that many items
206: if (iU < ptReportItem->desigItemCount)
207: {
208: ptCapability->isDesignatorRange = ptDesignatorItem->isRange;
209:
210: if (ptDesignatorItem->isRange)
211: {
212: ptCapability->u.range.designatorMin = ptDesignatorItem->minimum;
213: ptCapability->u.range.designatorMax = ptDesignatorItem->maximum;
214: }
215: else
216: ptCapability->u.notRange.designatorIndex = ptDesignatorItem->index;
217: }
218: // default, clear it
219: else
220: {
221: ptCapability->isDesignatorRange = false;
222: ptCapability->u.notRange.designatorIndex = 0;
223: }
224: ptCapability->startBit = startBit;
225: }
226: startBit += (ptReportItem->globals.reportSize * ptReportItem->globals.reportCount);
227: }
228: }
229: }
230: return kHIDSuccess;
231: }
232:
233: /*
234: *------------------------------------------------------------------------------
235: *
236: * HIDGetButtonCaps - Get the binary values for a report type
237: *
238: * Input:
239: * reportType - HIDP_Input, HIDP_Output, HIDP_Feature
240: * buttonCaps - ButtonCaps Array
241: * piButtonCapsLength - Maximum Entries
242: * ptPreparsedData - Pre-Parsed Data
243: * Output:
244: * piButtonCapsLength - Entries Populated
245: * Returns:
246: *
247: *------------------------------------------------------------------------------
248: */
249: OSStatus HIDGetButtonCaps(HIDReportType reportType,
250: HIDButtonCapsPtr buttonCaps,
251: UInt32 *piButtonCapsLength,
252: HIDPreparsedDataRef preparsedDataRef)
253: {
254: return HIDGetSpecificButtonCaps(reportType,0,0,0,buttonCaps,
255: piButtonCapsLength,preparsedDataRef);
256: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.