2 * Copyright (c) 1998-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@
25 Contains: xxx put contents here xxx
27 Version: xxx put version here xxx
29 Copyright: © 1999 by Apple Computer, Inc., all rights reserved.
33 DRI: xxx put dri here xxx
35 Other Contact: xxx put other contact here xxx
37 Technology: xxx put technology here xxx
43 Change History (most recent first):
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
57 *------------------------------------------------------------------------------
59 * HIDGetButtons - Get the state of the buttons for a Page
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
71 * piValue - Pointer to usage Value
74 *------------------------------------------------------------------------------
77 HIDGetButtons (HIDReportType reportType
,
79 HIDUsageAndPagePtr ptUsageList
,
80 UInt32
* piUsageListLength
,
81 HIDPreparsedDataRef preparsedDataRef
,
85 HIDPreparsedDataPtr ptPreparsedData
= (HIDPreparsedDataPtr
) preparsedDataRef
;
86 HIDCollection
*ptCollection
;
87 HIDReportItem
*ptReportItem
;
93 HIDUsageAndPage tUsageAndPage
;
96 * Disallow Null Pointers
98 if ((ptPreparsedData
== NULL
)
99 || (ptUsageList
== NULL
)
100 || (piUsageListLength
== NULL
)
101 || (psReport
== NULL
))
102 return kHIDNullPointerErr
;
103 if (ptPreparsedData
->hidTypeIfValid
!= kHIDOSType
)
104 return kHIDInvalidPreparsedDataErr
;
106 * Save the UsageList size
108 iMaxUsages
= *piUsageListLength
;
109 *piUsageListLength
= 0;
111 * Search only the scope of the Collection specified
112 * Go through the ReportItems
113 * Filter on ReportType
115 ptCollection
= &ptPreparsedData
->collections
[iCollection
];
116 for (iR
=0; iR
<ptCollection
->reportItemCount
; iR
++)
118 iReportItem
= ptCollection
->firstReportItem
+ iR
;
119 ptReportItem
= &ptPreparsedData
->reportItems
[iReportItem
];
120 if ((ptReportItem
->reportType
== reportType
)
121 && HIDIsButton(ptReportItem
, preparsedDataRef
))
124 * Save Arrays and Bitmaps
126 iStart
= ptReportItem
->startBit
;
127 for (iE
=0; iE
<ptReportItem
->globals
.reportCount
; iE
++)
129 OSStatus status
= noErr
;
132 if ((ptReportItem
->dataModes
& kHIDDataArrayBit
) == kHIDDataArray
)
134 status
= HIDGetData(psReport
, iReportLength
, iStart
, ptReportItem
->globals
.reportSize
, &iValue
, false);
136 status
= HIDPostProcessRIValue (ptReportItem
, &iValue
);
137 if (status
) return status
;
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
;
147 status
= HIDGetData(psReport
, iReportLength
, iStart
, 1, &iValue
, false);
149 status
= HIDPostProcessRIValue (ptReportItem
, &iValue
);
150 if (status
) return status
;
155 HIDUsageAndPageFromIndex(preparsedDataRef
,ptReportItem
,ptReportItem
->globals
.logicalMinimum
+iE
,&tUsageAndPage
);
156 if (*piUsageListLength
>= iMaxUsages
)
157 return kHIDBufferTooSmallErr
;
158 ptUsageList
[(*piUsageListLength
)++] = tUsageAndPage
;