HidDevice now supports capabilities and button capabilities.
authorStephaneLenclud
Sun, 15 Feb 2015 11:53:36 +0100
changeset 56cace0afae0fa
parent 55 08c70af8af84
child 57 878e0b271c11
HidDevice now supports capabilities and button capabilities.
HidDevice.cs
Win32Hid.cs
     1.1 --- a/HidDevice.cs	Sun Feb 15 10:50:09 2015 +0100
     1.2 +++ b/HidDevice.cs	Sun Feb 15 11:53:36 2015 +0100
     1.3 @@ -19,9 +19,18 @@
     1.4          public ushort VendorId { get; private set; }
     1.5          public ushort ProductId { get; private set; }
     1.6          public ushort Version { get; private set; }
     1.7 +        //Pre-parsed HID descriptor
     1.8          public IntPtr PreParsedData {get; private set;}
     1.9 +        //Info
    1.10          public RID_DEVICE_INFO Info { get {return iInfo;} }
    1.11          private RID_DEVICE_INFO iInfo;
    1.12 +        //Capabilities
    1.13 +        public HIDP_CAPS Capabilities { get { return iCapabilities; } }
    1.14 +        private HIDP_CAPS iCapabilities;
    1.15 +        //Input Button Capabilities
    1.16 +        public HIDP_BUTTON_CAPS[] InputButtonCapabilities { get { return iInputButtonCapabilities; } }
    1.17 +        private HIDP_BUTTON_CAPS[] iInputButtonCapabilities;
    1.18 +        
    1.19  
    1.20          /// <summary>
    1.21          /// Class constructor will fetch this object properties from HID sub system.
    1.22 @@ -115,6 +124,24 @@
    1.23              }
    1.24  
    1.25              handle.Close();
    1.26 +
    1.27 +            //Get capabilities
    1.28 +            HidStatus status = Win32.Function.HidP_GetCaps(PreParsedData, ref iCapabilities);
    1.29 +            if (status != HidStatus.HIDP_STATUS_SUCCESS)
    1.30 +            {
    1.31 +                throw new Exception("HidDevice: HidP_GetCaps failed: " + status.ToString());
    1.32 +            }
    1.33 +
    1.34 +            //Get input button caps
    1.35 +            iInputButtonCapabilities = new HIDP_BUTTON_CAPS[Capabilities.NumberInputButtonCaps];
    1.36 +            ushort buttonCapabilitiesLength = Capabilities.NumberInputButtonCaps;
    1.37 +            status = Win32.Function.HidP_GetButtonCaps(HIDP_REPORT_TYPE.HidP_Input, iInputButtonCapabilities, ref buttonCapabilitiesLength, PreParsedData);
    1.38 +            if (status != HidStatus.HIDP_STATUS_SUCCESS || buttonCapabilitiesLength != Capabilities.NumberInputButtonCaps)
    1.39 +            {
    1.40 +                throw new Exception("HidDevice: HidP_GetButtonCaps failed: " + status.ToString());
    1.41 +            }
    1.42 +            
    1.43 +
    1.44          }
    1.45  
    1.46          /// <summary>
     2.1 --- a/Win32Hid.cs	Sun Feb 15 10:50:09 2015 +0100
     2.2 +++ b/Win32Hid.cs	Sun Feb 15 11:53:36 2015 +0100
     2.3 @@ -24,23 +24,23 @@
     2.4          ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
     2.5          ///Capabilities: PHIDP_CAPS->_HIDP_CAPS*
     2.6          [DllImportAttribute("hid.dll", EntryPoint = "HidP_GetCaps", CallingConvention = CallingConvention.StdCall)]
     2.7 -        public static extern int HidP_GetCaps(System.IntPtr PreparsedData, ref HIDP_CAPS Capabilities);
     2.8 +        public static extern HidStatus HidP_GetCaps(System.IntPtr PreparsedData, ref HIDP_CAPS Capabilities);
     2.9  
    2.10          /// Return Type: NTSTATUS->LONG->int
    2.11          ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE
    2.12          ///ButtonCaps: PHIDP_BUTTON_CAPS->_HIDP_BUTTON_CAPS*
    2.13          ///ButtonCapsLength: PUSHORT->USHORT*
    2.14          ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
    2.15 -        [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "HidP_GetButtonCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
    2.16 -        public static extern int HidP_GetButtonCaps(HIDP_REPORT_TYPE ReportType, ref HIDP_BUTTON_CAPS ButtonCaps, ref ushort ButtonCapsLength, System.IntPtr PreparsedData);
    2.17 +        [System.Runtime.InteropServices.DllImportAttribute("hid.dll", EntryPoint = "HidP_GetButtonCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
    2.18 +        public static extern HidStatus HidP_GetButtonCaps(HIDP_REPORT_TYPE ReportType, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] HIDP_BUTTON_CAPS[] ButtonCaps, ref ushort ButtonCapsLength, System.IntPtr PreparsedData);
    2.19  
    2.20          /// Return Type: NTSTATUS->LONG->int
    2.21          ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE
    2.22          ///ValueCaps: PHIDP_VALUE_CAPS->_HIDP_VALUE_CAPS*
    2.23          ///ValueCapsLength: PUSHORT->USHORT*
    2.24          ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
    2.25 -        [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "HidP_GetValueCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
    2.26 -        public static extern int HidP_GetValueCaps(HIDP_REPORT_TYPE ReportType, ref HIDP_VALUE_CAPS ValueCaps, ref ushort ValueCapsLength, System.IntPtr PreparsedData);
    2.27 +        [System.Runtime.InteropServices.DllImportAttribute("hid.dll", EntryPoint = "HidP_GetValueCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
    2.28 +        public static extern HidStatus HidP_GetValueCaps(HIDP_REPORT_TYPE ReportType, ref HIDP_VALUE_CAPS[] ValueCaps, ref ushort ValueCapsLength, System.IntPtr PreparsedData);
    2.29  
    2.30      }
    2.31