int mp_input_ar_init(void) { io_iterator_t hidObjectIterator; io_object_t hidDevice; int i; IOHIDElementCookie *cookies = NULL; int nr_cookies = 0; if (initialized) mp_input_ar_close(-1); if (floor(NSAppKitVersionNumber) <= 824 /* NSAppKitVersionNumber10_4 */) { ar_codes = &ar_codes_tiger[0]; is_leopard = 0; } else { ar_codes = &ar_codes_leopard[0]; is_leopard = 1; } if (FindHIDDevices(kIOMasterPortDefault, &hidObjectIterator)) return -1; // Multiple controls could be found, we only use the first usable one. while ((hidDevice = IOIteratorNext(hidObjectIterator))) { if (CreateHIDDeviceInterface(hidDevice, &hidDeviceInterface) < 0) { hidDeviceInterface = NULL; IOObjectRelease(hidDevice); continue; } if (getHIDCookies((IOHIDDeviceInterface122 **)hidDeviceInterface, &cookies, &nr_cookies) < 0) { (*hidDeviceInterface)->Release(hidDeviceInterface); hidDeviceInterface = NULL; IOObjectRelease(hidDevice); continue; } IOObjectRelease(hidDevice); break; } if (hidDeviceInterface == NULL) goto mp_input_ar_init_error; // Open the device. if ((*hidDeviceInterface)->open(hidDeviceInterface, kIOHIDOptionsTypeSeizeDevice) != kIOReturnSuccess) goto mp_input_ar_init_error; hidDeviceIsOpen = 1; if ((queue = (*hidDeviceInterface)->allocQueue(hidDeviceInterface)) == NULL || *queue == NULL) goto mp_input_ar_init_error; // Create the queue. (*queue)->create(queue, 0, MAX_QUEUE_SIZE); // Add elements to the queue to make the queue work. // On tiger, it's a sequence from 1 to 21, // maybe it's the range of cookie values. for (i = 0;i < nr_cookies;i++) (*queue)->addElement(queue, cookies[i], 0); // not used anymore if (cookies != NULL) free(cookies); // Start data delivery to the queue. (*queue)->start(queue); // not useful anymore IOObjectRelease(hidObjectIterator); initialized = 1; return 0; mp_input_ar_init_error: if (cookies != NULL) free(cookies); if (hidDeviceInterface != NULL) { if (*hidDeviceInterface != NULL) { (*hidDeviceInterface)->close(hidDeviceInterface); (*hidDeviceInterface)->Release(hidDeviceInterface); } hidDeviceInterface = NULL; } IOObjectRelease(hidObjectIterator); return -1; }
unsigned int MT_HIDGamePad::Init() { #ifdef MT_GAMEPAD_MAC if(FindHIDDevices()) { fprintf(stderr,"No matching HID class devices found.\n"); fflush(stderr); return 1; } else if(FindGamePad()) { fprintf(stderr,"No gamepad found.\n"); fflush(stderr); return 1; } else if(CreateHIDDeviceInterface(&hidDeviceInterface)) { fprintf(stderr,"Couldn't create HID class device interface.\n"); fflush(stderr); return 1; } else { gpCookies = getHIDCookies((IOHIDDeviceInterface122 **)hidDeviceInterface); if(IOObjectRelease(hidDevice)) { fprintf(stderr,"Error releasing HID device.\n"); fflush(stderr); return 1; } if((*hidDeviceInterface)->open(hidDeviceInterface,0)) { fprintf(stderr,"Error opening HID device.\n"); fflush(stderr); return 1; } } // Set up the button queue ButtonQueue = (*hidDeviceInterface)->allocQueue (hidDeviceInterface); if(!ButtonQueue) { fprintf(stderr,"Could not create button queue.\n"); fflush(stderr); return 1; } (*ButtonQueue)->create(ButtonQueue,8,QUEUE_LENGTH); (*ButtonQueue)->addElement(ButtonQueue, gpCookies->gButton1Cookie, 0); (*ButtonQueue)->addElement(ButtonQueue, gpCookies->gButton2Cookie, 0); (*ButtonQueue)->addElement(ButtonQueue, gpCookies->gButton3Cookie, 0); (*ButtonQueue)->addElement(ButtonQueue, gpCookies->gButton4Cookie, 0); (*ButtonQueue)->addElement(ButtonQueue, gpCookies->gButton5Cookie, 0); (*ButtonQueue)->addElement(ButtonQueue, gpCookies->gButton6Cookie, 0); (*ButtonQueue)->addElement(ButtonQueue, gpCookies->gButton7Cookie, 0); (*ButtonQueue)->addElement(ButtonQueue, gpCookies->gButton8Cookie, 0); (*ButtonQueue)->addElement(ButtonQueue, gpCookies->gButton9Cookie, 0); (*ButtonQueue)->addElement(ButtonQueue, gpCookies->gButtonaCookie, 0); (*ButtonQueue)->addElement(ButtonQueue, gpCookies->gButtonbCookie, 0); (*ButtonQueue)->addElement(ButtonQueue, gpCookies->gButtoncCookie, 0); (*ButtonQueue)->start(ButtonQueue); xcenter = PollXAxis(); ycenter = PollYAxis(); #elif defined MT_GAMEPAD_USE_WX if(!myJoystick.IsOk()) { //wxMessageBox(_T("No joystick detected.")); return 1; } #endif StatusGood = true; return 0; }