本文整理汇总了C++中IOHIDManagerCreate函数的典型用法代码示例。如果您正苦于以下问题:C++ IOHIDManagerCreate函数的具体用法?C++ IOHIDManagerCreate怎么用?C++ IOHIDManagerCreate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IOHIDManagerCreate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:samguns,项目名称:OpenPilot,代码行数:82,代码来源:pjrc_rawhid_mac.cpp
示例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;
}
开发者ID:Cloudhomebr,项目名称:node-openzwave,代码行数:13,代码来源:hid.c
示例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;
}
开发者ID:blezek,项目名称:marathon-ios,代码行数:53,代码来源:mouse_cocoa.cpp
示例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);
}
}
开发者ID:arpg,项目名称:commander-node,代码行数:52,代码来源:Gamepad_macosx.cpp
示例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;
}
开发者ID:jsnel,项目名称:ckb,代码行数:13,代码来源:usb_mac.c
示例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;
}
开发者ID:darthrake,项目名称:hidapi,代码行数:15,代码来源:hid.c
示例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);
}
开发者ID:Gems,项目名称:majormaco,代码行数:15,代码来源:sleepwatcher.c
示例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);
}
开发者ID:RandomName001,项目名称:MFiWrapper,代码行数:16,代码来源:HIDManager_OSX.cpp
示例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;
}
开发者ID:Monroe88,项目名称:RetroArch,代码行数:17,代码来源:iohidmanager_hid.c
示例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;
}
开发者ID:octet8,项目名称:yoctolib_cpp,代码行数:44,代码来源:ypkt_osx.c
示例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;
}
}
开发者ID:BigBoss21X,项目名称:vice-emu,代码行数:19,代码来源:joy-hidmgr.c
示例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);
}
开发者ID:pawlowskialex,项目名称:CAPS,代码行数:41,代码来源:keyboard_leds.c
示例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);
}
}
开发者ID:yangjinzhong,项目名称:Karabiner-Elements,代码行数:21,代码来源:main.cpp
示例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;
}
开发者ID:eastebry,项目名称:osquery,代码行数:40,代码来源:iokit_hid.cpp
示例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;
}
开发者ID:rsravanreddy,项目名称:hidapi,代码行数:39,代码来源:hid.c
示例16: IOHIDManagerCreate
osxPointingDeviceManager::osxPointingDeviceManager()
{
manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!manager)
throw std::runtime_error("IOHIDManagerCreate failed");
const char *plist = hidDeviceFromVendorProductUsagePageUsage(0, 0, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse).c_str();
CFMutableDictionaryRef device_match = (CFMutableDictionaryRef)getPropertyListFromXML(plist);
IOHIDManagerSetDeviceMatching(manager, device_match);
IOHIDManagerRegisterDeviceMatchingCallback(manager, AddDevice, (void*)this);
IOHIDManagerRegisterDeviceRemovalCallback(manager, RemoveDevice, (void*)this);
#if USE_CURRENT_RUNLOOP
CFRunLoopRef runLoop = CFRunLoopGetCurrent();
CFStringRef runLoopMode = kCFRunLoopDefaultMode;
#else
CFRunLoopRef runLoop = CFRunLoopGetMain();
CFStringRef runLoopMode = kCFRunLoopCommonModes;
#endif
IOHIDManagerScheduleWithRunLoop(manager, runLoop, runLoopMode);
}
开发者ID:hemantsurale,项目名称:libpointing,代码行数:22,代码来源:osxPointingDeviceManager.cpp
示例17: pthread_mutex_lock
static void *Sys_Input_Thread(void *inarg)
{
struct input_data *input;
IOReturn tIOReturn;
input = inarg;
pthread_mutex_lock(&input->thread_mutex);
input->threadrunloop = CFRunLoopGetCurrent();
pthread_cond_signal(&input->thread_has_spawned);
pthread_mutex_unlock(&input->thread_mutex);
input->hid_manager = IOHIDManagerCreate(kCFAllocatorSystemDefault, kIOHIDOptionsTypeNone);
if (input->hid_manager)
{
IOHIDManagerSetDeviceMatching(input->hid_manager, NULL);
IOHIDManagerRegisterInputValueCallback(input->hid_manager, input_callback, input);
IOHIDManagerScheduleWithRunLoop(input->hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
tIOReturn = IOHIDManagerOpen(input->hid_manager, kIOHIDOptionsTypeNone);
if (tIOReturn == kIOReturnSuccess)
{
do
{
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, true);
}
while (!input->thread_shutdown);
}
IOHIDManagerUnscheduleFromRunLoop(input->hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
}
CFRelease(input->hid_manager);
return 0;
}
开发者ID:classicQ,项目名称:classicQ.github.io,代码行数:37,代码来源:in_macosx.c
示例18: apple_joypad_init
// RetroArch joypad driver:
static bool apple_joypad_init(void)
{
#ifdef OSX
CFMutableArrayRef matcher;
if (!g_hid_manager)
{
g_hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
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, hid_manager_device_attached, 0);
IOHIDManagerScheduleWithRunLoop(g_hid_manager, CFRunLoopGetMain(), kCFRunLoopCommonModes);
IOHIDManagerOpen(g_hid_manager, kIOHIDOptionsTypeNone);
}
#endif
return true;
}
开发者ID:DerrrekWang,项目名称:RetroArch,代码行数:25,代码来源:apple_joypad.c
示例19: IOHIDManagerCreate
CPH_HidMacOSX::CPH_HidMacOSX()
{
m_bindings[PS2::CControllerInfo::ANALOG_LEFT_X] = std::make_shared<CSimulatedAxisBinding>(kHIDUsage_KeyboardD, kHIDUsage_KeyboardG);
m_bindings[PS2::CControllerInfo::ANALOG_LEFT_Y] = std::make_shared<CSimulatedAxisBinding>(kHIDUsage_KeyboardR, kHIDUsage_KeyboardF);
m_bindings[PS2::CControllerInfo::ANALOG_RIGHT_X] = std::make_shared<CSimulatedAxisBinding>(kHIDUsage_KeyboardH, kHIDUsage_KeyboardK);
m_bindings[PS2::CControllerInfo::ANALOG_RIGHT_Y] = std::make_shared<CSimulatedAxisBinding>(kHIDUsage_KeyboardU, kHIDUsage_KeyboardJ);
m_bindings[PS2::CControllerInfo::START] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardReturnOrEnter);
m_bindings[PS2::CControllerInfo::SELECT] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardRightShift);
m_bindings[PS2::CControllerInfo::DPAD_LEFT] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardLeftArrow);
m_bindings[PS2::CControllerInfo::DPAD_RIGHT] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardRightArrow);
m_bindings[PS2::CControllerInfo::DPAD_UP] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardUpArrow);
m_bindings[PS2::CControllerInfo::DPAD_DOWN] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardDownArrow);
m_bindings[PS2::CControllerInfo::SQUARE] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardA);
m_bindings[PS2::CControllerInfo::CROSS] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardZ);
m_bindings[PS2::CControllerInfo::TRIANGLE] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardS);
m_bindings[PS2::CControllerInfo::CIRCLE] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardX);
m_bindings[PS2::CControllerInfo::L1] = std::make_shared<CSimpleBinding>(kHIDUsage_Keyboard1);
m_bindings[PS2::CControllerInfo::L2] = std::make_shared<CSimpleBinding>(kHIDUsage_Keyboard2);
m_bindings[PS2::CControllerInfo::L3] = std::make_shared<CSimpleBinding>(kHIDUsage_Keyboard3);
m_bindings[PS2::CControllerInfo::R1] = std::make_shared<CSimpleBinding>(kHIDUsage_Keyboard8);
m_bindings[PS2::CControllerInfo::R2] = std::make_shared<CSimpleBinding>(kHIDUsage_Keyboard9);
m_bindings[PS2::CControllerInfo::R3] = std::make_shared<CSimpleBinding>(kHIDUsage_Keyboard0);
m_hidManager = IOHIDManagerCreate(kCFAllocatorDefault, 0);
{
CFDictionaryRef matchingDict = CreateDeviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard);
IOHIDManagerSetDeviceMatching(m_hidManager, matchingDict);
CFRelease(matchingDict);
}
IOHIDManagerScheduleWithRunLoop(m_hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDManagerOpen(m_hidManager, kIOHIDOptionsTypeNone);
IOHIDManagerRegisterInputValueCallback(m_hidManager, InputValueCallbackStub, this);
}
开发者ID:AntKingSuplexCity,项目名称:Play-,代码行数:36,代码来源:PH_HidMacOSX.cpp
示例20: main
int main( int argc, const char * argv[] )
{
Boolean initialized = FALSE;
if (( argc != 4 ) && ( argc != 5 )) {
printf ( "usage: Dream Cheeky Notifier R G B [A]\n\tRGB values should be 0-31. A is an optional parameter on whether to do the LED activation sequence. Anything larger than 0 is YES, default is 0 (activate).\n\n");
exit ( -1 );
}
char r = (int)strtol ( argv[1], NULL, 10 );
char g = (int)strtol ( argv[2], NULL, 10 );
char b = (int)strtol ( argv[3], NULL, 10 );
if ( argc == 5 ) {
initialized = TRUE;
}
if ((r < 0) || (r > 31) || (g < 0) || (g > 31) || (b < 0) || (b > 31)) {
printf("RGB values must be within 0-31.");
exit -1;
}
// create a IO HID Manager reference
IOHIDManagerRef tIOHIDManagerRef = IOHIDManagerCreate( kCFAllocatorDefault, kIOHIDOptionsTypeNone );
// Create a device matching dictionary
CFDictionaryRef matchingCFDictRef = hu_CreateMatchingDictionaryUsagePageUsage( TRUE,
kHIDPage_GenericDesktop,
0x10 );
// set the HID device matching dictionary
IOHIDManagerSetDeviceMatching( tIOHIDManagerRef, matchingCFDictRef );
if ( matchingCFDictRef ) {
CFRelease( matchingCFDictRef );
}
// Now open the IO HID Manager reference
IOReturn tIOReturn = IOHIDManagerOpen( tIOHIDManagerRef, kIOHIDOptionsTypeNone );
// and copy out its devices
CFSetRef deviceCFSetRef = IOHIDManagerCopyDevices( tIOHIDManagerRef );
// how many devices in the set?
CFIndex deviceIndex, deviceCount = CFSetGetCount( deviceCFSetRef );
// allocate a block of memory to extact the device ref's from the set into
IOHIDDeviceRef * tIOHIDDeviceRefs = malloc( sizeof( IOHIDDeviceRef ) * deviceCount );
// now extract the device ref's from the set
CFSetGetValues( deviceCFSetRef, (const void **) tIOHIDDeviceRefs );
// before we get into the device loop we'll setup our element matching dictionary (Note: we don't do element matching anymore)
matchingCFDictRef = hu_CreateMatchingDictionaryUsagePageUsage( FALSE, 0, 0 );
for ( deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++ ) {
// if this isn't the notifier device... TODO: let's detect via vendor/product ids instead
long vendor_id = 0;
IOHIDDevice_GetLongProperty(tIOHIDDeviceRefs[deviceIndex], CFSTR(kIOHIDVendorIDKey), &vendor_id);
long product_id = 0;
IOHIDDevice_GetLongProperty(tIOHIDDeviceRefs[deviceIndex], CFSTR(kIOHIDProductIDKey), &product_id);
if ((vendor_id != 0x1D34 ) || (product_id != 0x0004 )) {
printf(" skipping device %p.\n", tIOHIDDeviceRefs[deviceIndex] );
continue; // ...skip it
}
printf( " device = %p.\n", tIOHIDDeviceRefs[deviceIndex] );
unsigned char report[8];
if (initialized == FALSE) {
report[0] = 0x1F; // turn on LEDs
report[1] = 0x02;
report[2] = 0x00;
report[3] = 0x5F;
report[4] = 0x00;
report[5] = 0x00;
report[6] = 0x1A;
report[7] = 0x03;
// Note: We don't use the returned value here, so the compiler might throw a warning.
IOReturn tIOReturn = IOHIDDeviceSetReport(
tIOHIDDeviceRefs[deviceIndex], // IOHIDDeviceRef for the HID device
kIOHIDReportTypeInput, // IOHIDReportType for the report (input, output, feature)
0, // CFIndex for the report ID
report, // address of report buffer
8); // length of the report
initialized = TRUE;
}
report[0] = r; // set brightness on LEDs to r, g, & b
report[1] = g;
report[2] = b;
report[3] = 0x00;
report[4] = 0x00;
report[5] = 0x00;
report[6] = 0x1A;
report[7] = 0x05;
tIOReturn = IOHIDDeviceSetReport(
tIOHIDDeviceRefs[deviceIndex], // IOHIDDeviceRef for the HID device
kIOHIDReportTypeInput, // IOHIDReportType for the report (input, output, feature)
0, // CFIndex for the report ID
report, // address of report buffer
//.........这里部分代码省略.........
开发者ID:edelbrp,项目名称:dream-cheeky-notifier-macosx,代码行数:101,代码来源:main.c
注:本文中的IOHIDManagerCreate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论