|
|
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: HIDSetUsageValue.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: * HIDSetUsageValue - 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 HIDSetUsageValue(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: int iStart; ! 90: int iReportItem; ! 91: UInt32 iUsageIndex; ! 92: Boolean bIncompatibleReport = false; ! 93: /* ! 94: * Disallow Null Pointers ! 95: */ ! 96: if ((ptPreparsedData == NULL) ! 97: || (psReport == NULL)) ! 98: return kHIDNullPointerErr; ! 99: if (ptPreparsedData->hidTypeIfValid != kHIDOSType) ! 100: return kHIDInvalidPreparsedDataErr; ! 101: /* ! 102: * The Collection must be in range ! 103: */ ! 104: if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount)) ! 105: return kHIDBadParameterErr; ! 106: /* ! 107: * Search only the scope of the Collection specified ! 108: * Go through the ReportItems ! 109: * Filter on ReportType and usagePage ! 110: */ ! 111: ptCollection = &ptPreparsedData->collections[iCollection]; ! 112: for (iR=0; iR<ptCollection->reportItemCount; iR++) ! 113: { ! 114: iReportItem = ptCollection->firstReportItem + iR; ! 115: ptReportItem = &ptPreparsedData->reportItems[iReportItem]; ! 116: if (HIDIsVariable(ptReportItem, preparsedDataRef) ! 117: && HIDHasUsage(preparsedDataRef,ptReportItem,usagePage,usage,&iUsageIndex,NULL)) ! 118: { ! 119: /* ! 120: * This may be the proper place ! 121: * Let's check for the proper Report ID, Type, and Length ! 122: */ ! 123: iStatus = HIDCheckReport(reportType,preparsedDataRef,ptReportItem, ! 124: psReport,iReportLength); ! 125: /* ! 126: * The Report ID or Type may not match. ! 127: * This may not be an error (yet) ! 128: */ ! 129: if (iStatus == kHIDIncompatibleReportErr) ! 130: bIncompatibleReport = true; ! 131: else if (iStatus != kHIDSuccess) ! 132: return iStatus; ! 133: else ! 134: { ! 135: /* ! 136: * Write out the data ! 137: */ ! 138: iStart = ptReportItem->startBit ! 139: + (ptReportItem->globals.reportSize * iUsageIndex); ! 140: iStatus = HIDPreProcessRIValue (ptReportItem, &iUsageValue); ! 141: iStatus = HIDPutData(psReport, iReportLength, iStart, ! 142: ptReportItem->globals.reportSize, iUsageValue); ! 143: if (iStatus != kHIDSuccess) ! 144: return iStatus; ! 145: return kHIDSuccess; ! 146: } ! 147: } ! 148: } ! 149: if (bIncompatibleReport) ! 150: return kHIDIncompatibleReportErr; ! 151: return kHIDUsageNotFoundErr; ! 152: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.