Annotation of XNU/iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDGetButtonsOnPage.c, revision 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:           HIDGetButtonsOnPage.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:          <USB4>         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:          <USB3>         5/26/99        BWS             We are not checking the usage page for bitmapped buttons! This
        !            50:                                                                        caused the Wingman Extreme to get the tilt button on the user
        !            51:                                                                        page confused with the first button on the button page.
        !            52:          <USB2>          4/7/99        BWS             Add support for reversed report items
        !            53:          <USB1>          3/5/99        BWS             first checked in
        !            54: */
        !            55: 
        !            56: #include "HIDLib.h"
        !            57: 
        !            58: /*
        !            59:  *------------------------------------------------------------------------------
        !            60:  *
        !            61:  * HIDGetButtonsOnPage - Get the state of the buttons for a Page
        !            62:  *
        !            63:  *      Input:
        !            64:  *                       reportType               - HIDP_Input, HIDP_Output, HIDP_Feature
        !            65:  *                       usagePage                        - Page Criteria or zero
        !            66:  *                       iCollection                   - Collection Criteria or zero
        !            67:  *                       piUsageList                   - Usages for pressed buttons
        !            68:  *                       piUsageListLength             - Max entries in UsageList
        !            69:  *                       ptPreparsedData               - Pre-Parsed Data
        !            70:  *                       psReport                              - An HID Report
        !            71:  *                       iReportLength                 - The length of the Report
        !            72:  *      Output:
        !            73:  *                       piValue                               - Pointer to usage Value
        !            74:  *      Returns:
        !            75:  *
        !            76:  *------------------------------------------------------------------------------
        !            77: */
        !            78: OSStatus HIDGetButtonsOnPage(HIDReportType reportType,
        !            79:                                                   HIDUsage usagePage,
        !            80:                                                   UInt32 iCollection,
        !            81:                                                   HIDUsage *piUsageList,
        !            82:                                                   UInt32 *piUsageListLength,
        !            83:                                                   HIDPreparsedDataRef preparsedDataRef,
        !            84:                                                   void *psReport,
        !            85:                                                   UInt32 iReportLength)
        !            86: {
        !            87:        HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
        !            88:        HIDUsageAndPage tUsageAndPage;
        !            89:        HIDCollection *ptCollection;
        !            90:        HIDReportItem *ptReportItem;
        !            91:        OSStatus iStatus;
        !            92:        int iR, iE;
        !            93:        long iValue;
        !            94:        int iStart;
        !            95:        int iMaxUsages;
        !            96:        int iReportItem;
        !            97:        Boolean bIncompatibleReport = false;
        !            98: /*
        !            99:  *     Disallow Null Pointers
        !           100: */
        !           101:        if ((ptPreparsedData == NULL)
        !           102:         || (piUsageList == NULL)
        !           103:         || (piUsageListLength == NULL)
        !           104:         || (psReport == NULL))
        !           105:                return kHIDNullPointerErr;
        !           106:        if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
        !           107:                return kHIDInvalidPreparsedDataErr;
        !           108: /*
        !           109:  *     The Collection must be in range
        !           110: */
        !           111:        if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount))
        !           112:                return kHIDBadParameterErr;
        !           113: /*
        !           114:  *     Save the size of the list
        !           115: */
        !           116:        iMaxUsages = *piUsageListLength;
        !           117:        *piUsageListLength = 0;
        !           118: /*
        !           119:  *     Search only the scope of the Collection specified
        !           120:  *     Go through the ReportItems
        !           121:  *     Filter on ReportType and usagePage
        !           122: */
        !           123:        ptCollection = &ptPreparsedData->collections[iCollection];
        !           124:        for (iR=0; iR<ptCollection->reportItemCount; iR++)
        !           125:        {
        !           126:                iReportItem = ptCollection->firstReportItem + iR;
        !           127:                ptReportItem = &ptPreparsedData->reportItems[iReportItem];
        !           128:                if (HIDIsButton(ptReportItem, preparsedDataRef))
        !           129:                {
        !           130: /*
        !           131:  *                     This may be the proper data to get
        !           132:  *                     Let's check for the proper Report ID, Type, and Length
        !           133: */
        !           134:                        iStatus = HIDCheckReport(reportType,preparsedDataRef,ptReportItem,
        !           135:                                                                           psReport,iReportLength);
        !           136: /*
        !           137:  *                     The Report ID or Type may not match.
        !           138:  *                     This may not be an error (yet)
        !           139: */
        !           140:                        if (iStatus == kHIDIncompatibleReportErr)
        !           141:                                bIncompatibleReport = true;
        !           142:                        else if (iStatus != kHIDSuccess)
        !           143:                                return iStatus;
        !           144:                        else
        !           145:                        {
        !           146: /*
        !           147:  *                             Save Array Buttons
        !           148: */
        !           149:                                iStart = ptReportItem->startBit;
        !           150:                                for (iE=0; iE<ptReportItem->globals.reportCount; iE++)
        !           151:                                {
        !           152:                                        if ((ptReportItem->dataModes & kHIDDataArrayBit) == kHIDDataArray)
        !           153:                                        {
        !           154:                                                iStatus = HIDGetData(psReport, iReportLength, iStart,
        !           155:                                                                         ptReportItem->globals.reportSize,
        !           156:                                                                         &iValue, false);
        !           157:                                                if (!iStatus)
        !           158:                                                        iStatus = HIDPostProcessRIValue (ptReportItem, &iValue);
        !           159:                                                HIDUsageAndPageFromIndex(preparsedDataRef,
        !           160:                                                                         ptReportItem,
        !           161:                                                                         iValue-ptReportItem->globals.logicalMinimum,
        !           162:                                                                         &tUsageAndPage);
        !           163:                                                iStart += ptReportItem->globals.reportSize;
        !           164:                                                if (usagePage == tUsageAndPage.usagePage)
        !           165:                                                {
        !           166:                                                        if (*piUsageListLength >= iMaxUsages)
        !           167:                                                                return kHIDBufferTooSmallErr;
        !           168:                                                        piUsageList[(*piUsageListLength)++] = iValue;
        !           169:                                                }
        !           170:                                        }
        !           171: /*
        !           172:  *                                     Save Bitmapped Buttons
        !           173: */
        !           174:                                        else
        !           175:                                        {
        !           176:                                                iStatus = HIDGetData(psReport, iReportLength, iStart, 1, &iValue, false);
        !           177:                                                if (!iStatus)
        !           178:                                                        iStatus = HIDPostProcessRIValue (ptReportItem, &iValue);
        !           179:                                                iStart++;
        !           180:                                                if (!iStatus && iValue != 0)
        !           181:                                                {
        !           182:                                                        HIDUsageAndPageFromIndex(preparsedDataRef,ptReportItem,iE,&tUsageAndPage);
        !           183:                                                        if (usagePage == tUsageAndPage.usagePage)
        !           184:                                                        {
        !           185:                                                                if (*piUsageListLength >= iMaxUsages)
        !           186:                                                                        return kHIDBufferTooSmallErr;
        !           187:                                                                piUsageList[(*piUsageListLength)++] = tUsageAndPage.usage;
        !           188:                                                        }
        !           189:                                                }
        !           190:                                        }
        !           191:                                }
        !           192:                        }
        !           193:                }
        !           194:        }
        !           195: /*
        !           196:  *     If nothing was returned then change the status
        !           197: */
        !           198:        if (*piUsageListLength == 0)
        !           199:        {
        !           200:                if (bIncompatibleReport)
        !           201:                        return kHIDIncompatibleReportErr;
        !           202:                return kHIDUsageNotFoundErr;
        !           203:        }
        !           204:        return kHIDSuccess;
        !           205: }

unix.superglobalmegacorp.com

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