本文整理汇总了C++中IOHIDManagerCreate函数的典型用法代码示例。如果您正苦于以下问题:C++ IOHIDManagerCreate函数的具体用法?C++ IOHIDManagerCreate怎么用?C++ IOHIDManagerCreate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IOHIDManagerCreate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IOHIDManagerCreate
// open - open 1 or more devices
//
// Inputs:
// max = maximum number of devices to open
// vid = Vendor ID, or -1 if any
// pid = Product ID, or -1 if any
// usage_page = top level usage page, or -1 if any
// usage = top level usage number, or -1 if any
// Output:
// actual number of devices opened
//
int pjrc_rawhid::open(int max, int vid, int pid, int usage_page, int usage)
{
static IOHIDManagerRef hid_manager=NULL;
CFMutableDictionaryRef dict;
CFNumberRef num;
IOReturn ret;
hid_t *p;
int count=0;
if (first_hid) free_all_hid();
//printf("pjrc_rawhid_open, max=%d\n", max);
if (max < 1) return 0;
// Start the HID Manager
// http://developer.apple.com/technotes/tn2007/tn2187.html
if (!hid_manager) {
hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (hid_manager == NULL || CFGetTypeID(hid_manager) != IOHIDManagerGetTypeID()) {
if (hid_manager) CFRelease(hid_manager);
return 0;
}
}
if (vid > 0 || pid > 0 || usage_page > 0 || usage > 0) {
// Tell the HID Manager what type of devices we want
dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if (!dict) return 0;
if (vid > 0) {
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &vid);
CFDictionarySetValue(dict, CFSTR(kIOHIDVendorIDKey), num);
CFRelease(num);
}
if (pid > 0) {
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &pid);
CFDictionarySetValue(dict, CFSTR(kIOHIDProductIDKey), num);
CFRelease(num);
}
if (usage_page > 0) {
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage_page);
CFDictionarySetValue(dict, CFSTR(kIOHIDPrimaryUsagePageKey), num);
CFRelease(num);
}
if (usage > 0) {
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
CFDictionarySetValue(dict, CFSTR(kIOHIDPrimaryUsageKey), num);
CFRelease(num);
}
IOHIDManagerSetDeviceMatching(hid_manager, dict);
CFRelease(dict);
} else {
IOHIDManagerSetDeviceMatching(hid_manager, NULL);
}
// set up a callbacks for device attach & detach
IOHIDManagerScheduleWithRunLoop(hid_manager, CFRunLoopGetCurrent(),
kCFRunLoopDefaultMode);
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, attach_callback, NULL);
IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, detach_callback, NULL);
ret = IOHIDManagerOpen(hid_manager, kIOHIDOptionsTypeNone);
if (ret != kIOReturnSuccess) {
printf("Could not start IOHIDManager");
IOHIDManagerUnscheduleFromRunLoop(hid_manager,
CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
CFRelease(hid_manager);
return 0;
}
printf("run loop\n");
// let it do the callback for all devices
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true) == kCFRunLoopRunHandledSource) ;
// count up how many were added by the callback
for (p = first_hid; p; p = p->next) count++;
return count;
}
示例2: init_hid_manager
/* Initialize the IOHIDManager. Return 0 for success and -1 for failure. */
static int init_hid_manager(void)
{
/* Initialize all the HID Manager Objects */
hid_mgr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (hid_mgr) {
IOHIDManagerSetDeviceMatching(hid_mgr, NULL);
IOHIDManagerScheduleWithRunLoop(hid_mgr, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
return 0;
}
return -1;
}
示例3: OSX_Mouse_Thread
static int OSX_Mouse_Thread(void *ctx)
{
if (!ctx)
return 0;
struct osx_mouse_data *mdata = static_cast<struct osx_mouse_data *>(ctx);
IOHIDManagerRef hid_manager = IOHIDManagerCreate(kCFAllocatorSystemDefault, kIOHIDOptionsTypeNone);
if (!hid_manager) {
SDL_DestroyMutex(mdata->mouse_mutex);
delete mdata;
return 0;
}
if (IOHIDManagerOpen(hid_manager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) {
CFRelease(hid_manager);
SDL_DestroyMutex(mdata->mouse_mutex);
delete mdata;
return 0;
}
IOHIDManagerRegisterInputValueCallback(hid_manager, input_callback, mdata);
IOHIDManagerScheduleWithRunLoop(hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
uint32_t page = kHIDPage_GenericDesktop;
uint32_t usage = kHIDUsage_GD_Mouse;
CFDictionaryRef dict = NULL;
CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
const void *keys[2] = { CFSTR(kIOHIDDeviceUsagePageKey), CFSTR(kIOHIDDeviceUsageKey) };
const void *vals[2] = { pageNumRef, usageNumRef };
if (pageNumRef && usageNumRef)
dict = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if (pageNumRef)
CFRelease(pageNumRef);
if (usageNumRef)
CFRelease(usageNumRef);
IOHIDManagerSetDeviceMatching(hid_manager, dict);
if (dict)
CFRelease(dict);
while (!mdata->should_exit) {
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, false);
}
IOHIDManagerUnscheduleFromRunLoop(hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDManagerClose(hid_manager, kIOHIDOptionsTypeNone);
CFRelease(hid_manager);
SDL_DestroyMutex(mdata->mouse_mutex);
delete mdata;
return 0;
}
示例4: Gamepad_init
void Gamepad_init() {
if (hidManager == NULL) {
CFStringRef keys[2];
int value;
CFNumberRef values[2];
CFDictionaryRef dictionaries[3];
CFArrayRef array;
hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone);
IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
keys[0] = CFSTR(kIOHIDDeviceUsagePageKey);
keys[1] = CFSTR(kIOHIDDeviceUsageKey);
value = kHIDPage_GenericDesktop;
values[0] = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value);
value = kHIDUsage_GD_Joystick;
values[1] = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value);
dictionaries[0] = CFDictionaryCreate(kCFAllocatorDefault, (const void **) keys, (const void **) values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFRelease(values[0]);
CFRelease(values[1]);
value = kHIDPage_GenericDesktop;
values[0] = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value);
value = kHIDUsage_GD_GamePad;
values[1] = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value);
dictionaries[1] = CFDictionaryCreate(kCFAllocatorDefault, (const void **) keys, (const void **) values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFRelease(values[0]);
CFRelease(values[1]);
value = kHIDPage_GenericDesktop;
values[0] = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value);
value = kHIDUsage_GD_MultiAxisController;
values[1] = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value);
dictionaries[2] = CFDictionaryCreate(kCFAllocatorDefault, (const void **) keys, (const void **) values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFRelease(values[0]);
CFRelease(values[1]);
array = CFArrayCreate(kCFAllocatorDefault, (const void **) dictionaries, 3, &kCFTypeArrayCallBacks);
CFRelease(dictionaries[0]);
CFRelease(dictionaries[1]);
CFRelease(dictionaries[2]);
IOHIDManagerSetDeviceMatchingMultiple(hidManager, array);
CFRelease(array);
IOHIDManagerRegisterDeviceMatchingCallback(hidManager, onDeviceMatched, NULL);
IOHIDManagerRegisterDeviceRemovalCallback(hidManager, onDeviceRemoved, NULL);
}
}
示例5: usbinit
int usbinit(){
// Create the device manager
if(!(usbmanager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeSeizeDevice))){
printf("Fatal: Failed to create device manager\n");
return -1;
}
// Start the device thread
if(pthread_create(&usbthread, 0, threadrun, 0)){
printf("Fatal: Failed to start USB thread\n");
return -1;
}
return 0;
}
示例6: init_hid_manager
static int init_hid_manager(void)
{
IOReturn res;
/* Initialize all the HID Manager Objects */
hid_mgr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
IOHIDManagerSetDeviceMatching(hid_mgr, NULL);
IOHIDManagerScheduleWithRunLoop(hid_mgr, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
res = IOHIDManagerOpen(hid_mgr, kIOHIDOptionsTypeNone);
if(res == kIOReturnSuccess)
return 0;
fprintf(stderr, "IOReturn error code: 0x%x\n", err_get_code(res));
return -1;
}
示例7: initializeResumeNotifications
static void initializeResumeNotifications (void) // see TN 2187
{
IOHIDManagerRef hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (! hidManager) {
message (LOG_ERR, "IOHIDManagerCreate failed\n");
exit (1);
}
if (IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) {
message (LOG_ERR, "IOHIDManagerOpen failed\n");
exit (1);
}
IOHIDManagerScheduleWithRunLoop (hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDManagerSetDeviceMatchingMultiple (hidManager, createGenericDesktopMatchingDictionaries());
IOHIDManagerRegisterInputValueCallback (hidManager, hidCallback, (void *) -1);
}
示例8: StartUp
void StartUp()
{
g_hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
CFMutableArrayRef matcher = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
append_matching_dictionary(matcher, kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick);
append_matching_dictionary(matcher, kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad);
IOHIDManagerSetDeviceMatchingMultiple(g_hid_manager, matcher);
CFRelease(matcher);
IOHIDManagerRegisterDeviceMatchingCallback(g_hid_manager, DeviceAttached, 0);
IOHIDManagerScheduleWithRunLoop(g_hid_manager, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
IOHIDManagerOpen(g_hid_manager, kIOHIDOptionsTypeNone);
}
示例9: iohidmanager_hid_manager_init
static int iohidmanager_hid_manager_init(iohidmanager_hid_t *hid)
{
if (!hid)
return -1;
if (hid->ptr) /* already initialized. */
return 0;
hid->ptr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!hid->ptr)
return -1;
IOHIDManagerSetDeviceMatching(hid->ptr, NULL);
IOHIDManagerScheduleWithRunLoop(hid->ptr, CFRunLoopGetCurrent(),
kCFRunLoopDefaultMode);
return 0;
}
示例10: yUSB_init
int yUSB_init(yContextSt *ctx,char *errmsg)
{
int c_vendorid = YOCTO_VENDORID;
IOReturn tIOReturn;
CFMutableDictionaryRef dictionary;
CFNumberRef Vendorid;
if(!yReserveGlobalAccess(ctx)){
return YERRMSG(YAPI_DOUBLE_ACCES,"Another process is already using yAPI");
}
ctx->usb_thread_state = USB_THREAD_NOT_STARTED;
pthread_create(&ctx->usb_thread, NULL, event_thread, ctx);
yInitializeCriticalSection(&ctx->hidMCS);
// Initialize HID Manager
ctx->hidM = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
// create dictionary to match Yocto devices
dictionary = CFDictionaryCreateMutable(kCFAllocatorDefault,1,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks);
Vendorid = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &c_vendorid );
CFDictionarySetValue( dictionary, CFSTR( kIOHIDVendorIDKey ), Vendorid );
// register the dictionary
IOHIDManagerSetDeviceMatching( ctx->hidM, dictionary );
// now we can release the dictionary
CFRelease(dictionary);
IOHIDManagerRegisterDeviceRemovalCallback(ctx->hidM,hid_device_removal_callback,ctx);
//register hid into read_thead's RunnLoop
while(ctx->usb_thread_state != USB_THREAD_RUNNING){
usleep(50000);
}
IOHIDManagerScheduleWithRunLoop(ctx->hidM, ctx->usb_run_loop, kCFRunLoopDefaultMode);
// Now open the IO HID Manager reference
tIOReturn = IOHIDManagerOpen( ctx->hidM, kIOHIDOptionsTypeNone );
CFRelease(Vendorid);
if(kIOReturnSuccess != tIOReturn ||CFGetTypeID(ctx->hidM) != IOHIDManagerGetTypeID()){
HALLOG("Unable to Open HID Manager");
return YERRMSG(YAPI_NOT_SUPPORTED,"Unable to Open HID Manager");
}
return YAPI_SUCCESS;
}
示例11: joy_hidlib_init
int joy_hidlib_init(void)
{
if ( !mgr ) {
// create the manager
mgr = IOHIDManagerCreate( kCFAllocatorDefault, 0L );
}
if ( mgr ) {
// open it
IOReturn tIOReturn = IOHIDManagerOpen( mgr, 0L);
if ( kIOReturnSuccess != tIOReturn ) {
return -1;
} else {
IOHIDManagerSetDeviceMatching( mgr, NULL );
return 0;
}
} else {
return -1;
}
}
示例12: setAllKeyboards
void setAllKeyboards(LedState changes[])
{
IOHIDManagerRef manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!manager) {
fprintf(stderr, "Failed to create IOHID manager.\n");
return;
}
CFDictionaryRef keyboard = getKeyboardDictionary();
if (!keyboard) {
fprintf(stderr, "Failed to get dictionary usage page for kHIDUsage_GD_Keyboard.\n");
return;
}
IOHIDManagerOpen(manager, kIOHIDOptionsTypeNone);
IOHIDManagerSetDeviceMatching(manager, keyboard);
CFSetRef devices = IOHIDManagerCopyDevices(manager);
if (devices) {
CFIndex deviceCount = CFSetGetCount(devices);
if (deviceCount == 0) {
fprintf(stderr, "Could not find any keyboard devices.\n");
}
else {
// Loop through all keyboards attempting to get or display led state
IOHIDDeviceRef *deviceRefs = malloc(sizeof(IOHIDDeviceRef) * deviceCount);
if (deviceRefs) {
CFSetGetValues(devices, (const void **) deviceRefs);
for (CFIndex deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++)
if (isKeyboardDevice(deviceRefs[deviceIndex]))
setKeyboard(deviceRefs[deviceIndex], keyboard, changes);
free(deviceRefs);
}
}
CFRelease(devices);
}
CFRelease(keyboard);
}
示例13: dump_hid_value
dump_hid_value(void) {
manager_ = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!manager_) {
return;
}
auto device_matching_dictionaries = iokit_utility::create_device_matching_dictionaries({
std::make_pair(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard),
std::make_pair(kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse),
std::make_pair(kHIDPage_GenericDesktop, kHIDUsage_GD_Pointer),
});
if (device_matching_dictionaries) {
IOHIDManagerSetDeviceMatchingMultiple(manager_, device_matching_dictionaries);
CFRelease(device_matching_dictionaries);
IOHIDManagerRegisterDeviceMatchingCallback(manager_, static_device_matching_callback, this);
IOHIDManagerRegisterDeviceRemovalCallback(manager_, static_device_removal_callback, this);
IOHIDManagerScheduleWithRunLoop(manager_, CFRunLoopGetMain(), kCFRunLoopDefaultMode);
}
}
示例14: stop
void IOKitHIDEventPublisher::restart() {
if (run_loop_ == nullptr) {
// There is no run loop to restart.
return;
}
// Remove any existing stream.
stop();
if (manager_ == nullptr) {
manager_ = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
}
// Match anything.
IOHIDManagerSetDeviceMatching(manager_, nullptr);
auto status = IOHIDManagerOpen(manager_, kIOHIDOptionsTypeNone);
if (status != kIOReturnSuccess) {
LOG(WARNING) << RLOG(617) << "Cannot open IOKit HID Manager";
return;
}
// Enumerate initial set of devices matched before time=0.
CFSetRef devices = IOHIDManagerCopyDevices(manager_);
if (devices == nullptr) {
return;
}
initial_device_count_ = CFSetGetCount(devices);
CFRelease(devices);
// Register callbacks.
IOHIDManagerRegisterDeviceMatchingCallback(
manager_, IOKitHIDEventPublisher::MatchingCallback, nullptr);
IOHIDManagerRegisterDeviceRemovalCallback(
manager_, IOKitHIDEventPublisher::RemovalCallback, nullptr);
IOHIDManagerScheduleWithRunLoop(manager_, run_loop_, kCFRunLoopDefaultMode);
manager_started_ = true;
}
示例15: main
int main(void)
{
IOHIDManagerRef mgr;
int i;
mgr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
IOHIDManagerSetDeviceMatching(mgr, NULL);
IOHIDManagerOpen(mgr, kIOHIDOptionsTypeNone);
CFSetRef device_set = IOHIDManagerCopyDevices(mgr);
if (device_set==NULL) {
return 0;
}
CFIndex num_devices = CFSetGetCount(device_set);
IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
CFSetGetValues(device_set, (const void **) device_array);
for (i = 0; i < num_devices; i++) {
IOHIDDeviceRef dev = device_array[i];
printf("Device: %p\n", dev);
printf(" %04hx %04hx\n", get_vendor_id(dev), get_product_id(dev));
wchar_t serial[256], buf[256];
char cbuf[256];
get_serial_number(dev, serial, 256);
printf(" Serial: %ls\n", serial);
printf(" Loc: %ld\n", get_location_id(dev));
get_transport(dev, buf, 256);
printf(" Trans: %ls\n", buf);
make_path(dev, cbuf, 256);
printf(" Path: %s\n", cbuf);
}
return 0;
}