HidDevice.cs
changeset 58 7ef0f9dc229c
parent 56 cace0afae0fa
child 60 687cace560d2
     1.1 --- a/HidDevice.cs	Sun Feb 15 12:10:40 2015 +0100
     1.2 +++ b/HidDevice.cs	Sun Feb 15 12:22:43 2015 +0100
     1.3 @@ -30,6 +30,11 @@
     1.4          //Input Button Capabilities
     1.5          public HIDP_BUTTON_CAPS[] InputButtonCapabilities { get { return iInputButtonCapabilities; } }
     1.6          private HIDP_BUTTON_CAPS[] iInputButtonCapabilities;
     1.7 +        //Input Value Capabilities
     1.8 +        public HIDP_VALUE_CAPS[] InputValueCapabilities { get { return iInputValueCapabilities; } }
     1.9 +        private HIDP_VALUE_CAPS[] iInputValueCapabilities;
    1.10 +
    1.11 +        
    1.12          
    1.13  
    1.14          /// <summary>
    1.15 @@ -67,6 +72,9 @@
    1.16          private void Construct(IntPtr hRawInputDevice)
    1.17          {
    1.18              PreParsedData = IntPtr.Zero;
    1.19 +            iInputButtonCapabilities = null;
    1.20 +            iInputValueCapabilities = null;
    1.21 +
    1.22              //Fetch various information defining the given HID device
    1.23              Name = Win32.Utils.RawInput.GetDeviceName(hRawInputDevice);
    1.24  
    1.25 @@ -132,15 +140,30 @@
    1.26                  throw new Exception("HidDevice: HidP_GetCaps failed: " + status.ToString());
    1.27              }
    1.28  
    1.29 -            //Get input button caps
    1.30 -            iInputButtonCapabilities = new HIDP_BUTTON_CAPS[Capabilities.NumberInputButtonCaps];
    1.31 -            ushort buttonCapabilitiesLength = Capabilities.NumberInputButtonCaps;
    1.32 -            status = Win32.Function.HidP_GetButtonCaps(HIDP_REPORT_TYPE.HidP_Input, iInputButtonCapabilities, ref buttonCapabilitiesLength, PreParsedData);
    1.33 -            if (status != HidStatus.HIDP_STATUS_SUCCESS || buttonCapabilitiesLength != Capabilities.NumberInputButtonCaps)
    1.34 +            //Get input button caps if needed
    1.35 +            if (Capabilities.NumberInputButtonCaps > 0)
    1.36              {
    1.37 -                throw new Exception("HidDevice: HidP_GetButtonCaps failed: " + status.ToString());
    1.38 +                iInputButtonCapabilities = new HIDP_BUTTON_CAPS[Capabilities.NumberInputButtonCaps];
    1.39 +                ushort buttonCapabilitiesLength = Capabilities.NumberInputButtonCaps;
    1.40 +                status = Win32.Function.HidP_GetButtonCaps(HIDP_REPORT_TYPE.HidP_Input, iInputButtonCapabilities, ref buttonCapabilitiesLength, PreParsedData);
    1.41 +                if (status != HidStatus.HIDP_STATUS_SUCCESS || buttonCapabilitiesLength != Capabilities.NumberInputButtonCaps)
    1.42 +                {
    1.43 +                    throw new Exception("HidDevice: HidP_GetButtonCaps failed: " + status.ToString());
    1.44 +                }
    1.45              }
    1.46 -            
    1.47 +
    1.48 +            //Get input value caps if needed
    1.49 +            if (Capabilities.NumberInputValueCaps > 0)
    1.50 +            {
    1.51 +                iInputValueCapabilities = new HIDP_VALUE_CAPS[Capabilities.NumberInputValueCaps];
    1.52 +                ushort valueCapabilitiesLength = Capabilities.NumberInputValueCaps;
    1.53 +                status = Win32.Function.HidP_GetValueCaps(HIDP_REPORT_TYPE.HidP_Input, iInputValueCapabilities, ref valueCapabilitiesLength, PreParsedData);
    1.54 +                if (status != HidStatus.HIDP_STATUS_SUCCESS || valueCapabilitiesLength != Capabilities.NumberInputValueCaps)
    1.55 +                {
    1.56 +                    throw new Exception("HidDevice: HidP_GetValueCaps failed: " + status.ToString());
    1.57 +                }
    1.58 +            }
    1.59 +
    1.60  
    1.61          }
    1.62