Annotation of XNU/iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDSetButtons.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:           HIDSetButtons.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. This means we
                     48:                                                                        need to pass an additional parameter to some internal functions
                     49:          <USB2>          4/7/99        BWS             Add support for reversed report items
                     50:          <USB1>          3/5/99        BWS             first checked in
                     51: */
                     52: 
                     53: #include "HIDLib.h"
                     54: 
                     55: /*
                     56:  *------------------------------------------------------------------------------
                     57:  *
                     58:  * HIDSetButton - Set the state of a button for a Page
                     59:  *
                     60:  *      Input:
                     61:  *                       reportType               - HIDP_Input, HIDP_Output, HIDP_Feature
                     62:  *                       usagePage                        - Page Criteria or zero
                     63:  *                       iCollection                   - Collection Criteria or zero
                     64:  *                       usage                            - Usages for pressed button
                     65:  *                       ptPreparsedData               - Pre-Parsed Data
                     66:  *                       psReport                              - An HID Report
                     67:  *                       iReportLength                 - The length of the Report
                     68:  *      Output:
                     69:  *      Returns:
                     70:  *
                     71:  *------------------------------------------------------------------------------
                     72: */
                     73: OSStatus HIDSetButton  (HIDReportType                  reportType,
                     74:                                                HIDUsage                                usagePage,
                     75:                                                UInt32                                  collection,
                     76:                                                HIDUsage                                usage,
                     77:                                                HIDPreparsedDataRef             preparsedDataRef,
                     78:                                                void *                                  report,
                     79:                                                ByteCount                               reportLength)
                     80: {
                     81:        HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
                     82:        HIDCollection *ptCollection;
                     83:        HIDReportItem *ptReportItem;
                     84:        OSStatus iStatus;
                     85:        int iR, iX;
                     86:        SInt32 data;
                     87:        int iStart;
                     88:        int iReportItem;
                     89:        UInt32 iUsageIndex;
                     90:        Boolean bIncompatibleReport = false;
                     91: /*
                     92:  *     Disallow Null Pointers
                     93: */
                     94:        if ((ptPreparsedData == NULL)
                     95:         || (report == NULL))
                     96:                return kHIDNullPointerErr;
                     97:        if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
                     98:                return kHIDInvalidPreparsedDataErr;
                     99: /*
                    100:  *     The Collection must be in range
                    101: */
                    102:        if ((collection < 0) || (collection >= ptPreparsedData->collectionCount))
                    103:                return kHIDBadParameterErr;
                    104: /*
                    105:  *     Search only the scope of the Collection specified
                    106:  *     Go through the ReportItems
                    107:  *     Filter on ReportType and usagePage
                    108: */
                    109:        ptCollection = &ptPreparsedData->collections[collection];
                    110:        for (iR=0; iR<ptCollection->reportItemCount; iR++)
                    111:        {
                    112:                iReportItem = ptCollection->firstReportItem + iR;
                    113:                ptReportItem = &ptPreparsedData->reportItems[iReportItem];
                    114:                if (HIDIsButton(ptReportItem, preparsedDataRef)
                    115:                 && HIDHasUsage(preparsedDataRef,ptReportItem,usagePage,usage,&iUsageIndex,NULL))
                    116:                {
                    117: /*
                    118:  *                     This may be the proper data to get
                    119:  *                     Let's check for the proper Report ID, Type, and Length
                    120: */
                    121:                        iStatus = HIDCheckReport(reportType,preparsedDataRef,ptReportItem,report,reportLength);
                    122: /*
                    123:  *                     The Report ID or Type may not match.
                    124:  *                     This may not be an error (yet)
                    125: */
                    126:                        if (iStatus == kHIDIncompatibleReportErr)
                    127:                                bIncompatibleReport = true;
                    128:                        else if (iStatus != kHIDSuccess)
                    129:                                return iStatus;
                    130:                        else
                    131:                        {
                    132: /*
                    133:  *                             Save Arrays
                    134: */
                    135:                                if ((ptReportItem->dataModes & kHIDDataArrayBit) == kHIDDataArray)
                    136:                                {
                    137:                                        for (iX=0; iX<ptReportItem->globals.reportCount; iX++)
                    138:                                        {
                    139:                                                iStart = ptReportItem->startBit + (ptReportItem->globals.reportSize * iX);
                    140:                                                iStatus = HIDGetData(report, reportLength, iStart,
                    141:                                                                                           ptReportItem->globals.reportSize, &data, true);
                    142:                                                if (!iStatus)
                    143:                                                        iStatus = HIDPostProcessRIValue (ptReportItem, &data);
                    144:                                                if (iStatus != kHIDSuccess)
                    145:                                                        return iStatus;
                    146:                                                // if not already in the list, add it (is this code right??)
                    147:                                                if (data == 0)
                    148:                                                        return HIDPutData(report, reportLength, iStart,
                    149:                                                                                                ptReportItem->globals.reportSize,
                    150:                                                                                                iUsageIndex + ptReportItem->globals.logicalMinimum);
                    151:                                        }
                    152:                                        return kHIDBufferTooSmallErr;
                    153:                                }
                    154: /*
                    155:  *                             Save Bitmaps
                    156: */
                    157:                                else if (ptReportItem->globals.reportSize == 1)
                    158:                                {
                    159:                                        iStart = ptReportItem->startBit + (ptReportItem->globals.reportSize * iUsageIndex);
                    160:                                        // should we call HIDPreProcessRIValue here?
                    161:                                        // we are passing '-1' as trhe value, is this right? Some hack to set the right bit to 1?
                    162:                                        iStatus = HIDPutData(report, reportLength, iStart, ptReportItem->globals.reportSize, -1);
                    163:                                        if (iStatus != kHIDSuccess)
                    164:                                                return iStatus;
                    165:                                        return kHIDSuccess;
                    166:                                }
                    167:                        }
                    168:                }
                    169:        }
                    170:        if (bIncompatibleReport)
                    171:                return kHIDIncompatibleReportErr;
                    172:        return kHIDUsageNotFoundErr;
                    173: }
                    174: 
                    175: /*
                    176:  *------------------------------------------------------------------------------
                    177:  *
                    178:  * HIDSetButtons - Set the state of the buttons for a Page
                    179:  *
                    180:  *      Input:
                    181:  *                       reportType               - HIDP_Input, HIDP_Output, HIDP_Feature
                    182:  *                       usagePage                        - Page Criteria or zero
                    183:  *                       collection                    - Collection Criteria or zero
                    184:  *                       piUsageList                   - Usages for pressed buttons
                    185:  *                       piUsageListLength             - Max entries in UsageList
                    186:  *                       ptPreparsedData               - Pre-Parsed Data
                    187:  *                       report                                - An HID Report
                    188:  *                       reportLength                  - The length of the Report
                    189:  *      Output:
                    190:  *                       piValue                               - Pointer to usage Value
                    191:  *      Returns:
                    192:  *
                    193:  *------------------------------------------------------------------------------
                    194: */
                    195: OSStatus
                    196: HIDSetButtons                     (HIDReportType                       reportType,
                    197:                                                        HIDUsage                                usagePage,
                    198:                                                        UInt32                                  collection,
                    199:                                                        HIDUsage *                              usageList,
                    200:                                                        UInt32 *                                usageListSize,
                    201:                                                        HIDPreparsedDataRef             preparsedDataRef,
                    202:                                                        void *                                  report,
                    203:                                                        ByteCount                               reportLength)
                    204: {
                    205:        HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
                    206:        OSStatus iStatus;
                    207:        int iUsages;
                    208:        int usage;
                    209: /*
                    210:  *     Disallow Null Pointers
                    211: */
                    212:        if ((ptPreparsedData == NULL)
                    213:         || (usageList == NULL)
                    214:         || (usageListSize == NULL)
                    215:         || (report == NULL))
                    216:                return kHIDNullPointerErr;
                    217:        if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
                    218:                return kHIDInvalidPreparsedDataErr;
                    219: /*
                    220:  *     Save the usage List Length
                    221: */
                    222:        iUsages = *usageListSize;
                    223: /*
                    224:  *     Write them out one at a time
                    225: */
                    226:        for (usage=0; usage<iUsages; usage++)
                    227:        {
                    228:                *usageListSize = usage;
                    229:                iStatus = HIDSetButton(reportType, usagePage, collection,
                    230:                                                                usageList[usage], preparsedDataRef,
                    231:                                                                report, reportLength);
                    232:                if (iStatus != kHIDSuccess)
                    233:                        return iStatus;
                    234:        }
                    235:        return kHIDSuccess;
                    236: }

unix.superglobalmegacorp.com

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