Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | /* * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * The contents of this file constitute Original Code as defined in and * are subject to the Apple Public Source License Version 1.1 (the * "License"). You may not use this file except in compliance with the * License. Please obtain a copy of the License at * http://www.apple.com/publicsource and read it before using this file. * * This Original Code and all software distributed under the License are * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* File: HIDGetUsageValueArray.c Contains: xxx put contents here xxx Version: xxx put version here xxx Copyright: © 1999-2001 by Apple Computer, Inc., all rights reserved. File Ownership: DRI: xxx put dri here xxx Other Contact: xxx put other contact here xxx Technology: xxx put technology here xxx Writers: (KH) Keithen Hayenga (BWS) Brent Schorsch Change History (most recent first): <USB5> 1/18/01 KH Fix for complex descriptors only needed for buttons. <USB4> 3/24/00 KH Complex report descriptors could lead to reporting kHIDUsageNotFoundErr's as kHIDIncompatibleReportErr's instead. <USB3> 11/1/99 BWS [2405720] We need a better check for 'bit padding' items, rather than just is constant. We will check to make sure the item is constant, and has no usage, or zero usage. This means we need to pass an additional parameter to some internal functions <USB2> 4/7/99 BWS Add support for reversed report items <USB1> 3/5/99 BWS first checked in */ #include "HIDLib.h" /* *------------------------------------------------------------------------------ * * HIDP_GetUsageValueArray - Get the values for a usage * * Input: * reportType - HIDP_Input, HIDP_Output, HIDP_Feature * usagePage - Page Criteria * iCollection - Collection Criteria or zero * usage - usage Criteria * psBuffer - Pointer to usage Buffer * iByteLength - Length of usage Buffer * ptPreparsedData - Pre-Parsed Data * psReport - An HID Report * iReportLength - The length of the Report * Output: * piValue - Pointer to usage Value * Returns: * *------------------------------------------------------------------------------ */ OSStatus HIDGetUsageValueArray(HIDReportType reportType, HIDUsage usagePage, UInt32 iCollection, HIDUsage usage, UInt8 *psUsageBuffer, UInt32 iByteLength, HIDPreparsedDataRef preparsedDataRef, void *psReport, UInt32 iReportLength) { HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef; HIDCollection *ptCollection; HIDReportItem *ptReportItem; OSStatus iStatus; int i; int iR; long iValue; int iStart; int iReportItem; UInt32 iUsageIndex; UInt32 iCount; int byteCount; Boolean bIncompatibleReport = false; /* * Disallow Null Pointers */ if ((ptPreparsedData == NULL) || (psUsageBuffer == NULL) || (psReport == NULL)) return kHIDNullPointerErr; if (ptPreparsedData->hidTypeIfValid != kHIDOSType) return kHIDInvalidPreparsedDataErr; /* * The Collection must be in range */ if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount)) return kHIDBadParameterErr; /* * Search only the scope of the Collection specified * Go through the ReportItems * Filter on ReportType and usagePage */ ptCollection = &ptPreparsedData->collections[iCollection]; for (iR=0; iR<ptCollection->reportItemCount; iR++) { iReportItem = ptCollection->firstReportItem + iR; ptReportItem = &ptPreparsedData->reportItems[iReportItem]; if (HIDIsVariable(ptReportItem, preparsedDataRef) && HIDHasUsage(preparsedDataRef,ptReportItem,usagePage,usage,&iUsageIndex,&iCount)) { /* * This may be the proper data to get * Let's check for the proper Report ID, Type, and Length */ iStatus = HIDCheckReport(reportType,preparsedDataRef,ptReportItem, psReport,iReportLength); /* * The Report ID or Type may not match. * This may not be an error (yet) */ if (iStatus == kHIDIncompatibleReportErr) bIncompatibleReport = true; else if (iStatus != kHIDSuccess) return iStatus; else { /* * Disallow single count variables * Count is set by HasUsage */ if (iCount <= 1) return kHIDNotValueArrayErr; /* * Get the data */ iStart = ptReportItem->startBit + (ptReportItem->globals.reportSize * iUsageIndex); byteCount = (ptReportItem->globals.reportSize * iCount + 7)/8; if (byteCount > iByteLength) byteCount = iByteLength; for (i=0; i<byteCount; i++) { iStatus = HIDGetData(psReport, iReportLength, iStart, 8, &iValue, ((ptReportItem->globals.logicalMinimum < 0) ||(ptReportItem->globals.logicalMaximum < 0))); if (!iStatus) iStatus = HIDPostProcessRIValue (ptReportItem, &iValue); if (iStatus != kHIDSuccess) return iStatus; *psUsageBuffer++ = (char) iValue; iStart += 8; } return kHIDSuccess; } } } if (bIncompatibleReport) return kHIDIncompatibleReportErr; return kHIDUsageNotFoundErr; } |