# HG changeset patch # User sl # Date 1417817893 -3600 # Node ID 24ac84ab96204261e75ee68a2432b64f95ef6d4e # Parent 8f7e35c3bfd162b9bd9f93a637c831ba6d535cec Consolidating our HID input report parsing. diff -r 8f7e35c3bfd1 -r 24ac84ab9620 HumanInterfaceDevice.cs --- a/HumanInterfaceDevice.cs Fri Dec 05 22:50:39 2014 +0100 +++ b/HumanInterfaceDevice.cs Fri Dec 05 23:18:13 2014 +0100 @@ -247,16 +247,6 @@ public enum ConsumerControl: ushort { /// - /// Alternative code for properties. - /// Also supported by Windows Media Center. - /// - MceProperties = 0x000A, - /// - /// Alternative code for program guide. - /// Also supported by Windows Media Center. - /// - MceProgramGuide = 0x0012, - /// /// Sent by MCE remotes. /// MediaSelectProgramGuide = 0x008D, diff -r 8f7e35c3bfd1 -r 24ac84ab9620 RemoteControlDevice.cs --- a/RemoteControlDevice.cs Fri Dec 05 22:50:39 2014 +0100 +++ b/RemoteControlDevice.cs Fri Dec 05 23:18:13 2014 +0100 @@ -331,7 +331,7 @@ if (this.ButtonPressed != null) { RemoteControlButton button=RemoteControlButton.Unknown; - if (aUsage == (ushort)ConsumerControl.AppCtrlProperties || aUsage == (ushort)ConsumerControl.MceProperties) + if (aUsage == (ushort)ConsumerControl.AppCtrlProperties) { button = RemoteControlButton.MoreInfo; } @@ -339,7 +339,7 @@ { button = RemoteControlButton.Print; } - else if (aUsage == (ushort)ConsumerControl.MediaSelectProgramGuide || aUsage == (ushort)ConsumerControl.MceProgramGuide) + else if (aUsage == (ushort)ConsumerControl.MediaSelectProgramGuide) { button = RemoteControlButton.Guide; } @@ -456,7 +456,9 @@ //Allocate a buffer for one HID input byte[] hidInputReport = new byte[rawInput.hid.dwSizeHid]; - //For each HID input in our raw input + Debug.WriteLine("Raw input contains " + rawInput.hid.dwCount + " HID input report(s)"); + + //For each HID input report in our raw input for (int i = 0; i < rawInput.hid.dwCount; i++) { //Compute the address from which to copy our HID input @@ -471,52 +473,29 @@ //Copy HID input into our buffer Marshal.Copy(new IntPtr(hidInputOffset), hidInputReport, 0, (int)rawInput.hid.dwSizeHid); - //Print HID raw input in our debug output - string hidDump = "HID " + rawInput.hid.dwCount + "/" + rawInput.hid.dwSizeHid + ":"; + //Print HID input report in our debug output + string hidDump = "HID input report: "; foreach (byte b in hidInputReport) { hidDump += b.ToString("X2"); } Debug.WriteLine(hidDump); - ushort usage = 0; - //hidInput[0] //Not sure what's the meaning of the code at offset 0 - if (hidInputReport.Length == 2) - { - //Single byte code - usage = hidInputReport[1]; //Get button code - } - else if (hidInputReport.Length > 2) //Defensive - { - //Assuming double bytes code - usage = (ushort)((hidInputReport[2] << 8) + hidInputReport[1]); - } - - Debug.WriteLine("Usage: 0x" + usage.ToString("X4")); - //Proper parsing now - //byte[] report = new byte[input.data.hid.dwSizeHid]; - //Marshal.Copy(IntPtr.Add(rawInput, HID_INPUT_DATA_OFFSET), report, 0, report.Length); - uint usageCount = rawInput.hid.dwCount; + uint usageCount = 1; //Assuming a single usage per input report. Is that correct? Win32.USAGE_AND_PAGE[] usages = new Win32.USAGE_AND_PAGE[usageCount]; Win32.HidStatus status = Win32.Function.HidP_GetUsagesEx(Win32.HIDP_REPORT_TYPE.HidP_Input, 0, usages, ref usageCount, preParsedData, hidInputReport, (uint)hidInputReport.Length); if (status != Win32.HidStatus.HIDP_STATUS_SUCCESS) { Debug.WriteLine("Could not parse HID data!"); - //this.LogError("Twinhan HID remote: failed to get raw input HID usages, device = {0}, status = {1}", device.Name, status); - //Dump.DumpBinary(rawInput, (int)input.header.dwSize); - //return false; } else { Debug.WriteLine("UsagePage: 0x" + usages[0].UsagePage.ToString("X4")); Debug.WriteLine("Usage: 0x" + usages[0].Usage.ToString("X4")); + //Call on our Usage Page handler + usagePageHandler(usages[0].Usage); } - - - - //Call on our Usage Page handler - usagePageHandler(usage); } }