|
|
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: HIDSetScaledUsageValue.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: <USB3> 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: <USB2> 4/7/99 BWS Add support for reversed report items
50: <USB1> 3/5/99 BWS first checked in
51: */
52:
53: #include "HIDLib.h"
54:
55: /*
56: *------------------------------------------------------------------------------
57: *
58: * HIDSetScaledUsageValue - Set the value for a usage
59: *
60: * Input:
61: * reportType - HIDP_Input, HIDP_Output, HIDP_Feature
62: * usagePage - Page Criteria or zero
63: * iCollection - Collection Criteria or zero
64: * usage - usage Criteria or zero
65: * iValue - The usage Value
66: * ptPreparsedData - Pre-Parsed Data
67: * psReport - An HID Report
68: * iReportLength - The length of the Report
69: * Output:
70: * piValue - Pointer to usage Value
71: * Returns:
72: *
73: *------------------------------------------------------------------------------
74: */
75: OSStatus HIDSetScaledUsageValue(HIDReportType reportType,
76: HIDUsage usagePage,
77: UInt32 iCollection,
78: HIDUsage usage,
79: SInt32 iUsageValue,
80: HIDPreparsedDataRef preparsedDataRef,
81: void *psReport,
82: ByteCount iReportLength)
83: {
84: HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
85: HIDCollection *ptCollection;
86: HIDReportItem *ptReportItem;
87: OSStatus iStatus;
88: int iR;
89: SInt32 data;
90: int iStart;
91: int iReportItem;
92: UInt32 iUsageIndex;
93: Boolean bIncompatibleReport = false;
94: /*
95: * Disallow Null Pointers
96: */
97: if ((ptPreparsedData == NULL)
98: || (psReport == NULL))
99: return kHIDNullPointerErr;
100: if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
101: return kHIDInvalidPreparsedDataErr;
102: /*
103: * The Collection must be in range
104: */
105: if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount))
106: return kHIDBadParameterErr;
107: /*
108: * Search only the scope of the Collection specified
109: * Go through the ReportItems
110: * Filter on ReportType and usagePage
111: */
112: ptCollection = &ptPreparsedData->collections[iCollection];
113: for (iR=0; iR<ptCollection->reportItemCount; iR++)
114: {
115: iReportItem = ptCollection->firstReportItem + iR;
116: ptReportItem = &ptPreparsedData->reportItems[iReportItem];
117: if ((ptReportItem->reportType == reportType)
118: && HIDIsVariable(ptReportItem, preparsedDataRef)
119: && HIDHasUsage(preparsedDataRef,ptReportItem,usagePage,usage,&iUsageIndex,NULL))
120: {
121: /*
122: * This may be the proper place to write data
123: * Let's check for the proper Report ID, Type, and Length
124: */
125: iStatus = HIDCheckReport(reportType,preparsedDataRef,ptReportItem,psReport,iReportLength);
126: /*
127: * The Report ID or Type may not match.
128: * This may not be an error (yet)
129: */
130: if (iStatus == kHIDIncompatibleReportErr)
131: bIncompatibleReport = true;
132: else if (iStatus != kHIDSuccess)
133: return iStatus;
134: else
135: {
136: iStatus = HIDScaleUsageValueOut(ptReportItem,iUsageValue,&data);
137: if (iStatus != kHIDSuccess)
138: return iStatus;
139: iStart = ptReportItem->startBit + (ptReportItem->globals.reportSize * iUsageIndex);
140: iStatus = HIDPreProcessRIValue (ptReportItem, &data);
141: iStatus = HIDPutData(psReport, iReportLength, iStart, ptReportItem->globals.reportSize, data);
142: if (iStatus != kHIDSuccess)
143: return iStatus;
144: return kHIDSuccess;
145: }
146: }
147: }
148: if (bIncompatibleReport)
149: return kHIDIncompatibleReportErr;
150: return kHIDUsageNotFoundErr;
151: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.