Device Info moves where it belongs into our device class.
1.1 --- a/HidDevice.cs Sat Feb 14 23:23:41 2015 +0100
1.2 +++ b/HidDevice.cs Sat Feb 14 23:41:12 2015 +0100
1.3 @@ -4,6 +4,7 @@
1.4 using System.Diagnostics;
1.5 using System.Text;
1.6 using Microsoft.Win32.SafeHandles;
1.7 +using Win32;
1.8
1.9 namespace Hid
1.10 {
1.11 @@ -19,6 +20,8 @@
1.12 public ushort ProductId { get; private set; }
1.13 public ushort Version { get; private set; }
1.14 public IntPtr PreParsedData {get; private set;}
1.15 + public RID_DEVICE_INFO Info { get {return iInfo;} }
1.16 + private RID_DEVICE_INFO iInfo;
1.17
1.18 /// <summary>
1.19 /// Class constructor will fetch this object properties from HID sub system.
1.20 @@ -32,6 +35,17 @@
1.21
1.22 //Get our HID descriptor pre-parsed data
1.23 PreParsedData = Win32.Utils.RawInput.GetPreParsedData(hRawInputDevice);
1.24 + if (PreParsedData == IntPtr.Zero)
1.25 + {
1.26 + throw new Exception("HidDevice: GetPreParsedData failed!");
1.27 + }
1.28 +
1.29 + //Fetch device info
1.30 + iInfo = new RID_DEVICE_INFO();
1.31 + if (!Win32.Utils.RawInput.GetDeviceInfo(hRawInputDevice, ref iInfo))
1.32 + {
1.33 + throw new Exception("HidDevice: GetDeviceInfo failed!");
1.34 + }
1.35
1.36 //Open our device from the device name/path
1.37 SafeFileHandle handle=Win32.Function.CreateFile(Name,
1.38 @@ -43,6 +57,7 @@
1.39 IntPtr.Zero
1.40 );
1.41
1.42 + //TODO: should we throw instead?
1.43 if (handle.IsInvalid)
1.44 {
1.45 Debug.WriteLine("Failed to CreateFile from device name " + Marshal.GetLastWin32Error().ToString());
2.1 --- a/HidEvent.cs Sat Feb 14 23:23:41 2015 +0100
2.2 +++ b/HidEvent.cs Sat Feb 14 23:41:12 2015 +0100
2.3 @@ -109,13 +109,6 @@
2.4 return;
2.5 }
2.6
2.7 - //TODO: move this into our device class
2.8 - //Fetch device info
2.9 - RID_DEVICE_INFO deviceInfo = new RID_DEVICE_INFO();
2.10 - if (!Win32.Utils.RawInput.GetDeviceInfo(rawInput.header.hDevice, ref deviceInfo))
2.11 - {
2.12 - return;
2.13 - }
2.14
2.15 //Get various information about this HID device
2.16 Device = new Hid.HidDevice(rawInput.header.hDevice);
2.17 @@ -127,8 +120,8 @@
2.18 Debug.WriteLine("WM_INPUT source device is HID.");
2.19 //Get Usage Page and Usage
2.20 //Debug.WriteLine("Usage Page: 0x" + deviceInfo.hid.usUsagePage.ToString("X4") + " Usage ID: 0x" + deviceInfo.hid.usUsage.ToString("X4"));
2.21 - UsagePage = deviceInfo.hid.usUsagePage;
2.22 - UsageCollection = deviceInfo.hid.usUsage;
2.23 + UsagePage = Device.Info.hid.usUsagePage;
2.24 + UsageCollection = Device.Info.hid.usUsage;
2.25
2.26 if (!(rawInput.hid.dwSizeHid > 1 //Make sure our HID msg size more than 1. In fact the first ushort is irrelevant to us for now
2.27 && rawInput.hid.dwCount > 0)) //Check that we have at least one HID msg
2.28 @@ -209,12 +202,12 @@
2.29
2.30 Debug.WriteLine("WM_INPUT source device is Keyboard.");
2.31 // do keyboard handling...
2.32 - Debug.WriteLine("Type: " + deviceInfo.keyboard.dwType.ToString());
2.33 - Debug.WriteLine("SubType: " + deviceInfo.keyboard.dwSubType.ToString());
2.34 - Debug.WriteLine("Mode: " + deviceInfo.keyboard.dwKeyboardMode.ToString());
2.35 - Debug.WriteLine("Number of function keys: " + deviceInfo.keyboard.dwNumberOfFunctionKeys.ToString());
2.36 - Debug.WriteLine("Number of indicators: " + deviceInfo.keyboard.dwNumberOfIndicators.ToString());
2.37 - Debug.WriteLine("Number of keys total: " + deviceInfo.keyboard.dwNumberOfKeysTotal.ToString());
2.38 + Debug.WriteLine("Type: " + Device.Info.keyboard.dwType.ToString());
2.39 + Debug.WriteLine("SubType: " + Device.Info.keyboard.dwSubType.ToString());
2.40 + Debug.WriteLine("Mode: " + Device.Info.keyboard.dwKeyboardMode.ToString());
2.41 + Debug.WriteLine("Number of function keys: " + Device.Info.keyboard.dwNumberOfFunctionKeys.ToString());
2.42 + Debug.WriteLine("Number of indicators: " + Device.Info.keyboard.dwNumberOfIndicators.ToString());
2.43 + Debug.WriteLine("Number of keys total: " + Device.Info.keyboard.dwNumberOfKeysTotal.ToString());
2.44 }
2.45 }
2.46 finally