|
|
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: HIDGetCaps.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: <USB2> 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: <USB1> 3/5/99 BWS first checked in ! 50: */ ! 51: ! 52: #include "HIDLib.h" ! 53: ! 54: /* ! 55: *------------------------------------------------------------------------------ ! 56: * ! 57: * HIDP_GetCaps ! 58: * ! 59: * Input: ! 60: * ptPreparsedData - Pre-Parsed Data ! 61: * ptCapabilities - Pointer to caller-provided structure ! 62: * Output: ! 63: * ptCapabilities - Capabilities data ! 64: * Returns: ! 65: * ! 66: *------------------------------------------------------------------------------ ! 67: */ ! 68: OSStatus HIDGetCaps(HIDPreparsedDataRef preparsedDataRef, HIDCapsPtr ptCapabilities) ! 69: { ! 70: HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef; ! 71: HIDCollection *ptCollection; ! 72: HIDReportItem *ptReportItem; ! 73: HIDReportSizes *ptReport; ! 74: int iFirstUsage; ! 75: int i; ! 76: /* ! 77: * Disallow Null Pointers ! 78: */ ! 79: ! 80: if ((ptPreparsedData == NULL) || (ptCapabilities == NULL)) ! 81: return kHIDNullPointerErr; ! 82: if (ptPreparsedData->hidTypeIfValid != kHIDOSType) ! 83: return kHIDInvalidPreparsedDataErr; ! 84: /* ! 85: * Copy the capabilities to the user ! 86: * Collection Capabilities ! 87: */ ! 88: ! 89: ptCollection = &ptPreparsedData->collections[1]; ! 90: ptCapabilities->usagePage = ptCollection->usagePage; ! 91: iFirstUsage = ptCollection->firstUsageItem; ! 92: ptCapabilities->usage = ptPreparsedData->usageItems[iFirstUsage].usage; ! 93: ptCapabilities->numberCollectionNodes = ptPreparsedData->collectionCount; ! 94: /* ! 95: * Report Capabilities Summary ! 96: */ ! 97: ! 98: ptCapabilities->inputReportByteLength = 0; ! 99: ptCapabilities->outputReportByteLength = 0; ! 100: ptCapabilities->featureReportByteLength = 0; ! 101: for (i=0; i<ptPreparsedData->reportCount; i++) ! 102: { ! 103: ptReport = &ptPreparsedData->reports[i]; ! 104: if (ptCapabilities->inputReportByteLength < ptReport->inputBitCount) ! 105: ptCapabilities->inputReportByteLength = ptReport->inputBitCount; ! 106: if (ptCapabilities->outputReportByteLength < ptReport->outputBitCount) ! 107: ptCapabilities->outputReportByteLength = ptReport->outputBitCount; ! 108: if (ptCapabilities->featureReportByteLength < ptReport->featureBitCount) ! 109: ptCapabilities->featureReportByteLength = ptReport->featureBitCount; ! 110: } ! 111: ptCapabilities->inputReportByteLength = (ptCapabilities->inputReportByteLength + 7) /8; ! 112: ptCapabilities->outputReportByteLength = (ptCapabilities->outputReportByteLength + 7)/8; ! 113: ptCapabilities->featureReportByteLength = (ptCapabilities->featureReportByteLength + 7)/8; ! 114: /* ! 115: * Sum the capabilities types ! 116: */ ! 117: ! 118: ptCapabilities->numberInputButtonCaps = 0; ! 119: ptCapabilities->numberInputValueCaps = 0; ! 120: ptCapabilities->numberOutputButtonCaps = 0; ! 121: ptCapabilities->numberOutputValueCaps = 0; ! 122: ptCapabilities->numberFeatureButtonCaps = 0; ! 123: ptCapabilities->numberFeatureValueCaps = 0; ! 124: for (i=0; i<ptPreparsedData->reportItemCount; i++) ! 125: { ! 126: ptReportItem = &ptPreparsedData->reportItems[i]; ! 127: switch (ptReportItem->reportType) ! 128: { ! 129: case kHIDInputReport: ! 130: if (HIDIsButton(ptReportItem, preparsedDataRef)) ! 131: ptCapabilities->numberInputButtonCaps += ptReportItem->usageItemCount; ! 132: else if (HIDIsVariable(ptReportItem, preparsedDataRef)) ! 133: ptCapabilities->numberInputValueCaps += ptReportItem->usageItemCount; ! 134: break; ! 135: case kHIDOutputReport: ! 136: if (HIDIsButton(ptReportItem, preparsedDataRef)) ! 137: ptCapabilities->numberOutputButtonCaps += ptReportItem->usageItemCount; ! 138: else if (HIDIsVariable(ptReportItem, preparsedDataRef)) ! 139: ptCapabilities->numberOutputValueCaps += ptReportItem->usageItemCount; ! 140: break; ! 141: case kHIDFeatureReport: ! 142: if (HIDIsButton(ptReportItem, preparsedDataRef)) ! 143: ptCapabilities->numberFeatureButtonCaps += ptReportItem->usageItemCount; ! 144: else if (HIDIsVariable(ptReportItem, preparsedDataRef)) ! 145: ptCapabilities->numberFeatureValueCaps += ptReportItem->usageItemCount; ! 146: break; ! 147: } ! 148: } ! 149: return kHIDSuccess; ! 150: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.