5 #if defined(VRPN_USE_HID) 7 #ifdef VRPN_USE_LOCAL_HIDAPI 8 #include "./submodules/hidapi/hidapi/hidapi.h" 35 "vrpn_HidInterface::vrpn_HidInterface(): NULL acceptor\n");
59 struct hid_device_info *devs = hid_enumerate(0, 0);
60 struct hid_device_info *loop = devs;
62 const wchar_t *serial;
64 while ((loop != NULL) && !found) {
66 device_info.
vendor = loop->vendor_id;
67 device_info.
product = loop->product_id;
80 serial = loop->serial_number;
83 #ifdef VRPN_HID_DEBUGGING 84 fprintf(stderr,
"vrpn_HidInterface::reconnect(): Found %ls %ls " 85 "(%04hx:%04hx) at path %s - will attempt to " 87 loop->manufacturer_string, loop->product_string,
_vendor,
94 fprintf(stderr,
"vrpn_HidInterface::reconnect(): Device not found\n");
95 hid_free_enumeration(devs);
101 _device = hid_open_path(path);
102 if (_device == NULL) {
104 "vrpn_HidInterface::reconnect(): Could not open device %s\n",
107 fprintf(stderr,
" (Did you remember to run as root?)\n");
109 hid_free_enumeration(devs);
118 hid_free_enumeration(devs);
123 if (hid_set_nonblocking(_device, 1) != 0) {
124 fprintf(stderr,
"vrpn_HidInterface::reconnect(): Could not set device " 129 #ifdef VRPN_HID_DEBUGGING 131 "vrpn_HidInterface::reconnect(): Device successfully opened.\n");
149 vrpn_uint8 inbuf[512];
155 ret = hid_read(_device, inbuf,
sizeof(inbuf));
157 fprintf(stderr,
"vrpn_HidInterface::update(): Read error\n");
158 #if !defined(_WIN32) && !defined(__APPLE__) 159 fprintf(stderr,
" (On one version of Red Hat Linux, this was from " 160 "not having libusb-devel installed when " 161 "configuring in CMake.)\n");
163 const wchar_t *errmsg = hid_error(_device);
167 "vrpn_HidInterface::update(): error message: %ls\n",
177 static_cast<vrpn_uint8 *
>(
static_cast<void *
>(inbuf));
190 fprintf(stderr,
"vrpn_HidInterface::send_data(): Interface not " 191 "currently working\n");
195 if ((ret = hid_write(_device, const_cast<vrpn_uint8 *>(buffer), bytes)) !=
197 fprintf(stderr,
"vrpn_HidInterface::send_data(): hid_interrupt_write() " 198 "failed with code %d\n",
204 const vrpn_uint8 *buffer)
207 fprintf(stderr,
"vrpn_HidInterface::send_feature_report(): Interface " 208 "not currently working\n");
212 int ret = hid_send_feature_report(_device, buffer, bytes);
214 fprintf(stderr,
"vrpn_HidInterface::send_feature_report(): failed to " 215 "send feature report\n");
216 const wchar_t *errmsg = hid_error(_device);
218 fprintf(stderr,
"vrpn_HidInterface::send_feature_report(): error " 232 fprintf(stderr,
"vrpn_HidInterface::get_feature_report(): Interface " 233 "not currently working\n");
237 int ret = hid_get_feature_report(_device, buffer, bytes);
239 fprintf(stderr,
"vrpn_HidInterface::get_feature_report(): failed to " 240 "get feature report\n");
241 const wchar_t *errmsg = hid_error(_device);
245 "vrpn_HidInterface::get_feature_report(): error message: %ls\n",
256 #endif // any interface
wchar_t * manufacturer_string
int get_feature_report(size_t bytes, vrpn_uint8 *buffer)
Call this to get a feature report from the device - first byte must be Report ID (or 0x0 for devices ...
int interface_number() const
Returns the USB interface number of connected device.
virtual void on_data_received(size_t bytes, vrpn_uint8 *buffer)=0
Derived class reimplements this callback.
vrpn_uint16 product() const
Returns USB product ID of connected device.
virtual bool reconnect()
Tries to reconnect to an acceptable device. Call this if you suspect a hotplug event has occurred...
void send_feature_report(size_t bytes, const vrpn_uint8 *buffer)
Call this to send a feature report to the device - first byte must be Report ID (or 0x0 for devices w...
vrpn_uint16 vendor() const
Returns USB vendor ID of connected device.
vrpn_HidAcceptor * _acceptor
This is the HidAcceptor we use when reconnecting.
virtual bool accept(const vrpn_HIDDEVINFO &device)=0
virtual void update()
Polls the device buffers and causes on_data_received callbacks if appropriate You NEED to call this f...
void send_data(size_t bytes, const vrpn_uint8 *buffer)
Call this to send data to the device.
virtual ~vrpn_HidInterface()
virtual bool connected() const
Returns true iff the last device I/O succeeded.
vrpn_HidInterface(vrpn_HidAcceptor *acceptor)