/* PSYCHHIDCheckInit() Check to see if we need to create the USB-HID device list. If it has not been created then create it. */ void PsychHIDVerifyInit(void) { psych_bool success = TRUE; // Build HID device list if it doesn't already exist: if (!HIDHaveDeviceList()) success = (psych_bool) HIDBuildDeviceList(0, 0); // This check can only be made against the 64-Bit HID Utilities, as the older 32-Bit // version is even more crappy and can't report meaningful error status: #if defined(__LP64__) if (!success) { printf("PsychHID-ERROR: Could not enumerate HID devices (HIDBuildDeviceList() failed)! There can be various reasons,\n"); printf("PsychHID-ERROR: ranging from bugs in Apples HID software to a buggy HID device driver for some connected device,\n"); printf("PsychHID-ERROR: to general operating system malfunction. A reboot or device driver update for 3rd party HID devices\n"); printf("PsychHID-ERROR: maybe could help. Check the OSX system log for possible HID related error messages or hints. Aborting...\n"); PsychErrorExitMsg(PsychError_system, "HID device enumeration failed due to malfunction in the OSX 64 Bit Apple HID Utilities framework."); } #endif // Double-Check to protect against pathetic Apple software: if (!HIDHaveDeviceList()) { printf("PsychHID-ERROR: Could not enumerate HID devices (HIDBuildDeviceList() success, but HIDHaveDeviceList() still failed)!\n"); printf("PsychHID-ERROR: Reasons can be ranging from bugs in Apples HID software to a buggy HID device driver for some connected device,\n"); printf("PsychHID-ERROR: to general operating system malfunction. A reboot or device driver update for 3rd party HID devices\n"); printf("PsychHID-ERROR: maybe could help. Check the OSX system log for possible HID related error messages or hints. Aborting...\n"); PsychErrorExitMsg(PsychError_system, "HID device enumeration failed due to malfunction in the OSX Apple HID Utilities framework (II)."); } // Verify no security sensitive application is blocking our low-level access to HID devices: PsychHIDWarnInputDisabled(NULL); #if defined(__LP64__) // Try to load all bundles from Psychtoolbox/PsychHardware/ // This loads the HID_Utilities.framework bundle if it is present. The whole point of it is // to allow our statically compiled-in version of the library to find the location of // the XML file with the database of (vendorId, productId) -> (VendorName, ProductName) and // (usagePage, usage) -> (usageName) mappings. // // In practice, the XML file only serves as a fallback, and one that doesn't contain much // useful info for mainstream products, only for a few niche products. Given its limited // value, i think we can refrain from shipping the framework as part of Psychtoolbox and // just provide the option to use it (== its XML file) if users decide to install it themselves. char tmpString[1024]; sprintf(tmpString, "%sPsychHardware/", PsychRuntimeGetPsychtoolboxRoot(FALSE)); CFStringRef urlString = CFStringCreateWithCString(kCFAllocatorDefault, tmpString, kCFStringEncodingASCII); CFURLRef directoryURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, urlString, kCFURLPOSIXPathStyle, false); CFRelease(urlString); CFArrayRef bundleArray = CFBundleCreateBundlesFromDirectory(kCFAllocatorDefault, directoryURL, NULL); CFRelease(directoryURL); CFRelease(bundleArray); #endif }
/* PsychInitializePsychHID() * * Master init routine - Called at module load time / first time init. * */ void PsychInitializePsychHID(void) { int i; // Initialize the generic USB tracker to "all off" state: for (i = 0; i < PSYCH_HID_MAX_GENERIC_USB_DEVICES; i++) { usbDeviceRecordBank[i].valid = 0; } // Setup event ringbuffers: for (i = 0; i < PSYCH_HID_MAX_DEVICES; i++) { hidEventBuffer[i] = NULL; hidEventBufferCapacity[i] = 10000; // Initial capacity of event buffer. hidEventBufferReadPos[i] = 0; hidEventBufferWritePos[i] = 0; } #if PSYCH_SYSTEM == PSYCH_OSX for (i = 0; i < MAXDEVICEINDEXS; i++) deviceInterfaces[i] = NULL; // Try to load all bundles from Psychtoolbox/PsychHardware/ // This loads the HID_Utilities.framework bundle if it is present. The whole point of it is // to allow our statically compiled-in version of the library to find the location of // the XML file with the database of (vendorId, productId) -> (VendorName, ProductName) and // (usagePage, usage) -> (usageName) mappings. // // In practice, the XML file only serves as a fallback, and one that doesn't contain much // useful info for mainstream products, only for a few niche products. Given its limited // value, i think we can refrain from shipping the framework as part of Psychtoolbox and // just provide the option to use it (== its XML file) if users decide to install it themselves. char tmpString[1024]; sprintf(tmpString, "%sPsychHardware/", PsychRuntimeGetPsychtoolboxRoot(FALSE)); CFStringRef urlString = CFStringCreateWithCString(kCFAllocatorDefault, tmpString, kCFStringEncodingASCII); CFURLRef directoryURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, urlString, kCFURLPOSIXPathStyle, false); CFRelease(urlString); CFArrayRef bundleArray = CFBundleCreateBundlesFromDirectory(kCFAllocatorDefault, directoryURL, NULL); CFRelease(directoryURL); CFRelease(bundleArray); #endif // Initialize OS specific interfaces and routines: PsychHIDInitializeHIDStandardInterfaces(); // This sets up data structures for HID report reception inside PsychHIDReceiveReports.c: PsychHIDReleaseAllReportMemory(); return; }