Example #1
0
        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();
            }
        }
Example #2
0
        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
            });
        }
Example #3
0
        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);
                    }
                }
            }
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
		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);
		}
Example #8
0
        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();
            }
        }
Example #9
0
        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);
        }
Example #10
0
        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();
            }
        }
Example #11
0
        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();
            }
        }
Example #12
0
        public Stream GetDeviceStream(IDeviceHandle deviceHandle)
        {
            var safeHandle = (deviceHandle as DeviceHandle).SafeFileHandle;

            return(new FileStream(safeHandle, FileAccess.ReadWrite));
        }