void HIDSaveElementConfig (FILE * fileRef, pRecDevice pDevice, pRecElement pElement, long actionCookie)
{
	recSaveHID saveRec;

	if (HIDIsValidElement(pDevice,pElement))
	{
		// clear rec
		bzero(&saveRec,sizeof(recSaveHID));

		saveRec.actionCookie = actionCookie;

		// must save
		// actionCookie
		// Device: serial,vendorID, productID, location, usagePage, usage
		// Element: cookie, usagePage, usage,
		// need to add serial number when I have a test case
		
		saveRec.vendorID = pDevice->vendorID;
		saveRec.productID = pDevice->productID;
		saveRec.locID = pDevice->locID;
		saveRec.usage = pDevice->usage;
		saveRec.usagePage = pDevice->usagePage;

		saveRec.usagePageE = pElement->usagePage;
		saveRec.usageE = pElement->usage;
		saveRec.cookie = pElement->cookie;

		// write to file
		if (fileRef)
			fwrite ((void *)&saveRec, sizeof (recSaveHID), 1, fileRef);
	}
}
Esempio n. 2
0
/*************************************************************************
 *
 * HIDAddDeviceElementToXML( inDevice, inElement )
 *
 * Purpose: Adds a devices info to the HID_device_usage_strings.plist( XML ) file
 *
 * Inputs: inDevice		- the device
 *			inElement	- the element
 *
 * Returns: Boolean		- if successful
 */
Boolean HIDAddDeviceElementToXML(IOHIDDeviceRef inIOHIDDeviceRef, IOHIDElementRef inIOHIDElementRef) {
	Boolean result = FALSE;
	if ( HIDIsValidElement(inIOHIDElementRef) ) {
		if ( HIDAddDeviceToXML(inIOHIDDeviceRef) ) {
			result = TRUE;
		}
		if ( hu_AddDeviceElementToUsageXML(inIOHIDDeviceRef, inIOHIDElementRef) ) {
			result = TRUE;
		}
	}
	
	return (result);
}   // HIDAddDeviceElementToXML
Boolean HIDSaveElementPref (const CFStringRef keyCFStringRef, CFStringRef appCFStringRef, pRecDevice pDevice, pRecElement pElement)
{
	Boolean success = false;

	if ((NULL != keyCFStringRef) && (NULL != appCFStringRef) && HIDIsValidElement(pDevice,pElement))
	{
		CFStringRef prefCFStringRef =
			CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("d:{v:%ld, p:%ld, l:%ld, p:%ld, u:%ld}, e:{t:%ld, p:%ld, u:%ld, c:%ld}"), 
							pDevice->vendorID, pDevice->productID, pDevice->locID, pDevice->usagePage, pDevice->usage, 
							pElement->type, pElement->usagePage, pElement->usage, pElement->cookie);

		if (NULL != prefCFStringRef)
		{
			CFPreferencesSetAppValue(keyCFStringRef, prefCFStringRef, kCFPreferencesCurrentApplication);
			CFRelease(prefCFStringRef);
			success = true;
		}
	}
	return success;
}