28 #include <sys/ioctl.h>
31 #include <linux/hidraw.h>
34 namespace OVR {
namespace Linux {
68 udev_monitor_filter_add_match_subsystem_devtype(
HIDMonitor,
"hidraw",
NULL);
70 int err = udev_monitor_enable_receiving(
HIDMonitor);
131 LogText(
"OVR::Linux::HIDDeviceManager - shutting down.\n");
157 const char* propertyName,
160 const char* str = udev_device_get_sysattr_value(device, propertyName);
163 *pResult = strtol(str,
NULL, 16);
197 const char* propertyName,
201 const char* str = udev_device_get_sysattr_value(device, propertyName);
223 udev_enumerate* devices = udev_enumerate_new(
UdevInstance);
224 udev_enumerate_add_match_subsystem(devices,
"hidraw");
225 udev_enumerate_scan_devices(devices);
227 udev_list_entry* entry = udev_enumerate_get_list_entry(devices);
230 while (entry !=
NULL)
233 const char* sysfs_path = udev_list_entry_get_name(entry);
235 hid = udev_device_new_from_syspath(
UdevInstance, sysfs_path);
236 const char* dev_path = udev_device_get_devnode(hid);
239 hid = udev_device_get_parent_with_subsystem_devtype(hid,
"usb",
"usb_device");
249 devDesc.
Path = dev_path;
256 if (existingDevice && existingDevice->pDevice)
258 existingDevice->Enumerated =
true;
262 int device_handle = open(dev_path, O_RDWR);
263 if (device_handle >= 0)
267 enumVisitor->
Visit(device, devDesc);
269 close(device_handle);
274 udev_device_unref(hid);
275 entry = udev_list_entry_get_next(entry);
280 udev_enumerate_unref(devices);
290 if (device->HIDInitialize(path))
330 udev_enumerate* devices = udev_enumerate_new(
UdevInstance);
331 udev_enumerate_add_match_subsystem(devices,
"hidraw");
332 udev_enumerate_scan_devices(devices);
334 udev_list_entry* entry = udev_enumerate_get_list_entry(devices);
336 bool success =
false;
338 while (entry !=
NULL)
341 const char* sysfs_path = udev_list_entry_get_name(entry);
343 hid = udev_device_new_from_syspath(
UdevInstance, sysfs_path);
344 const char* path = udev_device_get_devnode(hid);
350 hid = udev_device_get_parent_with_subsystem_devtype(hid,
"usb",
"usb_device");
353 desc->
Path = dev_path;
359 udev_device_unref(hid);
360 entry = udev_list_entry_get_next(entry);
364 udev_enumerate_unref(devices);
376 udev_device* hid = udev_monitor_receive_device(
HIDMonitor);
379 const char* dev_path = udev_device_get_devnode(hid);
380 const char* action = udev_device_get_action(hid);
383 device_info.
Path = dev_path;
394 hid = udev_device_get_parent_with_subsystem_devtype(hid,
"usb",
"usb_device");
412 bool deviceFound =
false;
429 udev_device_unref(hid);
437 : InMinimalMode(false), HIDManager(manager)
446 : InMinimalMode(true), HIDManager(manager),
DeviceHandle(device_handle)
462 const char* hid_path = path.
ToCStr();
465 LogText(
"OVR::Linux::HIDDevice - Failed to open HIDDevice: %s", hid_path);
472 LogText(
"OVR::Linux::HIDDevice - Opened '%s'\n"
473 " Manufacturer:'%s' Product:'%s' Serial#:'%s'\n",
488 hidraw_report_descriptor rpt_desc;
489 memset(&rpt_desc, 0,
sizeof(rpt_desc));
500 rpt_desc.size = desc_size;
548 OVR_ASSERT_LOG(
false, (
"Input report buffer length is bigger than read buffer."));
568 OVR_DEBUG_LOG((
"Failed 'CreateHIDFile' while opening device, error = 0x%X.", errno));
586 OVR_ASSERT_LOG(
false, (
"Failed to initialize polling for HIDDevice."));
640 UByte reportID = data[0];
699 const char* device_path = device_info->
Path.
ToCStr();
714 LogError(
"OVR::Linux::HIDDevice - Failed to reopen a device '%s' that was re-added.\n",
720 LogText(
"OVR::Linux::HIDDevice - Reopened device '%s'\n", device_path);
764 LogMessage(
Log_Debug,
"HIDDeviceManager::Create failed - OVR::System not initialized"); );
772 if (manager->Initialize())
798 LogMessage(
Log_Debug,
"HIDDeviceManager::Create failed - OVR::System not initialized"); );
804 if (!deviceManagerLinux)
809 if (!deviceManagerLinux->Initialize(
NULL))
814 deviceManager = deviceManagerLinux;
816 return deviceManagerLinux->GetHIDDeviceManager();
void LogText(const char *fmt,...) OVR_LOG_VAARG_ATTRIBUTE(1
virtual void OnInputReport(UByte *pData, UInt32 length)
bool getStringProperty(udev_device *device, const char *propertyName, OVR::String *pResult)
bool initVendorProductVersion(udev_device *device, HIDDeviceDesc *pDevDesc)
OVR_FORCE_INLINE void Clear()
#define OVR_ASSERT_LOG(c, args)
UByte ReadBuffer[ReadBufferSize]
void OnEvent(int i, int fd)
bool getIntProperty(udev_device *device, const char *key, int32_t *pResult)
static HIDDeviceManager * Create(Ptr< OVR::DeviceManager > &deviceManager)
virtual OVR::HIDDevice * Open(const String &path)
bool GetDescriptorFromPath(const char *dev_path, HIDDeviceDesc *desc)
static const UInt32 MAX_QUEUED_INPUT_REPORTS
OVR_FORCE_INLINE C * GetPtr() const
#define OVR_DEBUG_STATEMENT(s)
Array< HIDDevice * > NotificationDevices
virtual double OnTicks(double tickSeconds)
virtual bool MatchVendorProduct(UInt16 vendorId, UInt16 productId)
bool RemoveNotificationDevice(HIDDevice *device)
Ptr< DeviceManagerThread > pThread
virtual void Visit(HIDDevice &, const HIDDeviceDesc &)
const char * ToCStr() const
static HIDDeviceManager * CreateInternal(DeviceManager *manager)
UInt16 InputReportBufferLength
udev_monitor * HIDMonitor
Ptr< DeviceCreateDesc > FindHIDDevice(const HIDDeviceDesc &, bool created)
void void LogError(const char *fmt,...) OVR_LOG_VAARG_ATTRIBUTE(1
bool openDevice(const char *dev_path)
bool OnDeviceNotification(MessageType messageType, HIDDeviceDesc *device_info, bool *error)
bool getFullDesc(udev_device *device, HIDDeviceDesc *desc)
virtual bool GetFeatureReport(UByte *data, UInt32 length)
static bool OVR_CDECL IsInitialized()
bool HIDInitialize(const String &path)
static Log * GetDefaultLog()
void OnEvent(int i, int fd)
DeviceManager * DevManager
UInt16 FeatureReportBufferLength
int OVR_CDECL OVR_strcmp(const char *dest, const char *src)
double OnTicks(double tickSeconds)
void closeDevice(bool wasUnplugged)
virtual void OnDeviceMessage(HIDDeviceMessageType messageType)
bool AddNotificationDevice(HIDDevice *device)
UInt16 OutputReportBufferLength
__BEGIN_NAMESPACE_STD void void __END_NAMESPACE_STD void __BEGIN_NAMESPACE_STD void * memset(void *__s, int __c, size_t __n) __THROW __nonnull((1))
HIDDeviceManager * HIDManager
void DetectHIDDevice(const HIDDeviceDesc &)
#define OVR_DEBUG_LOG(args)
virtual ~HIDDeviceManager()
static int OVR_STDCALL CompareNoCase(const char *a, const char *b)
virtual double OnTicks(double tickSeconds)
virtual bool Enumerate(HIDEnumerateVisitor *enumVisitor)
void closeDeviceOnIOError()
virtual bool Initialize()
virtual bool SetFeatureReport(UByte *data, UInt32 length)