Annotation of XNU/iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDScaleUsageValue.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:           HIDScaleUsageValue.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:  * HIDScaleUsageValueIn
                     54:  *
                     55:  *      Input:
                     56:  *                       ptReportItem                  - The ReportItem in which the data resides
                     57:  *                       iValue                                - The unscaled data
                     58:  *                       piScaledValue                 - The scaled value
                     59:  *      Output:
                     60:  *                       piScaledValue                 - The scaled value
                     61:  *      Returns:
                     62:  *                       kHIDSuccess
                     63:  *
                     64:  *------------------------------------------------------------------------------
                     65: */
                     66: OSStatus HIDScaleUsageValueIn (HIDReportItem *ptReportItem, UInt32 iValue, SInt32 *piScaledValue)
                     67: {
                     68:        long int lData;
                     69:        long int lDeltaL;
                     70:        long int lDeltaP;
                     71:        long int lL, lP;
                     72:        long int lScaledData;
                     73:        long int lLMin, lLMax;
                     74: /*
                     75:  *     Disallow Null Pointers
                     76: */
                     77:        if ((ptReportItem == NULL) || (piScaledValue == NULL))
                     78:                return kHIDNullPointerErr;
                     79: /*
                     80:  *     Convert the data to Long Integer
                     81: */
                     82:        lData = iValue;
                     83: /*
                     84:  *     range check the Logical Value
                     85: */
                     86:        lLMax = ptReportItem->globals.logicalMaximum;
                     87:        lLMin = ptReportItem->globals.logicalMinimum;
                     88:        if ((lData < lLMin) || (lData > lLMax))
                     89:        {
                     90:                if ((ptReportItem->dataModes & kHIDDataNullStateBit) == kHIDDataNullState)
                     91:                        return kHIDNullStateErr;
                     92:                return kHIDValueOutOfRangeErr;
                     93:        }
                     94: /*
                     95:  *     (PhysicalValue - PhysicalMinimum)/(PhysicalMaximum - PhysicalMinimum)
                     96:  *     = (LogicalValue - LogicalMinimum)/(LogicalMaximum - LogicalMinimum)
                     97:  *
                     98:  *     Calculate the ranges
                     99:  *     Zero ranges are invalid!
                    100:  *       lDeltaL = (LogicalMaximum - LogicalMinimum)
                    101:  *       lDeltaP = (PhysicalMaximum - PhysicalMinimum)
                    102: */
                    103:        lDeltaL = lLMax - lLMin;
                    104:        lDeltaP = ptReportItem->globals.physicalMaximum - ptReportItem->globals.physicalMinimum;
                    105:        if ((lDeltaL == 0) || (lDeltaP == 0))
                    106:                return kHIDBadLogPhysValuesErr;
                    107: /*
                    108:  *     (PhysicalValue - PhysicalMinimum)/lDeltaP
                    109:  *     = (LogicalValue - LogicalMinimum)/lDeltaL
                    110:  *     lL = (LogicalValue - LogicalMinimum)
                    111: */
                    112:        lL = lData - ptReportItem->globals.logicalMinimum;
                    113: /*
                    114:  *     (PhysicalValue - PhysicalMinimum)/lDeltaP = lL/lDeltaL
                    115:  *     (PhysicalValue - PhysicalMinimum) = (lDeltaP * lL)/lDeltaL
                    116:  *     lP = (PhysicalValue - PhysicalMinimum) = (lDeltaP * lL)/lDeltaL
                    117: */
                    118:        lP = (lL* lDeltaP)/lDeltaL;
                    119: /*
                    120:  *     lP = (PhysicalValue - PhysicalMinimum)
                    121:  *     PhysicalValue = lP + PhysicalMinimum;
                    122: */
                    123:        lScaledData = lP + ptReportItem->globals.physicalMinimum;
                    124:        *piScaledValue = (int) lScaledData;
                    125:        return kHIDSuccess;
                    126: }
                    127: 
                    128: /*
                    129:  *------------------------------------------------------------------------------
                    130:  *
                    131:  * HIDScaleUsageValueOut
                    132:  *
                    133:  *      Input:
                    134:  *                       ptReportItem                  - The ReportItem in which the data will go
                    135:  *                       iValue                                - The unscaled data
                    136:  *                       piScaledValue                 - The scaled value
                    137:  *      Output:
                    138:  *                       piScaledValue                 - The scaled value
                    139:  *      Returns:
                    140:  *                       kHIDSuccess
                    141:  *
                    142:  *------------------------------------------------------------------------------
                    143: */
                    144: OSStatus HIDScaleUsageValueOut (HIDReportItem *ptReportItem, UInt32 iValue, SInt32 *piScaledValue)
                    145: {
                    146:        long int lData;
                    147:        long int lDeltaL;
                    148:        long int lDeltaP;
                    149:        long int lL, lP;
                    150:        long int lPMax, lPMin;
                    151: /*
                    152:  *     Convert the data to Long Integer
                    153: */
                    154:        lData = iValue;
                    155: /*
                    156:  *     range check the Logical Value
                    157: */
                    158:        lPMax = ptReportItem->globals.physicalMaximum;
                    159:        lPMin = ptReportItem->globals.physicalMinimum;
                    160:        if ((lData < lPMin) || (lData > lPMax))
                    161:        {
                    162:                if ((ptReportItem->dataModes & kHIDDataNullStateBit) == kHIDDataNullState)
                    163:                        return kHIDNullStateErr;
                    164:                return kHIDValueOutOfRangeErr;
                    165:        }
                    166: /*
                    167:  *     (PhysicalValue - PhysicalMinimum)/(PhysicalMaximum - PhysicalMinimum)
                    168:  *     = (LogicalValue - LogicalMinimum)/(LogicalMaximum - LogicalMinimum)
                    169:  *
                    170:  *     Calculate the ranges
                    171:  *     Zero ranges are invalid!
                    172:  *       lDeltaL = (LogicalMaximum - LogicalMinimum)
                    173:  *       lDeltaP = (PhysicalMaximum - PhysicalMinimum)
                    174: */
                    175:        lDeltaL = ptReportItem->globals.logicalMaximum - ptReportItem->globals.logicalMinimum;
                    176:        lDeltaP = ptReportItem->globals.physicalMaximum - ptReportItem->globals.physicalMinimum;
                    177:        if ((lDeltaL == 0) || (lDeltaP == 0))
                    178:                return kHIDBadLogPhysValuesErr;
                    179: /*
                    180:  *     (PhysicalValue - PhysicalMinimum)/lDeltaP
                    181:  *     = (LogicalValue - LogicalMinimum)/lDeltaL
                    182:  *     lP = (PhysicalValue - PhysicalMinimum)
                    183: */
                    184:        lP = lData - ptReportItem->globals.physicalMinimum;
                    185: /*
                    186:  *     (LogicalValue - LogicalMinimum)/lDeltaL = lP/lDeltaP
                    187:  *     (LogicalValue - LogicalMinimum)/lDeltaL = (lDeltaL * lP)/lDeltaP
                    188:  *     lL = (LogicalValue - LogicalMinimum) = (lDeltaL * lP)/lDeltaP
                    189: */
                    190:        lL = (lP* lDeltaL)/lDeltaP;
                    191: /*
                    192:  *     lL = (LogicalValue - LogicalMinimum)
                    193:  *     LogicalValue = lL + LogicalMinimum;
                    194: */
                    195:        lData = lL + ptReportItem->globals.logicalMinimum;
                    196:        *piScaledValue = (int) lData;
                    197:        return kHIDSuccess;
                    198: }

unix.superglobalmegacorp.com

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