#include "HIDLib.h"
OSStatus
HIDGetButtons (HIDReportType reportType,
UInt32 iCollection,
HIDUsageAndPagePtr ptUsageList,
UInt32 * piUsageListLength,
HIDPreparsedDataRef preparsedDataRef,
void * psReport,
UInt32 iReportLength)
{
HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
HIDCollection *ptCollection;
HIDReportItem *ptReportItem;
int iR, iE;
long iValue;
int iStart;
int iReportItem;
int iMaxUsages;
HIDUsageAndPage tUsageAndPage;
if ((ptPreparsedData == NULL)
|| (ptUsageList == NULL)
|| (piUsageListLength == NULL)
|| (psReport == NULL))
return kHIDNullPointerErr;
if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
return kHIDInvalidPreparsedDataErr;
iMaxUsages = *piUsageListLength;
*piUsageListLength = 0;
ptCollection = &ptPreparsedData->collections[iCollection];
for (iR=0; iR<ptCollection->reportItemCount; iR++)
{
iReportItem = ptCollection->firstReportItem + iR;
ptReportItem = &ptPreparsedData->reportItems[iReportItem];
if ((ptReportItem->reportType == reportType)
&& HIDIsButton(ptReportItem, preparsedDataRef))
{
iStart = ptReportItem->startBit;
for (iE=0; iE<ptReportItem->globals.reportCount; iE++)
{
OSStatus status = noErr;
iValue = 0;
if ((ptReportItem->dataModes & kHIDDataArrayBit) == kHIDDataArray)
{
status = HIDGetData(psReport, iReportLength, iStart, ptReportItem->globals.reportSize, &iValue, false);
if (!status)
status = HIDPostProcessRIValue (ptReportItem, &iValue);
if (status) return status;
iStart += ptReportItem->globals.reportSize;
HIDUsageAndPageFromIndex(preparsedDataRef,ptReportItem,ptReportItem->globals.logicalMinimum+iE,&tUsageAndPage);
if (*piUsageListLength >= iMaxUsages)
return kHIDBufferTooSmallErr;
ptUsageList[(*piUsageListLength)++] = tUsageAndPage;
}
else
{
status = HIDGetData(psReport, iReportLength, iStart, 1, &iValue, false);
if (!status)
status = HIDPostProcessRIValue (ptReportItem, &iValue);
if (status) return status;
iStart++;
if (iValue != 0)
{
HIDUsageAndPageFromIndex(preparsedDataRef,ptReportItem,ptReportItem->globals.logicalMinimum+iE,&tUsageAndPage);
if (*piUsageListLength >= iMaxUsages)
return kHIDBufferTooSmallErr;
ptUsageList[(*piUsageListLength)++] = tUsageAndPage;
}
}
}
}
}
return kHIDSuccess;
}