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@
23 File: HIDUsageAndPageFromIndex.c
25 Contains: xxx put contents here xxx
27 Version: xxx put version here xxx
29 Copyright: © 1999-2000 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
44 Change History (most recent first):
46 <USB2> 12/12/00 KH range count off by 1.
47 <USB1> 3/5/99 BWS first checked in
53 *------------------------------------------------------------------------------
55 * HIDUsageAndPageFromIndex
58 * ptPreparsedData - The Preparsed Data
59 * ptReportItem - The Report Item
60 * index - The usage Index
61 * ptUsageAndPage - The usage And Page
65 *------------------------------------------------------------------------------
67 void HIDUsageAndPageFromIndex (HIDPreparsedDataRef preparsedDataRef
,
68 HIDReportItem
*ptReportItem
, UInt32 index
,
69 HIDUsageAndPage
*ptUsageAndPage
)
71 HIDPreparsedDataPtr ptPreparsedData
= (HIDPreparsedDataPtr
) preparsedDataRef
;
72 HIDP_UsageItem
*ptUsageItem
= NULL
;
78 * Disallow NULL Pointers
80 if ((ptUsageAndPage
== NULL
) || (ptReportItem
== NULL
) || (ptPreparsedData
== NULL
))
82 ptUsageAndPage
->usagePage
= 0;
83 return; // kHIDNullPointerErr;
87 * Index through the usage Items for this ReportItem
89 iUsageItem
= ptReportItem
->firstUsageItem
;
90 for (i
=0; i
<ptReportItem
->usageItemCount
; i
++)
93 * Each usage Item is either a usage or a usage range
95 ptUsageItem
= &ptPreparsedData
->usageItems
[iUsageItem
++];
96 if (ptUsageItem
->isRange
)
100 * If the index is in the range
101 * then return the usage
102 * Otherwise adjust the index by the size of the range
104 iUsages
= ptUsageItem
->usageMaximum
- ptUsageItem
->usageMinimum
;
107 iUsages
++; // Add off by one adjustment AFTER sign correction.
110 ptUsageAndPage
->usagePage
= ptUsageItem
->usagePage
;
111 ptUsageAndPage
->usage
= ptUsageItem
->usageMinimum
+ index
;
120 * If the index is zero
121 * then return this usage
122 * Otherwise one less to index through
126 ptUsageAndPage
->usagePage
= ptUsageItem
->usagePage
;
127 ptUsageAndPage
->usage
= ptUsageItem
->usage
;
132 if (ptUsageItem
!= NULL
)
134 ptUsageAndPage
->usagePage
= ptUsageItem
->usagePage
;
135 if (ptUsageItem
->isRange
)
136 ptUsageAndPage
->usage
= ptUsageItem
->usageMaximum
;
138 ptUsageAndPage
->usage
= ptUsageItem
->usage
;