Annotation of XNU/iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDIsButtonOrValue.c, revision 1.1.1.1

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:           HIDIsButtonOrValue.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.
                     48:          <USB2>          3/5/99        BWS             [2311366]  HIDIsButton should screen out constants (at least
                     49:                                                                        until other functions, like HIDGetButtons, are fixed to be able
                     50:                                                                        to properly skip constants)
                     51:          <USB1>          3/5/99        BWS             first checked in
                     52: */
                     53: 
                     54: #include "HIDLib.h"
                     55: 
                     56: /*
                     57:  *-----------------------------------------------------------------------------
                     58:  *
                     59:  * HIDIsButton - Is the data button(s)?
                     60:  *
                     61:  *      Input:
                     62:  *                       ptReportItem                  - Input/Output/Feature
                     63:  *      Output:
                     64:  *      Returns:
                     65:  *                       Boolean
                     66:  *
                     67:  *-----------------------------------------------------------------------------
                     68: */
                     69: Boolean HIDIsButton(HIDReportItem *ptReportItem, HIDPreparsedDataRef preparsedDataRef)
                     70: {
                     71:        HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
                     72: 
                     73: /*
                     74:  *     Disallow Null Pointers
                     75: */
                     76:        if (ptReportItem==NULL)
                     77:                return false;
                     78: /*
                     79:  *     Remove items that are constant and have no usage
                     80:  */
                     81:        if ((ptReportItem->dataModes & kHIDDataConstantBit) == kHIDDataConstant)
                     82:        {
                     83:                // if has no usages, then bit filler
                     84:                if (ptReportItem->usageItemCount == 0)
                     85:                        return false;
                     86:                
                     87:                // also check to see if there is a usage, but it is zero
                     88:                
                     89:                // if the first usage item is range, then check that one
                     90:                // (we will not worry about report items with multiple zero usages, 
                     91:                //  as I dont think that is a case that makes sense)
                     92:                if (ptReportItem->firstUsageItem < ptPreparsedData->usageItemCount)
                     93:                {
                     94:                        HIDP_UsageItem * ptUsageItem = &ptPreparsedData->usageItems[ptReportItem->firstUsageItem];
                     95:                        
                     96:                        // if it is a range usage, with both zero usages 
                     97:                        if ((ptUsageItem->isRange && ptUsageItem->usageMinimum == 0 && ptUsageItem->usageMaximum == 0) &&
                     98:                                // or not a range, and zero usage
                     99:                                (!ptUsageItem->isRange && ptUsageItem->usage == 0))
                    100:                                // then this is bit filler
                    101:                                return false;
                    102:                }
                    103:        }
                    104: 
                    105: /*
                    106:  *     Arrays and 1-bit Variables
                    107: */
                    108:        return (((ptReportItem->dataModes & kHIDDataArrayBit) == kHIDDataArray)
                    109:           || (ptReportItem->globals.reportSize == 1));
                    110: }
                    111: 
                    112: /*
                    113:  *-----------------------------------------------------------------------------
                    114:  *
                    115:  * HIDIsVariable - Is the data variable(s)?
                    116:  *
                    117:  *      Input:
                    118:  *                       ptReportItem                  - Input/Output/Feature
                    119:  *      Output:
                    120:  *      Returns:
                    121:  *                       Boolean
                    122:  *
                    123:  *-----------------------------------------------------------------------------
                    124: */
                    125: Boolean HIDIsVariable(HIDReportItem *ptReportItem, HIDPreparsedDataRef preparsedDataRef)
                    126: {
                    127:        HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
                    128: 
                    129: /*
                    130:  *     Disallow Null Pointers
                    131: */
                    132:        if (ptReportItem==NULL)
                    133:                return false;
                    134: 
                    135: /*
                    136:  *     Remove items that are constant and have no usage
                    137:  */
                    138:        if ((ptReportItem->dataModes & kHIDDataConstantBit) == kHIDDataConstant)
                    139:        {
                    140:                // if has no usages, then bit filler
                    141:                if (ptReportItem->usageItemCount == 0)
                    142:                        return false;
                    143:                
                    144:                // also check to see if there is a usage, but it is zero
                    145:                
                    146:                // if the first usage item is range, then check that one
                    147:                // (we will not worry about report items with multiple zero usages, 
                    148:                //  as I dont think that is a case that makes sense)
                    149:                if (ptReportItem->firstUsageItem < ptPreparsedData->usageItemCount)
                    150:                {
                    151:                        HIDP_UsageItem * ptUsageItem = &ptPreparsedData->usageItems[ptReportItem->firstUsageItem];
                    152:                        
                    153:                        // if it is a range usage, with both zero usages 
                    154:                        if ((ptUsageItem->isRange && ptUsageItem->usageMinimum == 0 && ptUsageItem->usageMaximum == 0) &&
                    155:                                // or not a range, and zero usage
                    156:                                (!ptUsageItem->isRange && ptUsageItem->usage == 0))
                    157:                                // then this is bit filler
                    158:                                return false;
                    159:                }
                    160:        }
                    161: 
                    162: /*
                    163:  *     Multi-bit Variables
                    164: */
                    165:        return (((ptReportItem->dataModes & kHIDDataArrayBit) != kHIDDataArray)
                    166:           && (ptReportItem->globals.reportSize != 1));
                    167: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.