private void AddDevice(IDeviceHandle <IHMDDevice, IHMDInfo> handle) { _lock.EnterWriteLock(); try { var resources = new DeviceResources(_factory, handle); var key = resources.Key; _nativeResources.Add(key, resources); HMD hmd; if (!_devices.TryGetValue(key, out hmd)) { // There's no HMD for this device yet: We need to create one hmd = new HMD(handle.DeviceInfo, _lock); _devices.Add(key, hmd); } hmd.Resources = resources; var fn = DeviceAttached; if (fn != null) { fn(hmd); } } finally { _lock.ExitWriteLock(); } }
public HidDeviceCapabilities GetDeviceCapabilities(IDeviceHandle deviceHandle) { var safeHandle = (deviceHandle as DeviceHandle).SafeFileHandle; IntPtr preparsedData = new IntPtr(); HidD_GetPreparsedData(safeHandle, ref preparsedData); HIDP_CAPS caps = new HIDP_CAPS(); int result = HidP_GetCaps(preparsedData, ref caps); if (preparsedData != IntPtr.Zero) { HidD_FreePreparsedData(preparsedData); } HIDD_ATTRIBUTES attrib = new HIDD_ATTRIBUTES(); attrib.Size = Marshal.SizeOf(attrib); HidD_GetAttributes(safeHandle, ref attrib); return(new HidDeviceCapabilities { Usage = (ushort)caps.Usage, UsagePage = (ushort)caps.UsagePage, InputReportByteLength = (ushort)caps.InputReportByteLength, OutputReportByteLength = (ushort)caps.OutputReportByteLength, VersionNumber = (ushort)attrib.VersionNumber }); }
internal void DeviceChanged(IMessageDeviceStatus message) { if (message == null) { return; } if (message.Type == MessageType.DeviceAdded) { using (IDeviceHandle handle = message.DeviceHandle) { if (handle.DeviceType == DeviceType.HMD) { AddDevice((IDeviceHandle <IHMDDevice, IHMDInfo>)handle); } } } else if (message.Type == MessageType.DeviceRemoved) { using (IDeviceHandle handle = message.DeviceHandle) { if (handle.DeviceType == DeviceType.Sensor) { RemoveDevice((IDeviceHandle <ISensorDevice, ISensorInfo>)handle); } } } }
public DeviceResources(IFactory factory, IDeviceHandle <IHMDDevice, IHMDInfo> handle) { if (factory == null || handle == null) { throw new ArgumentNullException(); } Info = handle.DeviceInfo; Device = handle.CreateDevice(); Sensor = Device.Sensor; Fusion = factory.CreateSensorFusion(Sensor); if (Info == null) { throw new ArgumentNullException(); } if (Device == null) { throw new ArgumentNullException(); } if (Sensor == null) { throw new ArgumentNullException(); } Key = new DeviceKey(Sensor.Info); }
public byte[] GetInputReport(IDeviceHandle deviceHandle, int reportSize) { var safeHandle = (deviceHandle as DeviceHandle).SafeFileHandle; byte[] reportBuffer = new byte[reportSize]; if (HidD_GetInputReport(safeHandle, reportBuffer, reportSize)) { return(reportBuffer); } return(null); }
public void Open(HidDeviceAccess desiredAccess) { handle = manager.OpenDevice(devicePath, desiredAccess); if (handle.IsInvalid) { //Logger.Error("Cannot open device"); return; } AccessLevel = desiredAccess; capabilities = manager.GetDeviceCapabilities(handle); VersionNumber = capabilities.VersionNumber; stream = manager.GetDeviceStream(handle); }
public DeviceResources(IFactory factory, IDeviceHandle<IHMDDevice, IHMDInfo> handle) { if (factory == null || handle == null) throw new ArgumentNullException(); Info = handle.DeviceInfo; Device = handle.CreateDevice(); Sensor = Device.Sensor; Fusion = factory.CreateSensorFusion(Sensor); if (Info == null) throw new ArgumentNullException(); if (Device == null) throw new ArgumentNullException(); if (Sensor == null) throw new ArgumentNullException(); Key = new DeviceKey(Sensor.Info); }
private void RemoveDevice(IDeviceHandle <ISensorDevice, ISensorInfo> handle) { _lock.EnterWriteLock(); try { var key = new DeviceKey(handle.DeviceInfo); DeviceResources resources; if (!_nativeResources.TryGetValue(key, out resources)) { return; } RemoveDevice(resources); } finally { _lock.ExitWriteLock(); } }
public DeviceResources(IFactory factory, IDeviceHandle<IHMDDevice, IHMDInfo> handle) { if (factory == null || handle == null) throw new ArgumentNullException(); Info = handle.DeviceInfo; Device = handle.CreateDevice(); Sensor = Device.Sensor; Fusion = factory.CreateSensorFusion(Sensor); if (Info == null) throw new ArgumentNullException(); if (Device == null) throw new ArgumentNullException(); if (Sensor == null) System.Diagnostics.Trace.TraceWarning("Unable to create Sensor"); if (Sensor != null) Key = new DeviceKey(Sensor.Info); }
private void RemoveDevice(IDeviceHandle<ISensorDevice, ISensorInfo> handle) { _lock.EnterWriteLock(); try { var key = new DeviceKey(handle.DeviceInfo); DeviceResources resources; if (!_nativeResources.TryGetValue(key, out resources)) return; RemoveDevice(resources); } finally { _lock.ExitWriteLock(); } }
private void AddDevice(IDeviceHandle<IHMDDevice, IHMDInfo> handle) { _lock.EnterWriteLock(); try { var resources = new DeviceResources(_factory, handle); var key = resources.Key; _nativeResources.Add(key, resources); HMD hmd; if (!_devices.TryGetValue(key, out hmd)) { // There's no HMD for this device yet: We need to create one hmd = new HMD(handle.DeviceInfo, _lock); _devices.Add(key, hmd); } hmd.Resources = resources; var fn = DeviceAttached; if (fn != null) { fn(hmd); } } finally { _lock.ExitWriteLock(); } }
public Stream GetDeviceStream(IDeviceHandle deviceHandle) { var safeHandle = (deviceHandle as DeviceHandle).SafeFileHandle; return(new FileStream(safeHandle, FileAccess.ReadWrite)); }