HidEvent.cs
changeset 52 2f34ceaf0692
parent 49 2ec781e51f36
child 53 e7831b781512
     1.1 --- a/HidEvent.cs	Sat Feb 14 22:13:31 2015 +0100
     1.2 +++ b/HidEvent.cs	Sat Feb 14 23:23:41 2015 +0100
     1.3 @@ -99,8 +99,6 @@
     1.4  
     1.5              //Declare some pointers
     1.6              IntPtr rawInputBuffer = IntPtr.Zero;
     1.7 -            //My understanding is that this is basically our HID descriptor 
     1.8 -            IntPtr preParsedData = IntPtr.Zero;
     1.9  
    1.10              try
    1.11              {
    1.12 @@ -111,6 +109,7 @@
    1.13                      return;
    1.14                  }
    1.15  
    1.16 +                //TODO: move this into our device class
    1.17                  //Fetch device info
    1.18                  RID_DEVICE_INFO deviceInfo = new RID_DEVICE_INFO();
    1.19                  if (!Win32.Utils.RawInput.GetDeviceInfo(rawInput.header.hDevice, ref deviceInfo))
    1.20 @@ -131,8 +130,6 @@
    1.21                      UsagePage = deviceInfo.hid.usUsagePage;
    1.22                      UsageCollection = deviceInfo.hid.usUsage;
    1.23  
    1.24 -                    preParsedData = Win32.Utils.RawInput.GetPreParsedData(rawInput.header.hDevice);
    1.25 -
    1.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
    1.27                          && rawInput.hid.dwCount > 0))    //Check that we have at least one HID msg
    1.28                      {
    1.29 @@ -167,13 +164,13 @@
    1.30  						//First query our usage count
    1.31                          uint usageCount = 0; 
    1.32                          Win32.USAGE_AND_PAGE[] usages = null;
    1.33 -						Win32.HidStatus status = Win32.Function.HidP_GetUsagesEx(Win32.HIDP_REPORT_TYPE.HidP_Input, 0, usages, ref usageCount, preParsedData, InputReport, (uint)InputReport.Length);
    1.34 +						Win32.HidStatus status = Win32.Function.HidP_GetUsagesEx(Win32.HIDP_REPORT_TYPE.HidP_Input, 0, usages, ref usageCount, Device.PreParsedData, InputReport, (uint)InputReport.Length);
    1.35  						if (status == Win32.HidStatus.HIDP_STATUS_BUFFER_TOO_SMALL)
    1.36  						{
    1.37  							//Allocate a large enough buffer 
    1.38  							usages = new Win32.USAGE_AND_PAGE[usageCount];
    1.39  							//...and fetch our usages
    1.40 -							status = Win32.Function.HidP_GetUsagesEx(Win32.HIDP_REPORT_TYPE.HidP_Input, 0, usages, ref usageCount, preParsedData, InputReport, (uint)InputReport.Length);
    1.41 +                            status = Win32.Function.HidP_GetUsagesEx(Win32.HIDP_REPORT_TYPE.HidP_Input, 0, usages, ref usageCount, Device.PreParsedData, InputReport, (uint)InputReport.Length);
    1.42  							if (status != Win32.HidStatus.HIDP_STATUS_SUCCESS)
    1.43  							{
    1.44  								Debug.WriteLine("Second pass could not parse HID data: " + status.ToString());
    1.45 @@ -186,6 +183,7 @@
    1.46  
    1.47  						Debug.WriteLine("Usage count: " + usageCount.ToString());
    1.48  
    1.49 +                        //Copy usages into this event
    1.50  						if (usages != null)
    1.51  						{
    1.52  							foreach (USAGE_AND_PAGE up in usages)
    1.53 @@ -195,7 +193,7 @@
    1.54  								//Add this usage to our list
    1.55  								Usages.Add(up.Usage);
    1.56  							}
    1.57 -						}
    1.58 +						}                       
    1.59                      }
    1.60                  }
    1.61                  else if (rawInput.header.dwType == Const.RIM_TYPEMOUSE)
    1.62 @@ -223,7 +221,6 @@
    1.63              {
    1.64                  //Always executed when leaving our try block
    1.65                  Marshal.FreeHGlobal(rawInputBuffer);
    1.66 -                Marshal.FreeHGlobal(preParsedData);
    1.67              }
    1.68  
    1.69              //