|
|
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: HIDUsageAndPageFromIndex.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: <USB1> 3/5/99 BWS first checked in ! 46: */ ! 47: ! 48: #include "HIDLib.h" ! 49: ! 50: /* ! 51: *------------------------------------------------------------------------------ ! 52: * ! 53: * HIDUsageAndPageFromIndex ! 54: * ! 55: * Input: ! 56: * ptPreparsedData - The Preparsed Data ! 57: * ptReportItem - The Report Item ! 58: * index - The usage Index ! 59: * ptUsageAndPage - The usage And Page ! 60: * Output: ! 61: * Returns: ! 62: * ! 63: *------------------------------------------------------------------------------ ! 64: */ ! 65: void HIDUsageAndPageFromIndex (HIDPreparsedDataRef preparsedDataRef, ! 66: HIDReportItem *ptReportItem, UInt32 index, ! 67: HIDUsageAndPage *ptUsageAndPage) ! 68: { ! 69: HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef; ! 70: HIDP_UsageItem *ptUsageItem = NULL; ! 71: int iUsageItem; ! 72: int iUsages; ! 73: int i; ! 74: ! 75: /* ! 76: * Disallow NULL Pointers ! 77: */ ! 78: if ((ptUsageAndPage == NULL) || (ptReportItem == NULL) || (ptPreparsedData == NULL)) ! 79: { ! 80: ptUsageAndPage->usagePage = 0; ! 81: return; // kHIDNullPointerErr; ! 82: } ! 83: ! 84: /* ! 85: * Index through the usage Items for this ReportItem ! 86: */ ! 87: iUsageItem = ptReportItem->firstUsageItem; ! 88: for (i=0; i<ptReportItem->usageItemCount; i++) ! 89: { ! 90: /* ! 91: * Each usage Item is either a usage or a usage range ! 92: */ ! 93: ptUsageItem = &ptPreparsedData->usageItems[iUsageItem++]; ! 94: if (ptUsageItem->isRange) ! 95: { ! 96: /* ! 97: * For usage Ranges ! 98: * If the index is in the range ! 99: * then return the usage ! 100: * Otherwise adjust the index by the size of the range ! 101: */ ! 102: iUsages = ptUsageItem->usageMaximum - ptUsageItem->usageMinimum + 1; ! 103: if (iUsages < 0) ! 104: iUsages = -iUsages; ! 105: if (iUsages > index) ! 106: { ! 107: ptUsageAndPage->usagePage = ptUsageItem->usagePage; ! 108: ptUsageAndPage->usage = ptUsageItem->usageMinimum + index; ! 109: return; ! 110: } ! 111: index -= iUsages; ! 112: } ! 113: else ! 114: { ! 115: /* ! 116: * For Usages ! 117: * If the index is zero ! 118: * then return this usage ! 119: * Otherwise one less to index through ! 120: */ ! 121: if (index-- == 0) ! 122: { ! 123: ptUsageAndPage->usagePage = ptUsageItem->usagePage; ! 124: ptUsageAndPage->usage = ptUsageItem->usage; ! 125: return; ! 126: } ! 127: } ! 128: } ! 129: if (ptUsageItem != NULL) ! 130: { ! 131: ptUsageAndPage->usagePage = ptUsageItem->usagePage; ! 132: if (ptUsageItem->isRange) ! 133: ptUsageAndPage->usage = ptUsageItem->usageMaximum; ! 134: else ! 135: ptUsageAndPage->usage = ptUsageItem->usage; ! 136: } ! 137: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.