// Set up a config record for saving // takes an input records, returns record user can save as they want // Note: the save rec must be pre-allocated by the calling app and will be filled out void HIDSetElementConfig (pRecSaveHID pConfigRec, IOHIDDeviceRef inIOHIDDeviceRef, IOHIDElementRef inIOHIDElementRef, int actionCookie) { // must save: // actionCookie // Device: serial,vendorID, productID, location, usagePage, usage // Element: cookie, usagePage, usage, pConfigRec->actionCookie = actionCookie; // device // need to add serial number when I have a test case if (inIOHIDDeviceRef && inIOHIDElementRef) { pConfigRec->device.vendorID = IOHIDDevice_GetVendorID( inIOHIDDeviceRef ); pConfigRec->device.productID = IOHIDDevice_GetProductID( inIOHIDDeviceRef ); pConfigRec->device.locID = IOHIDDevice_GetLocationID( inIOHIDDeviceRef ); pConfigRec->device.usage = IOHIDDevice_GetUsage( inIOHIDDeviceRef ); pConfigRec->device.usagePage = IOHIDDevice_GetUsagePage( inIOHIDDeviceRef ); pConfigRec->element.usagePage = IOHIDElementGetUsagePage( inIOHIDElementRef ); pConfigRec->element.usage = IOHIDElementGetUsage( inIOHIDElementRef ); pConfigRec->element.minReport = IOHIDElement_GetCalibrationSaturationMin( inIOHIDElementRef ); pConfigRec->element.maxReport = IOHIDElement_GetCalibrationSaturationMax( inIOHIDElementRef ); pConfigRec->element.cookie = IOHIDElementGetCookie( inIOHIDElementRef ); } else { pConfigRec->device.vendorID = 0; pConfigRec->device.productID = 0; pConfigRec->device.locID = 0; pConfigRec->device.usage = 0; pConfigRec->device.usagePage = 0; pConfigRec->element.usagePage = 0; pConfigRec->element.usage = 0; pConfigRec->element.minReport = 0; pConfigRec->element.maxReport = 0; pConfigRec->element.cookie = 0; } }
// ************************************************************************* // // IOHIDElement_SetupCalibration(inIOHIDElementRef) // // Purpose: set default values for the element calibration parameters // // Inputs: inIOHIDElementRef - the IOHIDElementRef for this element // // Returns: nothing // void IOHIDElement_SetupCalibration(IOHIDElementRef inIOHIDElementRef) { // these are the min/max values returned by IOHIDValueGetScaledValue(v, kIOHIDValueScaleTypeCalibrated); IOHIDElement_SetCalibrationMin(inIOHIDElementRef, IOHIDElementGetLogicalMin(inIOHIDElementRef)); IOHIDElement_SetCalibrationMax(inIOHIDElementRef, IOHIDElementGetLogicalMax(inIOHIDElementRef)); CFIndex phyMin = IOHIDElementGetPhysicalMin(inIOHIDElementRef); CFIndex phyMax = IOHIDElementGetPhysicalMax(inIOHIDElementRef); CFIndex phyRange = phyMax - phyMin; // calculate the middle physical value we would expect from this element double phyMid = (phyMin + phyMax) / 2.f; // this is the granularity of the values returned by IOHIDValueGetScaledValue(v, kIOHIDValueScaleTypeCalibrated); // for example if set to 0.1 the values returned will be multiples of 0.1 (0.1, 0.2, 0.3, etc.) IOHIDElement_SetCalibrationGranularity(inIOHIDElementRef, 0.); Boolean isRelative = IOHIDElementIsRelative(inIOHIDElementRef); Boolean hasPreferredState = IOHIDElementHasPreferredState(inIOHIDElementRef); // define the dead zone (like in the middle of joystick axis) if (!isRelative && hasPreferredState && (phyRange > 3)) { IOHIDElement_SetCalibrationDeadZoneMin(inIOHIDElementRef, phyMid - 1.0); IOHIDElement_SetCalibrationDeadZoneMax(inIOHIDElementRef, phyMid + 1.0); } else { IOHIDElement_SetCalibrationDeadZoneMin(inIOHIDElementRef, 0.); IOHIDElement_SetCalibrationDeadZoneMax(inIOHIDElementRef, 0.); } // get the current value of this element double phyValue = IOHIDElement_GetValue(inIOHIDElementRef, kIOHIDValueScaleTypePhysical); #if true // use that that value to determine the min/max saturation values used for calibration IOHIDElement_SetCalibrationSaturationMin(inIOHIDElementRef, phyValue); IOHIDElement_SetCalibrationSaturationMax(inIOHIDElementRef, phyValue); #else // if 1 #if true // this value determines the min/max values that have been recieved from the device element IOHIDElement_SetCalibrationSaturationMin(inIOHIDElementRef, (phyMin + phyMid) / 2.f); IOHIDElement_SetCalibrationSaturationMax(inIOHIDElementRef, (phyMid + phyMax) / 2.f); #else // if 1 // use it as our min/max saturation // this value determines the min/max values that have been recieved from the device element IOHIDElement_SetCalibrationSaturationMin(inIOHIDElementRef, phyMid); IOHIDElement_SetCalibrationSaturationMax(inIOHIDElementRef, phyMid); #endif // if 1 // and the current value to adjust the current saturation values if it's outside their range if (phyValue < IOHIDElement_GetCalibrationSaturationMin(inIOHIDElementRef)) { IOHIDElement_SetCalibrationSaturationMin(inIOHIDElementRef, phyValue); } if (phyValue > IOHIDElement_GetCalibrationSaturationMax(inIOHIDElementRef)) { IOHIDElement_SetCalibrationSaturationMax(inIOHIDElementRef, phyValue); } #endif // if 1 } // IOHIDElement_SetupCalibration
// Set up a config record for saving // takes an input records, returns record user can save as they want // Note: the save rec must be pre-allocated by the calling app and will be filled out void HIDSetElementConfig(HID_info_ptr inHIDInfoPtr, IOHIDDeviceRef inIOHIDDeviceRef, IOHIDElementRef inIOHIDElementRef, IOHIDElementCookie actionCookie) { // must save: // actionCookie // Device: serial,vendorID, productID, location, usagePage, usage // Element: cookie, usagePage, usage, inHIDInfoPtr->actionCookie = actionCookie; // device // need to add serial number when I have a test case if (inIOHIDDeviceRef && inIOHIDElementRef) { inHIDInfoPtr->device.vendorID = IOHIDDevice_GetVendorID(inIOHIDDeviceRef); inHIDInfoPtr->device.productID = IOHIDDevice_GetProductID(inIOHIDDeviceRef); inHIDInfoPtr->device.locID = IOHIDDevice_GetLocationID(inIOHIDDeviceRef); inHIDInfoPtr->device.usage = IOHIDDevice_GetUsage(inIOHIDDeviceRef); inHIDInfoPtr->device.usagePage = IOHIDDevice_GetUsagePage(inIOHIDDeviceRef); if (!inHIDInfoPtr->device.usagePage || !inHIDInfoPtr->device.usage) { inHIDInfoPtr->device.usagePage = IOHIDDevice_GetPrimaryUsagePage(inIOHIDDeviceRef); inHIDInfoPtr->device.usage = IOHIDDevice_GetPrimaryUsage(inIOHIDDeviceRef); } inHIDInfoPtr->element.usagePage = IOHIDElementGetUsagePage(inIOHIDElementRef); inHIDInfoPtr->element.usage = IOHIDElementGetUsage(inIOHIDElementRef); inHIDInfoPtr->element.minReport = IOHIDElement_GetCalibrationSaturationMin(inIOHIDElementRef); inHIDInfoPtr->element.maxReport = IOHIDElement_GetCalibrationSaturationMax(inIOHIDElementRef); inHIDInfoPtr->element.cookie = IOHIDElementGetCookie(inIOHIDElementRef); } else { inHIDInfoPtr->device.vendorID = 0; inHIDInfoPtr->device.productID = 0; inHIDInfoPtr->device.locID = 0; inHIDInfoPtr->device.usage = 0; inHIDInfoPtr->device.usagePage = 0; inHIDInfoPtr->element.usagePage = 0; inHIDInfoPtr->element.usage = 0; inHIDInfoPtr->element.minReport = 0; inHIDInfoPtr->element.maxReport = 0; inHIDInfoPtr->element.cookie = 0; } } // HIDSetElementConfig
void HIDDumpElementCalibrationInfo(IOHIDElementRef inIOHIDElementRef) { printf(" Element: %p = { ", inIOHIDElementRef); CFIndex calMin = IOHIDElement_GetCalibrationMin(inIOHIDElementRef); CFIndex calMax = IOHIDElement_GetCalibrationMax(inIOHIDElementRef); printf("cal: {min: %ld, max: %ld}, ", calMin, calMax); CFIndex satMin = IOHIDElement_GetCalibrationSaturationMin(inIOHIDElementRef); CFIndex satMax = IOHIDElement_GetCalibrationSaturationMax(inIOHIDElementRef); printf("sat: {min: %ld, max: %ld}, ", satMin, satMax); CFIndex deadMin = IOHIDElement_GetCalibrationDeadZoneMin(inIOHIDElementRef); CFIndex deadMax = IOHIDElement_GetCalibrationDeadZoneMax(inIOHIDElementRef); printf("dead: {min: %ld, max: %ld}, ", deadMin, deadMax); double_t granularity = IOHIDElement_GetCalibrationGranularity(inIOHIDElementRef); printf("granularity: %6.2f }\n", granularity); } // HIDDumpElementCalibrationInfo
//************************************************************************* // // IOHIDElement_SetupCalibration( inElementRef ) // // Purpose: set default values for the element calibration parameters // // Inputs: inElementRef - the IOHIDElementRef for this element // // Returns: nothing // void IOHIDElement_SetupCalibration( IOHIDElementRef inIOHIDElementRef ) { // these are the min/max values returned by IOHIDValueGetScaledValue( v, kIOHIDValueScaleTypeCalibrated ); IOHIDElement_SetCalibrationMin( inIOHIDElementRef, IOHIDElementGetLogicalMin( inIOHIDElementRef ) ); IOHIDElement_SetCalibrationMax( inIOHIDElementRef, IOHIDElementGetLogicalMax( inIOHIDElementRef ) ); // this is the granularity of the values returned by IOHIDValueGetScaledValue( v, kIOHIDValueScaleTypeCalibrated ); // for example if set to 0.1 the values returned will be multiples of 0.1 ( 0.1, 0.2, 0.3, etc. ) IOHIDElement_SetCalibrationGranularity( inIOHIDElementRef, 0. ); // these define the dead zone (like in the middel of joystick axis) IOHIDElement_SetCalibrationDeadZoneMin( inIOHIDElementRef, 0 ); IOHIDElement_SetCalibrationDeadZoneMax( inIOHIDElementRef, 0 ); #if 1 // get the current value of this element double value = IOHIDElement_GetValue( inIOHIDElementRef, kIOHIDValueScaleTypePhysical ); // use it as our min/mas saturation IOHIDElement_SetCalibrationSaturationMin( inIOHIDElementRef, value ); IOHIDElement_SetCalibrationSaturationMax( inIOHIDElementRef, value ); #else // calculate the middle physical value we would expect from this element CFIndex valueMin = IOHIDElementGetPhysicalMin( inIOHIDElementRef ); CFIndex valueMax = IOHIDElementGetPhysicalMax( inIOHIDElementRef ); CFIndex valueMid = ( valueMin + valueMax ) / 2; // use it as our min/mas saturation // this value determines the min/max values that have been recieved from the device element IOHIDElement_SetCalibrationSaturationMin( inIOHIDElementRef, valueMid ); IOHIDElement_SetCalibrationSaturationMax( inIOHIDElementRef, valueMid ); // get the current value of this element double value = IOHIDElement_GetValue( inIOHIDElementRef, kIOHIDValueScaleTypePhysical ); // and use it to adjust the current saturation values if it's outside their range if ( value < IOHIDElement_GetCalibrationSaturationMin( inIOHIDElementRef ) ) { IOHIDElement_SetCalibrationSaturationMin( inIOHIDElementRef, value ); } if ( value > IOHIDElement_GetCalibrationSaturationMax( inIOHIDElementRef ) ) { IOHIDElement_SetCalibrationSaturationMax( inIOHIDElementRef, value ); } #endif } // IOHIDElement_SetupCalibration