|
|
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: HIDGetButtons.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> 4/7/99 BWS Add support for reversed report items
50: <USB2> 3/5/99 BWS [2311349] iteration broken, passing wrong value
51: <USB1> 3/5/99 BWS first checked in
52: */
53:
54: #include "HIDLib.h"
55:
56: /*
57: *------------------------------------------------------------------------------
58: *
59: * HIDGetButtons - Get the state of the buttons for a Page
60: *
61: * Input:
62: * reportType - HIDP_Input, HIDP_Output, HIDP_Feature
63: * usagePage - Page Criteria or zero
64: * iCollection - Collection Criteria or zero
65: * piUsageList - Usages for pressed buttons
66: * piUsageListLength - Max entries in UsageList
67: * ptPreparsedData - Pre-Parsed Data
68: * psReport - An HID Report
69: * iReportLength - The length of the Report
70: * Output:
71: * piValue - Pointer to usage Value
72: * Returns:
73: *
74: *------------------------------------------------------------------------------
75: */
76: OSStatus
77: HIDGetButtons (HIDReportType reportType,
78: UInt32 iCollection,
79: HIDUsageAndPagePtr ptUsageList,
80: UInt32 * piUsageListLength,
81: HIDPreparsedDataRef preparsedDataRef,
82: void * psReport,
83: UInt32 iReportLength)
84: {
85: HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
86: HIDCollection *ptCollection;
87: HIDReportItem *ptReportItem;
88: int iR, iE;
89: long iValue;
90: int iStart;
91: int iReportItem;
92: int iMaxUsages;
93: HIDUsageAndPage tUsageAndPage;
94:
95: /*
96: * Disallow Null Pointers
97: */
98: if ((ptPreparsedData == NULL)
99: || (ptUsageList == NULL)
100: || (piUsageListLength == NULL)
101: || (psReport == NULL))
102: return kHIDNullPointerErr;
103: if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
104: return kHIDInvalidPreparsedDataErr;
105: /*
106: * Save the UsageList size
107: */
108: iMaxUsages = *piUsageListLength;
109: *piUsageListLength = 0;
110: /*
111: * Search only the scope of the Collection specified
112: * Go through the ReportItems
113: * Filter on ReportType
114: */
115: ptCollection = &ptPreparsedData->collections[iCollection];
116: for (iR=0; iR<ptCollection->reportItemCount; iR++)
117: {
118: iReportItem = ptCollection->firstReportItem + iR;
119: ptReportItem = &ptPreparsedData->reportItems[iReportItem];
120: if ((ptReportItem->reportType == reportType)
121: && HIDIsButton(ptReportItem, preparsedDataRef))
122: {
123: /*
124: * Save Arrays and Bitmaps
125: */
126: iStart = ptReportItem->startBit;
127: for (iE=0; iE<ptReportItem->globals.reportCount; iE++)
128: {
129: OSStatus status = noErr;
130: iValue = 0;
131:
132: if ((ptReportItem->dataModes & kHIDDataArrayBit) == kHIDDataArray)
133: {
134: status = HIDGetData(psReport, iReportLength, iStart, ptReportItem->globals.reportSize, &iValue, false);
135: if (!status)
136: status = HIDPostProcessRIValue (ptReportItem, &iValue);
137: if (status) return status;
138:
139: iStart += ptReportItem->globals.reportSize;
140: HIDUsageAndPageFromIndex(preparsedDataRef,ptReportItem,ptReportItem->globals.logicalMinimum+iE,&tUsageAndPage);
141: if (*piUsageListLength >= iMaxUsages)
142: return kHIDBufferTooSmallErr;
143: ptUsageList[(*piUsageListLength)++] = tUsageAndPage;
144: }
145: else
146: {
147: status = HIDGetData(psReport, iReportLength, iStart, 1, &iValue, false);
148: if (!status)
149: status = HIDPostProcessRIValue (ptReportItem, &iValue);
150: if (status) return status;
151:
152: iStart++;
153: if (iValue != 0)
154: {
155: HIDUsageAndPageFromIndex(preparsedDataRef,ptReportItem,ptReportItem->globals.logicalMinimum+iE,&tUsageAndPage);
156: if (*piUsageListLength >= iMaxUsages)
157: return kHIDBufferTooSmallErr;
158: ptUsageList[(*piUsageListLength)++] = tUsageAndPage;
159: }
160: }
161: }
162: }
163: }
164: return kHIDSuccess;
165: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.