Device list now showing usage collection string.
authorStephaneLenclud
Sun, 15 Feb 2015 20:28:46 +0100
changeset 62bc92e2648220
parent 61 60bfe5083721
child 63 4b8b058de215
Device list now showing usage collection string.
HidUtils.cs
RawInput.cs
RemoteControlSample.csproj
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/HidUtils.cs	Sun Feb 15 20:28:46 2015 +0100
     1.3 @@ -0,0 +1,32 @@
     1.4 +using System;
     1.5 +using System.Collections.Generic;
     1.6 +using System.Text;
     1.7 +
     1.8 +namespace Hid
     1.9 +{
    1.10 +    static class Utils
    1.11 +    {
    1.12 +        /// <summary>
    1.13 +        /// Provide the type for the usage collection corresponding to the given usage page.
    1.14 +        /// </summary>
    1.15 +        /// <param name="aUsagePage"></param>
    1.16 +        /// <returns></returns>
    1.17 +        public static Type UsageCollectionType(UsagePage aUsagePage)
    1.18 +        {
    1.19 +            switch (aUsagePage)
    1.20 +            {
    1.21 +                case UsagePage.GenericDesktopControls:
    1.22 +                    return typeof(UsageCollectionGenericDesktop);
    1.23 +
    1.24 +                case UsagePage.Consumer:
    1.25 +                    return typeof(UsageCollectionConsumer);
    1.26 +
    1.27 +                case UsagePage.WindowsMediaCenterRemoteControl:
    1.28 +                    return typeof(UsageCollectionWindowsMediaCenter);
    1.29 +
    1.30 +                default:
    1.31 +                    return null;
    1.32 +            }
    1.33 +        }
    1.34 +    }
    1.35 +}
     2.1 --- a/RawInput.cs	Sun Feb 15 19:53:27 2015 +0100
     2.2 +++ b/RawInput.cs	Sun Feb 15 20:28:46 2015 +0100
     2.3 @@ -183,6 +183,7 @@
     2.4                  //Work out proper suffix for our device root node.
     2.5                  //That allows users to see in a glance what kind of device this is.
     2.6                  string suffix = "";
     2.7 +                Type usageCollectionType=null; 
     2.8                  if (hidDevice.Info.dwType == RawInputDeviceType.RIM_TYPEHID)
     2.9                  {
    2.10                      //Process usage page
    2.11 @@ -191,6 +192,7 @@
    2.12                          //We know this usage page, add its name
    2.13                          Hid.UsagePage usagePage = (Hid.UsagePage)hidDevice.Info.hid.usUsagePage;
    2.14                          suffix += " ( " + usagePage.ToString() + ", ";
    2.15 +                        usageCollectionType = Hid.Utils.UsageCollectionType(usagePage);
    2.16                      }
    2.17                      else
    2.18                      {
    2.19 @@ -198,9 +200,18 @@
    2.20                          suffix += " ( 0x" + hidDevice.Info.hid.usUsagePage.ToString("X4") + ", ";
    2.21                      }
    2.22  
    2.23 -                    //Process usage
    2.24 +                    //Process usage collection
    2.25                      //We don't know this usage page, add its value
    2.26 -                    suffix += "0x" + hidDevice.Info.hid.usUsage.ToString("X4") + " )";
    2.27 +                    if (usageCollectionType == null || !Enum.IsDefined(usageCollectionType, hidDevice.Info.hid.usUsage))
    2.28 +                    {
    2.29 +                        //Show Hexa
    2.30 +                        suffix += "0x" + hidDevice.Info.hid.usUsage.ToString("X4") + " )";
    2.31 +                    }
    2.32 +                    else
    2.33 +                    {
    2.34 +                        //We know this usage page, add its name
    2.35 +                        suffix += Enum.GetName(usageCollectionType, hidDevice.Info.hid.usUsage) + " )";                        
    2.36 +                    }
    2.37                  }
    2.38                  else if (hidDevice.Info.dwType == RawInputDeviceType.RIM_TYPEKEYBOARD)
    2.39                  {
     3.1 --- a/RemoteControlSample.csproj	Sun Feb 15 19:53:27 2015 +0100
     3.2 +++ b/RemoteControlSample.csproj	Sun Feb 15 20:28:46 2015 +0100
     3.3 @@ -128,6 +128,7 @@
     3.4      <Compile Include="HidEvent.cs" />
     3.5      <Compile Include="HidHandler.cs" />
     3.6      <Compile Include="HidUsageTables.cs" />
     3.7 +    <Compile Include="HidUtils.cs" />
     3.8      <Compile Include="MainForm.cs">
     3.9        <SubType>Form</SubType>
    3.10      </Compile>