1/* 2 * @APPLE_LICENSE_HEADER_START@ 3 * 4 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24 File: HIDIsButtonOrValue.c 25 26 Contains: xxx put contents here xxx 27 28 Version: xxx put version here xxx 29 30 Copyright: � 1999 by Apple Computer, Inc., all rights reserved. 31 32 File Ownership: 33 34 DRI: xxx put dri here xxx 35 36 Other Contact: xxx put other contact here xxx 37 38 Technology: xxx put technology here xxx 39 40 Writers: 41 42 (BWS) Brent Schorsch 43 44 Change History (most recent first): 45 46 <USB3> 11/1/99 BWS [2405720] We need a better check for 'bit padding' items, 47 rather than just is constant. We will check to make sure the 48 item is constant, and has no usage, or zero usage. 49 <USB2> 3/5/99 BWS [2311366] HIDIsButton should screen out constants (at least 50 until other functions, like HIDGetButtons, are fixed to be able 51 to properly skip constants) 52 <USB1> 3/5/99 BWS first checked in 53*/ 54 55#include "HIDLib.h" 56 57/* 58 *----------------------------------------------------------------------------- 59 * 60 * HIDIsButton - Is the data button(s)? 61 * 62 * Input: 63 * ptReportItem - Input/Output/Feature 64 * Output: 65 * Returns: 66 * Boolean 67 * 68 *----------------------------------------------------------------------------- 69*/ 70Boolean HIDIsButton(HIDReportItem *ptReportItem, HIDPreparsedDataRef preparsedDataRef) 71{ 72 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef; 73 74/* 75 * Disallow Null Pointers 76*/ 77 if (ptReportItem==NULL) 78 return false; 79/* 80 * Remove items that are constant and have no usage 81 */ 82 if ((ptReportItem->dataModes & kHIDDataConstantBit) == kHIDDataConstant) 83 { 84 // if has no usages, then bit filler 85 if (ptReportItem->usageItemCount == 0) 86 return false; 87 88 // also check to see if there is a usage, but it is zero 89 90 // if the first usage item is range, then check that one 91 // (we will not worry about report items with multiple zero usages, 92 // as I dont think that is a case that makes sense) 93 if (ptReportItem->firstUsageItem < ptPreparsedData->usageItemCount) 94 { 95 HIDP_UsageItem * ptUsageItem = &ptPreparsedData->usageItems[ptReportItem->firstUsageItem]; 96 97 // if it is a range usage, with both zero usages 98 if ((ptUsageItem->isRange && ptUsageItem->usageMinimum == 0 && ptUsageItem->usageMaximum == 0) && 99 // or not a range, and zero usage 100 (!ptUsageItem->isRange && ptUsageItem->usage == 0)) 101 // then this is bit filler 102 return false; 103 } 104 } 105 106/* 107 * Arrays and 1-bit Variables 108*/ 109 return (((ptReportItem->dataModes & kHIDDataArrayBit) == kHIDDataArray) 110 || (ptReportItem->globals.reportSize == 1)); 111} 112 113/* 114 *----------------------------------------------------------------------------- 115 * 116 * HIDIsVariable - Is the data variable(s)? 117 * 118 * Input: 119 * ptReportItem - Input/Output/Feature 120 * Output: 121 * Returns: 122 * Boolean 123 * 124 *----------------------------------------------------------------------------- 125*/ 126Boolean HIDIsVariable(HIDReportItem *ptReportItem, HIDPreparsedDataRef preparsedDataRef) 127{ 128 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef; 129 130/* 131 * Disallow Null Pointers 132*/ 133 if (ptReportItem==NULL) 134 return false; 135 136/* 137 * Remove items that are constant and have no usage 138 */ 139 if ((ptReportItem->dataModes & kHIDDataConstantBit) == kHIDDataConstant) 140 { 141 // if has no usages, then bit filler 142 if (ptReportItem->usageItemCount == 0) 143 return false; 144 145 // also check to see if there is a usage, but it is zero 146 147 // if the first usage item is range, then check that one 148 // (we will not worry about report items with multiple zero usages, 149 // as I dont think that is a case that makes sense) 150 if (ptReportItem->firstUsageItem < ptPreparsedData->usageItemCount) 151 { 152 HIDP_UsageItem * ptUsageItem = &ptPreparsedData->usageItems[ptReportItem->firstUsageItem]; 153 154 // if it is a range usage, with both zero usages 155 if ((ptUsageItem->isRange && ptUsageItem->usageMinimum == 0 && ptUsageItem->usageMaximum == 0) && 156 // or not a range, and zero usage 157 (!ptUsageItem->isRange && ptUsageItem->usage == 0)) 158 // then this is bit filler 159 return false; 160 } 161 } 162 163/* 164 * Multi-bit Variables 165*/ 166 return (((ptReportItem->dataModes & kHIDDataArrayBit) != kHIDDataArray) 167 && (ptReportItem->globals.reportSize != 1)); 168} 169