Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InputDevice"/> class with the specified <see cref="DeviceDescriptor"/> and parent <see cref="DeviceManager"/>
        /// </summary>
        /// <param name="descriptor">Describes the HID compliant device to open a connection to</param>
        /// <param name="manager">The parent <see cref="DeviceManager"/> of this <see cref="InputDevice"/></param>
        public InputDevice(DeviceDescriptor descriptor, DeviceManager manager)
        {
            this.descriptor = descriptor;
            this.manager    = manager;

            Open();

            // If the device succeeded in opening, get the attributes and capabilities
            if (open)
            {
                Connected = true;

                WindowsNative.HIDD_ATTRIBUTES attr = new WindowsNative.HIDD_ATTRIBUTES();
                attr.Size = Marshal.SizeOf(attr);
                WindowsNative.HidD_GetAttributes(hid, ref attr);

                capabilities = default(WindowsNative.HIDP_CAPS);
                IntPtr ptr = default(IntPtr);

                // This shouldn't fail, but no big deal if it does
                // The device will just end up getting garbage collected if it has invalid vid/pid
                if (WindowsNative.HidD_GetPreparsedData(hid, ref ptr))
                {
                    WindowsNative.HidP_GetCaps(ptr, ref capabilities);
                    WindowsNative.HidD_FreePreparsedData(ptr);
                }

                Close();

                this.descriptor.SetIDSFromAttributes(attr);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Populates <see cref="VendorID"/> and <see cref="ProductID"/> from a given <see cref="WindowsNative.HIDD_ATTRIBUTES"/>
 /// </summary>
 /// <param name="attr">The struct containing the product and vendor IDs to set</param>
 public void SetIDSFromAttributes(WindowsNative.HIDD_ATTRIBUTES attr)
 {
     VendorID  = attr.VendorID;
     ProductID = attr.ProductID;
 }