本文整理汇总了C++中IOHIDDeviceGetProperty函数的典型用法代码示例。如果您正苦于以下问题:C++ IOHIDDeviceGetProperty函数的具体用法?C++ IOHIDDeviceGetProperty怎么用?C++ IOHIDDeviceGetProperty使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IOHIDDeviceGetProperty函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_hid
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;
}
示例2: attach_callback
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;
}
}
示例3: IOHIDDeviceGetProperty
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;
}
示例4: match_callback
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();
}
示例5: add_device
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);
}
示例6: hid_manager_device_attached
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);
}
}
示例7: build_joystick_list
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++;
}
}
}
示例8: GetIntProperty
static int GetIntProperty(IOHIDDeviceRef device, CFStringRef key)
{
int value = 0;
CFNumberRef ref = static_cast<CFNumberRef>(IOHIDDeviceGetProperty(device, key));
CFNumberGetValue(ref, kCFNumberSInt32Type, &value);
return value;
}
示例9: AllocateHIDObjectFromIOHIDDeviceRef
//---------------------------------------------------------------------------------
//
// 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
示例10: get_string_property_utf8
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;
}
示例11: get_string_property_utf8
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;
}
示例12: fillDescriptorInfo
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 ;
}
}
}
示例13: usbgetvalue
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;
}
示例14: get_osx_device_name
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;
}
示例15: get_ff
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));
}