static void add_hid(hid_t *h) { // fprintf(stderr, "add_hid\n"); //IOHIDDeviceRef* r= &h->ref; CFTypeRef prod = IOHIDDeviceGetProperty(h->ref, CFSTR(kIOHIDProductKey)); const char* prodstr = CFStringGetCStringPtr(prod, kCFStringEncodingMacRoman); // fprintf(stderr,"prodstr: %s\n",prodstr); CFTypeRef prop= IOHIDDeviceGetProperty(h->ref,CFSTR(kIOHIDManufacturerKey)); //CFStringRef manu = (CFStringRef)prop; const char* manustr = CFStringGetCStringPtr(prop, kCFStringEncodingMacRoman); // fprintf(stderr,"manustr: %s\n",manustr); if (!first_hid || !last_hid) { first_hid = last_hid = h; h->next = h->prev = NULL; return; } last_hid->next = h; h->prev = last_hid; h->next = NULL; last_hid = h; }
static void attach_callback(void *context, IOReturn r, void *hid_mgr, IOHIDDeviceRef dev) { CFTypeRef type; struct usb_list_struct *n, *p; int32_t pid, vid; if (!dev) return; type = IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVendorIDKey)); if (!type || CFGetTypeID(type) != CFNumberGetTypeID()) return; if (!CFNumberGetValue((CFNumberRef)type, kCFNumberSInt32Type, &vid)) return; type = IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductIDKey)); if (!type || CFGetTypeID(type) != CFNumberGetTypeID()) return; if (!CFNumberGetValue((CFNumberRef)type, kCFNumberSInt32Type, &pid)) return; n = (struct usb_list_struct *)malloc(sizeof(struct usb_list_struct)); if (!n) return; //printf("attach callback: vid=%04X, pid=%04X\n", vid, pid); n->ref = dev; n->vid = vid; n->pid = pid; n->next = NULL; if (usb_list == NULL) { usb_list = n; } else { for (p = usb_list; p->next; p = p->next) ; p->next = n; } }
bool JoystickOSX::configure_joystick(IOHIDDeviceRef p_device_ref, joystick *p_joy) { CFTypeRef refCF = NULL; p_joy->device_ref = p_device_ref; /* get device name */ String name; char c_name[256]; refCF = IOHIDDeviceGetProperty(p_device_ref, CFSTR(kIOHIDProductKey)); if (!refCF) { refCF = IOHIDDeviceGetProperty(p_device_ref, CFSTR(kIOHIDManufacturerKey)); } if ((!refCF) || (!CFStringGetCString((CFStringRef)refCF, c_name, sizeof(c_name), kCFStringEncodingUTF8))) { name = "Unidentified Joystick"; } name = c_name; int id = input->get_unused_joy_id(); ERR_FAIL_COND_V(id == -1, false); p_joy->id = id; int vendor = 0; refCF = IOHIDDeviceGetProperty(p_device_ref, CFSTR(kIOHIDVendorIDKey)); if (refCF) { CFNumberGetValue((CFNumberRef)refCF, kCFNumberSInt32Type, &vendor); } int product_id = 0; refCF = IOHIDDeviceGetProperty(p_device_ref, CFSTR(kIOHIDProductIDKey)); if (refCF) { CFNumberGetValue((CFNumberRef)refCF, kCFNumberSInt32Type, &product_id); } if (vendor && product_id) { char uid[128]; sprintf(uid, "%04x%08x%04x%08x", OSSwapHostToBigInt32(vendor), 0, OSSwapHostToBigInt32(product_id), 0); input->joy_connection_changed(id, true, name, uid); } else { //bluetooth device String guid = "05000000"; for (int i = 0; i < 12; i++) { if (i < name.size()) guid += _hex_str(name[i]); else guid += "00"; } input->joy_connection_changed(id, true, name, guid); } CFArrayRef array = NULL; array = IOHIDDeviceCopyMatchingElements(p_device_ref, NULL, kIOHIDOptionsTypeNone); if (array) { p_joy->add_hid_elements(array); CFRelease(array); } return true; }
static void match_callback(void *context, IOReturn result, void *sender, IOHIDDeviceRef device) { static int captured_devices = 0; static int failed_captures = 0; // dump instead of capturing if (false) { { CFTypeRef o = IOHIDDeviceGetProperty( device, CFSTR(kIOHIDDeviceUsagePairsKey)); printf("\tkIOHIDDeviceUsagePairsKey = %p\n", o); CFShow(o); } { CFTypeRef o = IOHIDDeviceGetProperty( device, CFSTR(kIOHIDElementKey)); printf("\tkIOHIDElementKey = %p\n", o); CFShow(o); } return; } IOReturn r = IOHIDDeviceOpen(device, kIOHIDOptionsTypeSeizeDevice); if (r == kIOReturnSuccess) { struct keyboard_handler *handler = (struct keyboard_handler*) malloc(sizeof(*handler)); memset(handler, 0x00, sizeof(*handler)); handler->index = captured_devices++; IOHIDDeviceRegisterInputReportCallback( device, handler->hid_report_buffer, sizeof(handler->hid_report_buffer), &got_hid_report, (void*) handler); move(handler->index + 1, 0); printw("%i <no reports yet>", handler->index); } else { failed_captures++; } move(0, 0); clrtoeol(); printw("Seized %i devices", captured_devices); if (failed_captures) { printw(" (%i failed)", failed_captures); } refresh(); }
static void add_device(void* context, IOReturn result, void* sender, IOHIDDeviceRef device) { char device_name[PATH_MAX_LENGTH]; CFStringRef device_name_ref; CFNumberRef vendorID, productID; struct pad_connection* connection = (struct pad_connection*) calloc(1, sizeof(*connection)); connection->device_handle = device; connection->slot = MAX_USERS; IOHIDDeviceOpen(device, kIOHIDOptionsTypeNone); /* Move the device's run loop to this thread. */ IOHIDDeviceScheduleWithRunLoop(device, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); IOHIDDeviceRegisterRemovalCallback(device, remove_device, connection); #ifndef IOS device_name_ref = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); CFStringGetCString(device_name_ref, device_name, sizeof(device_name), kCFStringEncodingUTF8); #endif vendorID = (CFNumberRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)); CFNumberGetValue(vendorID, kCFNumberIntType, &connection->v_id); productID = (CFNumberRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductIDKey)); CFNumberGetValue(productID, kCFNumberIntType, &connection->p_id); connection->slot = pad_connection_pad_init(slots, device_name, connection, &hid_pad_connection_send_control); if (pad_connection_has_interface(slots, connection->slot)) IOHIDDeviceRegisterInputReportCallback(device, connection->data + 1, sizeof(connection->data) - 1, hid_device_report, connection); else IOHIDDeviceRegisterInputValueCallback(device, hid_device_input_callback, connection); if (device_name[0] == '\0') return; strlcpy(g_settings.input.device_names[connection->slot], device_name, sizeof(g_settings.input.device_names)); input_config_autoconfigure_joypad(connection->slot, device_name, connection->v_id, connection->p_id, apple_hid_joypad.ident); RARCH_LOG("Port %d: %s.\n", connection->slot, device_name); }
static void hid_manager_device_attached(void* context, IOReturn result, void* sender, IOHIDDeviceRef device) { char device_name[1024]; CFStringRef device_name_ref; struct apple_pad_connection* connection = (struct apple_pad_connection*)calloc(1, sizeof(*connection)); connection->device = device; connection->slot = MAX_PLAYERS; IOHIDDeviceOpen(device, kIOHIDOptionsTypeNone); IOHIDDeviceScheduleWithRunLoop(device, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); IOHIDDeviceRegisterRemovalCallback(device, hid_device_removed, connection); device_name_ref = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); CFStringGetCString(device_name_ref, device_name, sizeof(device_name), kCFStringEncodingUTF8); connection->slot = apple_joypad_connect(device_name, connection); if (apple_joypad_has_interface(connection->slot)) IOHIDDeviceRegisterInputReportCallback(device, connection->data + 1, sizeof(connection->data) - 1, hid_device_report, connection); else IOHIDDeviceRegisterInputValueCallback(device, hid_device_input_callback, connection); if (device_name[0] != '\0') { strlcpy(g_settings.input.device_names[connection->slot], device_name, sizeof(g_settings.input.device_names)); input_config_autoconfigure_joypad(connection->slot, device_name, apple_joypad.ident); RARCH_LOG("Port %d: %s.\n", connection->slot, device_name); } }
static void build_joystick_list(joy_hid_device_array_t *dev_array) { int i; int num_devices = dev_array->num_internal_devices; CFArrayRef devices = dev_array->internal_devices; joy_hid_device_t *d = dev_array->devices; for ( i = 0; i < num_devices ; i++ ) { IOHIDDeviceRef dev = ( IOHIDDeviceRef ) CFArrayGetValueAtIndex( devices, i ); if(is_joystick(dev)) { long vendor_id = 0; IOHIDDevice_GetLongProperty( dev, CFSTR( kIOHIDVendorIDKey ), &vendor_id ); long product_id = 0; IOHIDDevice_GetLongProperty( dev, CFSTR( kIOHIDProductIDKey ), &product_id ); CFStringRef product_key; product_key = IOHIDDeviceGetProperty( dev, CFSTR( kIOHIDProductKey ) ); char *product_name = "N/A"; if(product_key) { char buffer[256]; if(CFStringGetCString(product_key, buffer, 256, kCFStringEncodingUTF8)) { product_name = strdup(buffer); } } d->internal_device = dev; d->vendor_id = (int)vendor_id; d->product_id = (int)product_id; d->serial = 0; /* will be filled in later */ d->product_name = product_name; d++; } } }
static int GetIntProperty(IOHIDDeviceRef device, CFStringRef key) { int value = 0; CFNumberRef ref = static_cast<CFNumberRef>(IOHIDDeviceGetProperty(device, key)); CFNumberGetValue(ref, kCFNumberSInt32Type, &value); return value; }
//--------------------------------------------------------------------------------- // // AllocateHIDObjectFromIOHIDDeviceRef( ) // // returns: // NULL, or acceptable io_object_t // //--------------------------------------------------------------------------------- io_service_t AllocateHIDObjectFromIOHIDDeviceRef(IOHIDDeviceRef inIOHIDDeviceRef) { io_service_t result = 0L; if ( inIOHIDDeviceRef ) { // Set up the matching criteria for the devices we're interested in. // We are interested in instances of class IOHIDDevice. // matchingDict is consumed below( in IOServiceGetMatchingService ) // so we have no leak here. CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOHIDDeviceKey); if ( matchingDict ) { // Add a key for locationID to our matching dictionary. This works for matching to // IOHIDDevices, so we will only look for a device attached to that particular port // on the machine. CFTypeRef tCFTypeRef = IOHIDDeviceGetProperty( inIOHIDDeviceRef, CFSTR(kIOHIDLocationIDKey) ); if ( tCFTypeRef ) { CFDictionaryAddValue(matchingDict, CFSTR(kIOHIDLocationIDKey), tCFTypeRef); // CFRelease( tCFTypeRef ); // don't release objects that we "Get". // IOServiceGetMatchingService assumes that we already know that there is only one device // that matches. This way we don't have to do the whole iteration dance to look at each // device that matches. This is a new API in 10.2 result = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict); } // Note: We're not leaking the matchingDict. // One reference is consumed by IOServiceGetMatchingServices } } return (result); } // AllocateHIDObjectFromIOHIDDeviceRef
static int get_string_property_utf8(IOHIDDeviceRef device, CFStringRef prop, char *buf, size_t len) { CFStringRef str = IOHIDDeviceGetProperty(device, prop); buf[0] = 0x0000; if (str) { CFRange range; range.location = 0; range.length = len; CFIndex used_buf_len; CFStringGetBytes(str, range, kCFStringEncodingUTF8, (char)'?', FALSE, (UInt8*)buf, len, &used_buf_len); buf[len-1] = 0x00000000; return used_buf_len; } else return 0; }
static int get_string_property_utf8(IOHIDDeviceRef device, CFStringRef prop, char *buf, size_t len) { CFStringRef str; if (!len) return 0; str = IOHIDDeviceGetProperty(device, prop); buf[0] = 0; if (str) { len--; CFIndex str_len = CFStringGetLength(str); CFRange range; range.location = 0; range.length = (str_len > len)? len: str_len; CFIndex used_buf_len; CFIndex chars_copied; chars_copied = CFStringGetBytes(str, range, kCFStringEncodingUTF8, (char)'?', FALSE, (UInt8*)buf, len, &used_buf_len); buf[chars_copied] = 0; return used_buf_len; } else return 0; }
void osxPointingDeviceManager::AddDevice(void *sender, IOReturn, void *, IOHIDDeviceRef devRef) { // Prevent other HID devices from being detected if (isNotPointingDevice(devRef)) return; osxPointingDeviceManager *self = (osxPointingDeviceManager *)sender; osxPointingDeviceData *pdd = new osxPointingDeviceData; fillDescriptorInfo(devRef, pdd->desc); pdd->devRef = devRef; self->registerDevice(devRef, pdd); CFDataRef descriptor = (CFDataRef)IOHIDDeviceGetProperty(devRef, CFSTR(kIOHIDReportDescriptorKey)); if (descriptor) { const UInt8 *bytes = CFDataGetBytePtr(descriptor); CFIndex length = CFDataGetLength(descriptor); if (!pdd->parser.setDescriptor(bytes, length)) { if (self->debugLevel > 1) std::cerr << " osxPointingDeviceManager::AddDevice: unable to parse the HID report descriptor" << std::endl; } else IOHIDDeviceRegisterInputReportCallback(devRef, pdd->report, sizeof(pdd->report), hidReportCallback, self); if (self->debugLevel > 1) { std::cerr << "HID descriptors: [ " << std::flush ; for (int i=0; i<length; ++i) std::cerr << std::hex << std::setfill('0') << std::setw(2) << (int)bytes[i] << " " ; std::cerr << "]" << std::endl ; } } }
long usbgetvalue(IOHIDDeviceRef device, CFStringRef key){ long res = 0; CFTypeRef output = IOHIDDeviceGetProperty(device, key); if(output && CFGetTypeID(output) == CFNumberGetTypeID() && CFNumberGetValue(output, kCFNumberLongType, &res)) return res; return 0; }
static int get_osx_device_name(int id, char *name, int length) { CFStringRef str; IOHIDDeviceRef tIOHIDDeviceRef; tIOHIDDeviceRef = get_device_ref(id); if (name) name[0] = 0; if (!tIOHIDDeviceRef) return 0; str = IOHIDDeviceGetProperty(tIOHIDDeviceRef, CFSTR( kIOHIDProductKey )); if (str) { CFIndex len = CFStringGetLength(str); if (length >= len) { CFStringGetCString(str,name,length,kCFStringEncodingASCII); return len; } else return (len+1); } return 0; }
static HRESULT get_ff(IOHIDDeviceRef device, FFDeviceObjectReference *ret) { io_service_t service; CFMutableDictionaryRef matching; CFTypeRef type; matching = IOServiceMatching(kIOHIDDeviceKey); if(!matching) { WARN("IOServiceMatching failed, force feedback disabled\n"); return DIERR_DEVICENOTREG; } type = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDLocationIDKey)); if(!matching) { CFRelease(matching); WARN("IOHIDDeviceGetProperty failed, force feedback disabled\n"); return DIERR_DEVICENOTREG; } CFDictionaryAddValue(matching, CFSTR(kIOHIDLocationIDKey), type); service = IOServiceGetMatchingService(kIOMasterPortDefault, matching); if(!ret) return FFIsForceFeedback(service) == FF_OK ? S_OK : S_FALSE; return osx_to_win32_hresult(FFCreateDevice(service, ret)); }
static void apple_hid_device_get_product_string(IOHIDDeviceRef device, char *buf, size_t len) { CFStringRef ref = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); if (ref) CFStringGetCString(ref, buf, len, kCFStringEncodingUTF8); }
static int _ykosx_getIntProperty( IOHIDDeviceRef dev, CFStringRef key ) { int result = 0; CFTypeRef tCFTypeRef = IOHIDDeviceGetProperty( dev, key ); if ( tCFTypeRef ) { if ( CFNumberGetTypeID( ) == CFGetTypeID( tCFTypeRef ) ) { CFNumberGetValue( ( CFNumberRef ) tCFTypeRef, kCFNumberSInt32Type, &result ); } } return result; }
int GamepadManager::getIntDeviceProperty(IOHIDDeviceRef device, CFStringRef key) { CFTypeRef type = IOHIDDeviceGetProperty(device, key); OVR_ASSERT(type != NULL && CFGetTypeID(type) == CFNumberGetTypeID()); int value; CFNumberGetValue((CFNumberRef) type, kCFNumberSInt32Type, &value); return value; }
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, char *string, size_t maxlen) { CFStringRef str = IOHIDDeviceGetProperty( dev->device_handle, CFSTR(kIOHIDProductKey) ); if ( str ) { CFStringGetCString( str, string, maxlen, kCFStringEncodingUTF8 ); return 0; } return -1; }
static int IOHIDDeviceGetIntProperty(IOHIDDeviceRef deviceRef, CFStringRef key) { CFTypeRef typeRef; int value; typeRef = IOHIDDeviceGetProperty(deviceRef, key); if (typeRef == NULL || CFGetTypeID(typeRef) != CFNumberGetTypeID()) { return 0; } CFNumberGetValue((CFNumberRef) typeRef, kCFNumberSInt32Type, &value); return value; }
HIDGamepad::HIDGamepad(IOHIDDeviceRef hidDevice) : m_hidDevice(hidDevice) { m_connectTime = m_lastUpdateTime = monotonicallyIncreasingTime(); CFNumberRef cfVendorID = (CFNumberRef)IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVendorIDKey)); CFNumberRef cfProductID = (CFNumberRef)IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductIDKey)); int vendorID, productID; CFNumberGetValue(cfVendorID, kCFNumberIntType, &vendorID); CFNumberGetValue(cfProductID, kCFNumberIntType, &productID); CFStringRef cfProductName = (CFStringRef)IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductKey)); String productName(cfProductName); // Currently the spec has no formatting for the id string. // This string formatting matches Firefox. m_id = String::format("%x-%x-%s", vendorID, productID, productName.utf8().data()); initElements(); }
void setKeyboard(struct __IOHIDDevice *device, CFDictionaryRef keyboardDictionary, LedState changes[]) { CFStringRef deviceNameRef = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); if (!deviceNameRef) return; const char * deviceName = CFStringGetCStringPtr(deviceNameRef, kCFStringEncodingUTF8); if (nameMatch && fnmatch(nameMatch, deviceName, 0) != 0) return; if (verbose) printf("\n \"%s\" ", deviceName); CFArrayRef elements = IOHIDDeviceCopyMatchingElements(device, keyboardDictionary, kIOHIDOptionsTypeNone); if (elements) { for (CFIndex elementIndex = 0; elementIndex < CFArrayGetCount(elements); elementIndex++) { IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, elementIndex); if (element && kHIDPage_LEDs == IOHIDElementGetUsagePage(element)) { uint32_t led = IOHIDElementGetUsage(element); if (led >= maxLeds) break; // Get current keyboard led status IOHIDValueRef currentValue = 0; if (IOHIDDeviceGetValue(device, element, ¤tValue) == kIOReturnSuccess && IOHIDValueGetLength(currentValue) < 3) { long current = IOHIDValueGetIntegerValue(currentValue); CFRelease(currentValue); // Should we try to set the led? if (changes[led] != NoChange && changes[led] != current) { IOHIDValueRef newValue = IOHIDValueCreateWithIntegerValue(kCFAllocatorDefault, element, 0, changes[led]); if (newValue) { IOReturn changeResult = IOHIDDeviceSetValue(device, element, newValue); // Was the change successful? if (kIOReturnSuccess == changeResult && verbose) { printf("%s%s ", stateSymbol[changes[led]], ledNames[led - 1]); } CFRelease(newValue); } } else if (verbose) { printf("%s%s ", stateSymbol[current], ledNames[led - 1]); } } } } CFRelease(elements); } if (verbose) printf("\n"); }
static u32 get_int_property(IOHIDDeviceRef device, CFStringRef key) { CFTypeRef ref; u32 value; ref = IOHIDDeviceGetProperty(device, key); if (ref) { if (CFGetTypeID(ref) == CFNumberGetTypeID() && CFNumberGetValue((CFNumberRef) ref, kCFNumberSInt32Type, &value)) { return value; } } return 0; }
static bool is_joypad(IOHIDDeviceRef p_device_ref) { int usage_page = 0; int usage = 0; CFTypeRef refCF = IOHIDDeviceGetProperty(p_device_ref, CFSTR(kIOHIDPrimaryUsagePageKey)); if (refCF) { CFNumberGetValue((CFNumberRef)refCF, kCFNumberSInt32Type, &usage_page); } if (usage_page != kHIDPage_GenericDesktop) { return false; } refCF = IOHIDDeviceGetProperty(p_device_ref, CFSTR(kIOHIDPrimaryUsageKey)); if (refCF) { CFNumberGetValue((CFNumberRef)refCF, kCFNumberSInt32Type, &usage); } if ((usage != kHIDUsage_GD_Joystick && usage != kHIDUsage_GD_GamePad && usage != kHIDUsage_GD_MultiAxisController)) { return false; } return true; }
static long get_long_property(IOHIDDeviceRef device, CFStringRef key) { CFTypeRef ref; int32_t value; ref = IOHIDDeviceGetProperty(device, key); if (ref) { if (CFGetTypeID(ref) == CFNumberGetTypeID()) { CFNumberGetValue((CFNumberRef) ref, kCFNumberSInt32Type, &value); return value; } } return 0; }
static int32_t iohidmanager_hid_device_get_int_property( IOHIDDeviceRef device, CFStringRef key) { int32_t value; CFNumberRef ref = (CFNumberRef)IOHIDDeviceGetProperty(device, key); if (ref && (CFGetTypeID(ref) == CFNumberGetTypeID())) { CFNumberGetValue((CFNumberRef)ref, kCFNumberIntType, &value); return value; } return 0; }
bool HIDDeviceManager::getStringProperty(IOHIDDeviceRef device, CFStringRef propertyName, String* pResult) { CFStringRef str = (CFStringRef) IOHIDDeviceGetProperty(device, propertyName); if (!str) { return false; } CFIndex length = CFStringGetLength(str); CFRange range = CFRangeMake(0, length); // Test the conversion first to get required buffer size. CFIndex bufferLength; CFIndex numberOfChars = CFStringGetBytes(str, range, kCFStringEncodingUTF8, (char) '?', FALSE, NULL, 0, &bufferLength); if (numberOfChars == 0) { return false; } // Now allocate buffer. char* buffer = new char[bufferLength+1]; numberOfChars = CFStringGetBytes(str, range, kCFStringEncodingUTF8, (char) '?', FALSE, (UInt8*) buffer, bufferLength, NULL); OVR_ASSERT_LOG(numberOfChars != 0, ("CFStringGetBytes failed.")); buffer[bufferLength] = '\0'; *pResult = String(buffer); return true; }
std::string IOKitHIDEventPublisher::getProperty(const IOHIDDeviceRef &device, const CFStringRef &property) { CFTypeRef value = IOHIDDeviceGetProperty(device, property); if (value == nullptr) { return ""; } // Only support CFNumber and CFString types. if (CFGetTypeID(value) == CFNumberGetTypeID()) { return stringFromCFNumber((CFDataRef)value); } else if (CFGetTypeID(value) == CFStringGetTypeID()) { return stringFromCFString((CFStringRef)value); } return ""; }
static Boolean IOHIDDevice_GetLongProperty( IOHIDDeviceRef inIOHIDDeviceRef, CFStringRef inKey, long * outValue ) { Boolean result = FALSE; if ( inIOHIDDeviceRef ) { CFTypeRef tCFTypeRef = IOHIDDeviceGetProperty( inIOHIDDeviceRef, inKey ); if ( tCFTypeRef ) { // if this is a number if ( CFNumberGetTypeID() == CFGetTypeID( tCFTypeRef ) ) { // get it's value result = CFNumberGetValue( ( CFNumberRef ) tCFTypeRef, kCFNumberSInt32Type, outValue ); } } } return result; } // IOHIDDevice_GetLongProperty
static void DeviceAttached(void* context, IOReturn result, void* sender, IOHIDDeviceRef device) { Connection* connection = new Connection(); connection->device = device; IOHIDDeviceOpen(device, kIOHIDOptionsTypeNone); IOHIDDeviceScheduleWithRunLoop(device, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); IOHIDDeviceRegisterRemovalCallback(device, DeviceRemoved, connection); CFStringRef device_name_ref = (CFStringRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); char device_name[1024]; CFStringGetCString(device_name_ref, device_name, sizeof(device_name), kCFStringEncodingUTF8); connection->hidpad = HIDPad::Connect(device_name, connection); IOHIDDeviceRegisterInputReportCallback(device, connection->data + 1, sizeof(connection->data) - 1, DeviceReport, connection); }