int libusb_release_interface(libusb_device_handle* dev, int interface_number) { usb_dev_handle* device_handle (translate(dev)); usb_release_interface(device_handle, interface_number); // LIBUSB_ERROR_NOT_FOUND if the interface was not claimed // LIBUSB_ERROR_NO_DEVICE if the device has been disconnected // another LIBUSB_ERROR code on other failure // 0 on success return(0); }
bool handle_input_event(input_event eventid, void* eventdata) override { // Only handle raw input data if (!input_enabled() || eventid != INPUT_EVENT_RAWINPUT) return false; HRAWINPUT rawinputdevice = *static_cast<HRAWINPUT*>(eventdata); BYTE small_buffer[4096]; std::unique_ptr<BYTE[]> larger_buffer; LPBYTE data = small_buffer; UINT size; // ignore if not enabled if (!input_enabled()) return false; // determine the size of databuffer we need if ((*get_rawinput_data)(rawinputdevice, RID_INPUT, nullptr, &size, sizeof(RAWINPUTHEADER)) != 0) return false; // if necessary, allocate a temporary buffer and fetch the data if (size > sizeof(small_buffer)) { larger_buffer = std::make_unique<BYTE[]>(size); data = larger_buffer.get(); if (data == nullptr) return false; } // fetch the data and process the appropriate message types bool result = (*get_rawinput_data)(static_cast<HRAWINPUT>(rawinputdevice), RID_INPUT, data, &size, sizeof(RAWINPUTHEADER)); if (result) { std::lock_guard<std::mutex> scope_lock(m_module_lock); RAWINPUT *input = reinterpret_cast<RAWINPUT*>(data); // find the device in the list and update auto target_device = std::find_if(devicelist()->begin(), devicelist()->end(), [input](auto &device) { auto devinfo = dynamic_cast<rawinput_device*>(device.get()); return devinfo != nullptr && input->header.hDevice == devinfo->device_handle(); }); if (target_device != devicelist()->end()) { static_cast<rawinput_device*>((*target_device).get())->queue_events(input, 1); return true; } } return false; }
int libusb_control_transfer(libusb_device_handle* dev_handle, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char* data, uint16_t wLength, unsigned int timeout) { usb_dev_handle* device_handle (translate(dev_handle)); // in libusb-1.0 a timeout of zero it means 'wait indefinitely'; in libusb-0.1, a timeout of zero means 'return immediatelly'! timeout = (0 == timeout) ? 60000 : timeout; // wait 60000ms (60s = 1min) if the transfer is supposed to wait indefinitely... int bytes_transferred = usb_control_msg(device_handle, bmRequestType, bRequest, wValue, wIndex, (char*)data, wLength, timeout); // on success, the number of bytes actually transferred // LIBUSB_ERROR_TIMEOUT if the transfer timed out // LIBUSB_ERROR_PIPE if the control request was not supported by the device // LIBUSB_ERROR_NO_DEVICE if the device has been disconnected // another LIBUSB_ERROR code on other failures return(bytes_transferred); }
int libusb_claim_interface(libusb_device_handle* dev, int interface_number) { usb_dev_handle* device_handle (translate(dev)); if (0 == usb_claim_interface(device_handle, interface_number)) { int ok2 = usb_set_configuration(device_handle, 1); } // LIBUSB_ERROR_NOT_FOUND if the requested interface does not exist // LIBUSB_ERROR_BUSY if another program or driver has claimed the interface // LIBUSB_ERROR_NO_DEVICE if the device has been disconnected // a LIBUSB_ERROR code on other failure // 0 on success return(0); }
int libusb_open(libusb_device* dev, libusb_device_handle** handle) { struct usb_device* device (translate(dev)); usb_dev_handle* device_handle (usb_open(device)); *handle = translate(device_handle); if (NULL == device_handle) { // LIBUSB_ERROR_NO_MEM on memory allocation failure // LIBUSB_ERROR_ACCESS if the user has insufficient permissions // LIBUSB_ERROR_NO_DEVICE if the device has been disconnected // another LIBUSB_ERROR code on other failure return(LIBUSB_ERROR_OTHER); } //0 on success return(0); }
static void rt_main(struct rt_t *rt) { int r; size_t n; if (raise_priority() == -1) return; while (!rt->finished) { r = poll(rt->pt, rt->npt, -1); if (r == -1) { if (errno == EINTR) { continue; } else { perror("poll"); return; } } for (n = 0; n < rt->ndv; n++) device_handle(rt->dv[n]); } }
void libusb_close(libusb_device_handle* dev_handle) { usb_dev_handle* device_handle (translate(dev_handle)); usb_close(device_handle); }