# HG changeset patch # User StephaneLenclud # Date 1424033287 -3600 # Node ID 4b8b058de2152866d5fc6a178593726ee84b63f8 # Parent bc92e26482203a59e01d3ca62a5023295a9d55dd HidDevice: Adding friendly name property. diff -r bc92e2648220 -r 4b8b058de215 HidDevice.cs --- a/HidDevice.cs Sun Feb 15 20:28:46 2015 +0100 +++ b/HidDevice.cs Sun Feb 15 21:48:07 2015 +0100 @@ -14,7 +14,18 @@ /// public class HidDevice: IDisposable { + /// + /// Unique name of that HID device. + /// Notably used as input to CreateFile. + /// public string Name { get; private set; } + + /// + /// Friendly name that people should be able to read. + /// + public string FriendlyName { get; private set; } + + // public string Manufacturer { get; private set; } public string Product { get; private set; } public ushort VendorId { get; private set; } @@ -127,6 +138,8 @@ handle.Close(); + SetFriendlyName(); + //Get our HID descriptor pre-parsed data PreParsedData = Win32.RawInput.GetPreParsedData(hRawInputDevice); @@ -169,6 +182,68 @@ } + + + } + + /// + /// + /// + private void SetFriendlyName() + { + //Work out proper suffix for our device root node. + //That allows users to see in a glance what kind of device this is. + string suffix = ""; + Type usageCollectionType = null; + if (Info.dwType == RawInputDeviceType.RIM_TYPEHID) + { + //Process usage page + if (Enum.IsDefined(typeof(Hid.UsagePage), Info.hid.usUsagePage)) + { + //We know this usage page, add its name + Hid.UsagePage usagePage = (Hid.UsagePage)Info.hid.usUsagePage; + suffix += " ( " + usagePage.ToString() + ", "; + usageCollectionType = Hid.Utils.UsageCollectionType(usagePage); + } + else + { + //We don't know this usage page, add its value + suffix += " ( 0x" + Info.hid.usUsagePage.ToString("X4") + ", "; + } + + //Process usage collection + //We don't know this usage page, add its value + if (usageCollectionType == null || !Enum.IsDefined(usageCollectionType, Info.hid.usUsage)) + { + //Show Hexa + suffix += "0x" + Info.hid.usUsage.ToString("X4") + " )"; + } + else + { + //We know this usage page, add its name + suffix += Enum.GetName(usageCollectionType, Info.hid.usUsage) + " )"; + } + } + else if (Info.dwType == RawInputDeviceType.RIM_TYPEKEYBOARD) + { + suffix = " - Keyboard"; + } + else if (Info.dwType == RawInputDeviceType.RIM_TYPEMOUSE) + { + suffix = " - Mouse"; + } + + if (Product != null && Product.Length > 1) + { + //Add the devices with a proper name at the top + FriendlyName = Product + suffix; + } + else + { + //Add other once at the bottom + FriendlyName = "0x" + ProductId.ToString("X4") + suffix; + } + } /// diff -r bc92e2648220 -r 4b8b058de215 HidEvent.cs --- a/HidEvent.cs Sun Feb 15 20:28:46 2015 +0100 +++ b/HidEvent.cs Sun Feb 15 21:48:07 2015 +0100 @@ -222,7 +222,7 @@ if (IsButtonDown) { //TODO: Make this optional - StartRepeatTimer(iRepeatDelay); + //StartRepeatTimer(iRepeatDelay); } IsValid = true; diff -r bc92e2648220 -r 4b8b058de215 RawInput.cs --- a/RawInput.cs Sun Feb 15 20:28:46 2015 +0100 +++ b/RawInput.cs Sun Feb 15 21:48:07 2015 +0100 @@ -180,58 +180,16 @@ { Hid.HidDevice hidDevice=new Hid.HidDevice(device.hDevice); - //Work out proper suffix for our device root node. - //That allows users to see in a glance what kind of device this is. - string suffix = ""; - Type usageCollectionType=null; - if (hidDevice.Info.dwType == RawInputDeviceType.RIM_TYPEHID) - { - //Process usage page - if (Enum.IsDefined(typeof(Hid.UsagePage), hidDevice.Info.hid.usUsagePage)) - { - //We know this usage page, add its name - Hid.UsagePage usagePage = (Hid.UsagePage)hidDevice.Info.hid.usUsagePage; - suffix += " ( " + usagePage.ToString() + ", "; - usageCollectionType = Hid.Utils.UsageCollectionType(usagePage); - } - else - { - //We don't know this usage page, add its value - suffix += " ( 0x" + hidDevice.Info.hid.usUsagePage.ToString("X4") + ", "; - } - - //Process usage collection - //We don't know this usage page, add its value - if (usageCollectionType == null || !Enum.IsDefined(usageCollectionType, hidDevice.Info.hid.usUsage)) - { - //Show Hexa - suffix += "0x" + hidDevice.Info.hid.usUsage.ToString("X4") + " )"; - } - else - { - //We know this usage page, add its name - suffix += Enum.GetName(usageCollectionType, hidDevice.Info.hid.usUsage) + " )"; - } - } - else if (hidDevice.Info.dwType == RawInputDeviceType.RIM_TYPEKEYBOARD) - { - suffix = " - Keyboard"; - } - else if (hidDevice.Info.dwType == RawInputDeviceType.RIM_TYPEMOUSE) - { - suffix = " - Mouse"; - } - TreeNode node = null; if (hidDevice.Product != null && hidDevice.Product.Length > 1) { //Add the devices with a proper name at the top - node = aTreeView.Nodes.Insert(0, hidDevice.Name, hidDevice.Product + suffix); + node = aTreeView.Nodes.Insert(0, hidDevice.Name, hidDevice.FriendlyName); } else { //Add other once at the bottom - node = aTreeView.Nodes.Add(hidDevice.Name, "0x" + hidDevice.ProductId.ToString("X4") + suffix); + node = aTreeView.Nodes.Add(hidDevice.Name, "0x" + hidDevice.FriendlyName); } node.Nodes.Add("Manufacturer: " + hidDevice.Manufacturer);