HidDevice: Adding friendly name property.
1.1 --- a/HidDevice.cs Sun Feb 15 20:28:46 2015 +0100
1.2 +++ b/HidDevice.cs Sun Feb 15 21:48:07 2015 +0100
1.3 @@ -14,7 +14,18 @@
1.4 /// </summary>
1.5 public class HidDevice: IDisposable
1.6 {
1.7 + /// <summary>
1.8 + /// Unique name of that HID device.
1.9 + /// Notably used as input to CreateFile.
1.10 + /// </summary>
1.11 public string Name { get; private set; }
1.12 +
1.13 + /// <summary>
1.14 + /// Friendly name that people should be able to read.
1.15 + /// </summary>
1.16 + public string FriendlyName { get; private set; }
1.17 +
1.18 + //
1.19 public string Manufacturer { get; private set; }
1.20 public string Product { get; private set; }
1.21 public ushort VendorId { get; private set; }
1.22 @@ -127,6 +138,8 @@
1.23
1.24 handle.Close();
1.25
1.26 + SetFriendlyName();
1.27 +
1.28 //Get our HID descriptor pre-parsed data
1.29 PreParsedData = Win32.RawInput.GetPreParsedData(hRawInputDevice);
1.30
1.31 @@ -169,6 +182,68 @@
1.32 }
1.33
1.34
1.35 +
1.36 +
1.37 + }
1.38 +
1.39 + /// <summary>
1.40 + ///
1.41 + /// </summary>
1.42 + private void SetFriendlyName()
1.43 + {
1.44 + //Work out proper suffix for our device root node.
1.45 + //That allows users to see in a glance what kind of device this is.
1.46 + string suffix = "";
1.47 + Type usageCollectionType = null;
1.48 + if (Info.dwType == RawInputDeviceType.RIM_TYPEHID)
1.49 + {
1.50 + //Process usage page
1.51 + if (Enum.IsDefined(typeof(Hid.UsagePage), Info.hid.usUsagePage))
1.52 + {
1.53 + //We know this usage page, add its name
1.54 + Hid.UsagePage usagePage = (Hid.UsagePage)Info.hid.usUsagePage;
1.55 + suffix += " ( " + usagePage.ToString() + ", ";
1.56 + usageCollectionType = Hid.Utils.UsageCollectionType(usagePage);
1.57 + }
1.58 + else
1.59 + {
1.60 + //We don't know this usage page, add its value
1.61 + suffix += " ( 0x" + Info.hid.usUsagePage.ToString("X4") + ", ";
1.62 + }
1.63 +
1.64 + //Process usage collection
1.65 + //We don't know this usage page, add its value
1.66 + if (usageCollectionType == null || !Enum.IsDefined(usageCollectionType, Info.hid.usUsage))
1.67 + {
1.68 + //Show Hexa
1.69 + suffix += "0x" + Info.hid.usUsage.ToString("X4") + " )";
1.70 + }
1.71 + else
1.72 + {
1.73 + //We know this usage page, add its name
1.74 + suffix += Enum.GetName(usageCollectionType, Info.hid.usUsage) + " )";
1.75 + }
1.76 + }
1.77 + else if (Info.dwType == RawInputDeviceType.RIM_TYPEKEYBOARD)
1.78 + {
1.79 + suffix = " - Keyboard";
1.80 + }
1.81 + else if (Info.dwType == RawInputDeviceType.RIM_TYPEMOUSE)
1.82 + {
1.83 + suffix = " - Mouse";
1.84 + }
1.85 +
1.86 + if (Product != null && Product.Length > 1)
1.87 + {
1.88 + //Add the devices with a proper name at the top
1.89 + FriendlyName = Product + suffix;
1.90 + }
1.91 + else
1.92 + {
1.93 + //Add other once at the bottom
1.94 + FriendlyName = "0x" + ProductId.ToString("X4") + suffix;
1.95 + }
1.96 +
1.97 }
1.98
1.99 /// <summary>
2.1 --- a/HidEvent.cs Sun Feb 15 20:28:46 2015 +0100
2.2 +++ b/HidEvent.cs Sun Feb 15 21:48:07 2015 +0100
2.3 @@ -222,7 +222,7 @@
2.4 if (IsButtonDown)
2.5 {
2.6 //TODO: Make this optional
2.7 - StartRepeatTimer(iRepeatDelay);
2.8 + //StartRepeatTimer(iRepeatDelay);
2.9 }
2.10
2.11 IsValid = true;
3.1 --- a/RawInput.cs Sun Feb 15 20:28:46 2015 +0100
3.2 +++ b/RawInput.cs Sun Feb 15 21:48:07 2015 +0100
3.3 @@ -180,58 +180,16 @@
3.4 {
3.5 Hid.HidDevice hidDevice=new Hid.HidDevice(device.hDevice);
3.6
3.7 - //Work out proper suffix for our device root node.
3.8 - //That allows users to see in a glance what kind of device this is.
3.9 - string suffix = "";
3.10 - Type usageCollectionType=null;
3.11 - if (hidDevice.Info.dwType == RawInputDeviceType.RIM_TYPEHID)
3.12 - {
3.13 - //Process usage page
3.14 - if (Enum.IsDefined(typeof(Hid.UsagePage), hidDevice.Info.hid.usUsagePage))
3.15 - {
3.16 - //We know this usage page, add its name
3.17 - Hid.UsagePage usagePage = (Hid.UsagePage)hidDevice.Info.hid.usUsagePage;
3.18 - suffix += " ( " + usagePage.ToString() + ", ";
3.19 - usageCollectionType = Hid.Utils.UsageCollectionType(usagePage);
3.20 - }
3.21 - else
3.22 - {
3.23 - //We don't know this usage page, add its value
3.24 - suffix += " ( 0x" + hidDevice.Info.hid.usUsagePage.ToString("X4") + ", ";
3.25 - }
3.26 -
3.27 - //Process usage collection
3.28 - //We don't know this usage page, add its value
3.29 - if (usageCollectionType == null || !Enum.IsDefined(usageCollectionType, hidDevice.Info.hid.usUsage))
3.30 - {
3.31 - //Show Hexa
3.32 - suffix += "0x" + hidDevice.Info.hid.usUsage.ToString("X4") + " )";
3.33 - }
3.34 - else
3.35 - {
3.36 - //We know this usage page, add its name
3.37 - suffix += Enum.GetName(usageCollectionType, hidDevice.Info.hid.usUsage) + " )";
3.38 - }
3.39 - }
3.40 - else if (hidDevice.Info.dwType == RawInputDeviceType.RIM_TYPEKEYBOARD)
3.41 - {
3.42 - suffix = " - Keyboard";
3.43 - }
3.44 - else if (hidDevice.Info.dwType == RawInputDeviceType.RIM_TYPEMOUSE)
3.45 - {
3.46 - suffix = " - Mouse";
3.47 - }
3.48 -
3.49 TreeNode node = null;
3.50 if (hidDevice.Product != null && hidDevice.Product.Length > 1)
3.51 {
3.52 //Add the devices with a proper name at the top
3.53 - node = aTreeView.Nodes.Insert(0, hidDevice.Name, hidDevice.Product + suffix);
3.54 + node = aTreeView.Nodes.Insert(0, hidDevice.Name, hidDevice.FriendlyName);
3.55 }
3.56 else
3.57 {
3.58 //Add other once at the bottom
3.59 - node = aTreeView.Nodes.Add(hidDevice.Name, "0x" + hidDevice.ProductId.ToString("X4") + suffix);
3.60 + node = aTreeView.Nodes.Add(hidDevice.Name, "0x" + hidDevice.FriendlyName);
3.61 }
3.62
3.63 node.Nodes.Add("Manufacturer: " + hidDevice.Manufacturer);