本文整理汇总了C++中IOHIDDeviceRegisterInputReportCallback函数的典型用法代码示例。如果您正苦于以下问题:C++ IOHIDDeviceRegisterInputReportCallback函数的具体用法?C++ IOHIDDeviceRegisterInputReportCallback怎么用?C++ IOHIDDeviceRegisterInputReportCallback使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IOHIDDeviceRegisterInputReportCallback函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OVR_ASSERT
void HIDDevice::closeDevice(bool wasUnplugged)
{
OVR_ASSERT(Device != NULL);
if (!wasUnplugged)
{
// Clear the registered callbacks.
IOHIDDeviceRegisterInputReportCallback(Device,
ReadBuffer,
InputReportBufferLength,
NULL,
this);
IOHIDDeviceRegisterRemovalCallback(Device, NULL, this);
IOHIDDeviceUnscheduleFromRunLoop(Device,
HIDManager->getRunLoop(),
kCFRunLoopDefaultMode);
IOHIDDeviceClose(Device, kIOHIDOptionsTypeNone);
}
CFRelease(Device);
Device = NULL;
LogText("OVR::OSX::HIDDevice - HID Device Closed '%s'\n", DevDesc.Path.ToCStr());
}
示例2: iohidmanager_hid_device_add
static void iohidmanager_hid_device_add(void *data, IOReturn result,
void* sender, IOHIDDeviceRef device)
{
IOReturn ret;
uint16_t dev_vid, dev_pid;
settings_t *settings = config_get_ptr();
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)hid_driver_get_data();
struct iohidmanager_hid_adapter *adapter = (struct iohidmanager_hid_adapter*)
calloc(1, sizeof(*adapter));
if (!adapter || !hid)
return;
adapter->handle = device;
ret = IOHIDDeviceOpen(device, kIOHIDOptionsTypeNone);
if (ret != kIOReturnSuccess)
{
free(adapter);
return;
}
/* Move the device's run loop to this thread. */
IOHIDDeviceScheduleWithRunLoop(device, CFRunLoopGetCurrent(),
kCFRunLoopCommonModes);
IOHIDDeviceRegisterRemovalCallback(device, iohidmanager_hid_device_remove, adapter);
#ifndef IOS
iohidmanager_hid_device_get_product_string(device, adapter->name,
sizeof(adapter->name));
#endif
dev_vid = iohidmanager_hid_device_get_vendor_id (device);
dev_pid = iohidmanager_hid_device_get_product_id (device);
adapter->slot = pad_connection_pad_init(hid->slots,
adapter->name, dev_vid, dev_pid, adapter, &iohidmanager_hid_device_send_control);
if (adapter->slot == -1)
return;
if (pad_connection_has_interface(hid->slots, adapter->slot))
IOHIDDeviceRegisterInputReportCallback(device,
adapter->data + 1, sizeof(adapter->data) - 1,
iohidmanager_hid_device_report, adapter);
else
IOHIDDeviceRegisterInputValueCallback(device,
iohidmanager_hid_device_input_callback, adapter);
if (adapter->name[0] == '\0')
return;
strlcpy(settings->input.device_names[adapter->slot],
adapter->name, sizeof(settings->input.device_names[adapter->slot]));
iohidmanager_hid_device_add_autodetect(adapter->slot,
adapter->name, iohidmanager_hid.ident, dev_vid, dev_pid);
}
示例3: 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 ;
}
}
}
示例4: yyyPacketShutdown
void yyyPacketShutdown(yInterfaceSt *iface)
{
int i;
// remove iface from setuped ifaces
for (i=0; i< SETUPED_IFACE_CACHE_SIZE ; i++) {
if(yContext->setupedIfaceCache[i]==iface){
yContext->setupedIfaceCache[i] = NULL;
break;
}
}
YASSERT(i<SETUPED_IFACE_CACHE_SIZE);
if(iface->devref!=NULL){
IOHIDDeviceRegisterInputReportCallback(iface->devref, // IOHIDDeviceRef for the HID device
(u8*) &iface->tmprxpkt, // pointer to the report data (uint8_t's)
USB_PKT_SIZE, // number of bytes in the report (CFIndex)
NULL, // the callback routine
iface); // context passed to callback
IOHIDDeviceClose(iface->devref, kIOHIDOptionsTypeNone);
iface->devref=NULL;
}
yPktQueueFree(&iface->rxQueue);
yPktQueueFree(&iface->txQueue);
iface->flags.yyySetupDone = 0;
CFRelease(iface->run_loop_mode);
if (yContext->osx_flags & YCTX_OSX_MULTIPLES_HID) {
stopHIDManager(&iface->hid);
}
}
示例5: attach_callback
static void attach_callback(void *context, IOReturn r, void *hid_mgr, IOHIDDeviceRef dev)
{
struct hid_struct *h;
//fprintf(stderr,"attach callback\n");
//
if (IOHIDDeviceOpen(dev, kIOHIDOptionsTypeNone) != kIOReturnSuccess) return;
h = (hid_t *)malloc(sizeof(hid_t));
if (!h) return;
memset(h, 0, sizeof(hid_t));
IOHIDDeviceScheduleWithRunLoop(dev, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDDeviceRegisterInputReportCallback(dev, h->buffer, sizeof(h->buffer),
input_callback, h);
h->ref = dev;
h->open = 1;
add_hid(h);
usbstatus=1;
/*
r = rawhid_open(1, 0x16C0, 0x0480, 0xFFAB, 0x0200);
if (r <= 0)
{
fprintf(stderr,"no rawhid device found\n");
}
else
{
fprintf(stderr,"new rawhid device found\n");
}
*/
}
示例6: yyySetup
int yyySetup(yInterfaceSt *iface,char *errmsg)
{
char str[32];
yyyInitPktQueue(iface);
yInitializeCriticalSection(&iface->yyyCS);
if(iface->devref==NULL){
return YERR(YAPI_DEVICE_NOT_FOUND);
}
IOReturn ret = IOHIDDeviceOpen(iface->devref, kIOHIDOptionsTypeNone);
if (ret != kIOReturnSuccess) {
YSPRINTF(str,32,"Unable to open device (0x%x)",ret);
return YERRMSG(YAPI_IO_ERROR,str);
}
/* Create the Run Loop Mode for this device. printing the reference seems to work. */
sprintf(str, "yocto_%p", iface->devref);
iface->run_loop_mode = CFStringCreateWithCString(NULL, str, kCFStringEncodingASCII);
/* Attach the device to a Run Loop */
IOHIDDeviceScheduleWithRunLoop(iface->devref, yContext->usb_run_loop, iface->run_loop_mode);
IOHIDDeviceRegisterInputReportCallback( iface->devref, // IOHIDDeviceRef for the HID device
(u8*) &iface->tmprxpkt, // pointer to the report data
USB_PKT_SIZE, // number of bytes in the report (CFIndex)
&Handle_IOHIDDeviceIOHIDReportCallback, // the callback routine
iface); // context passed to callback
return 0;
}
示例7: 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);
}
}
示例8: openusb
void openusb(usbdevice* kb){
// The driver sometimes isn't completely ready yet, so give it a short delay
sleep(1);
// Handle 3 is the control handle
kb->lastkeypress = -1;
kb->handle = kb->handles[3];
// Set up the device
int setup = setupusb(kb);
if(setup == -1){
closehandle(kb);
pthread_mutex_unlock(&kb->mutex);
pthread_mutex_destroy(&kb->mutex);
pthread_mutex_destroy(&kb->keymutex);
return;
} else if(setup){
// If the setup had a communication error, wait a bit and try again.
sleep(1);
resetusb(kb);
}
// Start handling HID reports for the Corsair input
IOHIDDeviceRegisterInputReportCallback(kb->handles[2], kb->intinput, MSG_SIZE, reportcallback, kb);
// Register for close notification
IOHIDDeviceRegisterRemovalCallback(kb->handle, usbremove, kb);
// Update connected
updateconnected();
notifyconnect(kb, 1);
int index = INDEX_OF(kb, keyboard);
printf("Device ready at %s%d\n", devpath, index);
pthread_mutex_unlock(&kb->mutex);
}
示例9: TeensyControls_usb_close
void TeensyControls_usb_close(void)
{
teensy_t *t;
int wait=0;
for (t = TeensyControls_first_teensy; t; t = t->next) {
if (t->online) {
printf("close USB device\n");
IOHIDDeviceRegisterInputReportCallback(t->usb.dev,
t->usb.inbuf, 64, NULL, NULL);
// TODO: how to terminate input thread?
// TODO: how to terminate output thread?
pthread_cond_signal(&t->output_event);
IOHIDDeviceClose(t->usb.dev, 0);
t->online = 0;
}
}
if (hmgr) {
printf("closing hid manager\n");
IOHIDManagerRegisterDeviceMatchingCallback(hmgr, NULL, NULL);
IOHIDManagerRegisterDeviceRemovalCallback(hmgr, NULL, NULL);
IOHIDManagerClose(hmgr, 0);
hmgr = NULL;
}
while (++wait < 20 && num_thread_alive() > 0) {
usleep(10000);
printf("wait #%d for thread exit\n", wait);
}
}
示例10: 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();
}
示例11: openusb
void openusb(usbdevice* kb, short vendor, short product){
kb->lastkeypress = KEY_NONE;
if(IS_RGB(vendor, product))
// Handle 3 is the control handle
kb->handle = kb->handles[3];
else
// Non RGB keyboards don't have one, so just use 0
kb->handle = kb->handles[0];
// Set up the device
int setup = setupusb(kb, vendor, product);
if(setup == -1 || (setup && usb_tryreset(kb))){
closehandle(kb);
pthread_mutex_unlock(&kb->mutex);
pthread_mutex_destroy(&kb->mutex);
pthread_mutex_destroy(&kb->keymutex);
return;
}
// Start handling HID reports for the input
IOHIDDeviceRegisterInputReportCallback(kb->handles[0], kb->urbinput, 8, reportcallback, kb);
if(IS_RGB(vendor, product))
IOHIDDeviceRegisterInputReportCallback(kb->handles[1], kb->urbinput + 8, 21, reportcallback, kb);
else
IOHIDDeviceRegisterInputReportCallback(kb->handles[1], kb->urbinput + 8, 4, reportcallback, kb);
if(IS_RGB(vendor, product))
IOHIDDeviceRegisterInputReportCallback(kb->handles[2], kb->kbinput, MSG_SIZE, reportcallback, kb);
else
IOHIDDeviceRegisterInputReportCallback(kb->handles[2], kb->urbinput + 8 + 4, 15, reportcallback, kb);
// Register for close notification
IOHIDDeviceRegisterRemovalCallback(kb->handle, usbremove, kb);
// Update connected
updateconnected();
notifyconnect(kb, 1);
int index = INDEX_OF(kb, keyboard);
printf("Device ready at %s%d\n", devpath, index);
pthread_mutex_unlock(&kb->mutex);
}
示例12: 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);
}
示例13: input_thread
static void input_thread(void *arg)
{
teensy_t *t = (teensy_t *)arg;
printf("input_thread begin\n");
IOHIDDeviceRegisterInputReportCallback(t->usb.dev,
t->usb.inbuf, 64, input_callback, t);
while (1) {
int r;
if (t->online == 0) break;
r = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, true);
}
t->input_thread_quit = 1;
printf("input_thread end\n");
}
示例14: IOHIDManagerRegisterDeviceMatchingCallback
/**
* @brief Called by the USB system
* @param dev The device that was attached
*/
void pjrc_rawhid::attach(IOHIDDeviceRef d)
{
// Store the device handle
dev = d;
if (IOHIDDeviceOpen(dev, kIOHIDOptionsTypeNone) != kIOReturnSuccess) return;
// Disconnect the attach callback since we don't want to automatically reconnect
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, NULL, NULL);
IOHIDDeviceScheduleWithRunLoop(dev, the_correct_runloop, kCFRunLoopDefaultMode);
IOHIDDeviceRegisterInputReportCallback(dev, buffer, sizeof(buffer), pjrc_rawhid::input_callback, this);
attach_count++;
device_open = true;
unplugged = false;
}
示例15: attach_callback
static void attach_callback(void *context, IOReturn r, void *hid_mgr, IOHIDDeviceRef dev)
{
struct hid_struct *h;
printf("attach callback\n");
if (IOHIDDeviceOpen(dev, kIOHIDOptionsTypeNone) != kIOReturnSuccess) return;
h = (hid_t *)malloc(sizeof(hid_t));
if (!h) return;
memset(h, 0, sizeof(hid_t));
IOHIDDeviceScheduleWithRunLoop(dev, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDDeviceRegisterInputReportCallback(dev, h->buffer, sizeof(h->buffer), input_callback, h);
h->ref = dev;
h->open = 1;
add_hid(h);
}