1.1 --- a/RemoteControlDevice.cs Fri Dec 05 22:50:39 2014 +0100
1.2 +++ b/RemoteControlDevice.cs Fri Dec 05 23:18:13 2014 +0100
1.3 @@ -331,7 +331,7 @@
1.4 if (this.ButtonPressed != null)
1.5 {
1.6 RemoteControlButton button=RemoteControlButton.Unknown;
1.7 - if (aUsage == (ushort)ConsumerControl.AppCtrlProperties || aUsage == (ushort)ConsumerControl.MceProperties)
1.8 + if (aUsage == (ushort)ConsumerControl.AppCtrlProperties)
1.9 {
1.10 button = RemoteControlButton.MoreInfo;
1.11 }
1.12 @@ -339,7 +339,7 @@
1.13 {
1.14 button = RemoteControlButton.Print;
1.15 }
1.16 - else if (aUsage == (ushort)ConsumerControl.MediaSelectProgramGuide || aUsage == (ushort)ConsumerControl.MceProgramGuide)
1.17 + else if (aUsage == (ushort)ConsumerControl.MediaSelectProgramGuide)
1.18 {
1.19 button = RemoteControlButton.Guide;
1.20 }
1.21 @@ -456,7 +456,9 @@
1.22 //Allocate a buffer for one HID input
1.23 byte[] hidInputReport = new byte[rawInput.hid.dwSizeHid];
1.24
1.25 - //For each HID input in our raw input
1.26 + Debug.WriteLine("Raw input contains " + rawInput.hid.dwCount + " HID input report(s)");
1.27 +
1.28 + //For each HID input report in our raw input
1.29 for (int i = 0; i < rawInput.hid.dwCount; i++)
1.30 {
1.31 //Compute the address from which to copy our HID input
1.32 @@ -471,52 +473,29 @@
1.33 //Copy HID input into our buffer
1.34 Marshal.Copy(new IntPtr(hidInputOffset), hidInputReport, 0, (int)rawInput.hid.dwSizeHid);
1.35
1.36 - //Print HID raw input in our debug output
1.37 - string hidDump = "HID " + rawInput.hid.dwCount + "/" + rawInput.hid.dwSizeHid + ":";
1.38 + //Print HID input report in our debug output
1.39 + string hidDump = "HID input report: ";
1.40 foreach (byte b in hidInputReport)
1.41 {
1.42 hidDump += b.ToString("X2");
1.43 }
1.44 Debug.WriteLine(hidDump);
1.45
1.46 - ushort usage = 0;
1.47 - //hidInput[0] //Not sure what's the meaning of the code at offset 0
1.48 - if (hidInputReport.Length == 2)
1.49 - {
1.50 - //Single byte code
1.51 - usage = hidInputReport[1]; //Get button code
1.52 - }
1.53 - else if (hidInputReport.Length > 2) //Defensive
1.54 - {
1.55 - //Assuming double bytes code
1.56 - usage = (ushort)((hidInputReport[2] << 8) + hidInputReport[1]);
1.57 - }
1.58 -
1.59 - Debug.WriteLine("Usage: 0x" + usage.ToString("X4"));
1.60 -
1.61 //Proper parsing now
1.62 - //byte[] report = new byte[input.data.hid.dwSizeHid];
1.63 - //Marshal.Copy(IntPtr.Add(rawInput, HID_INPUT_DATA_OFFSET), report, 0, report.Length);
1.64 - uint usageCount = rawInput.hid.dwCount;
1.65 + uint usageCount = 1; //Assuming a single usage per input report. Is that correct?
1.66 Win32.USAGE_AND_PAGE[] usages = new Win32.USAGE_AND_PAGE[usageCount];
1.67 Win32.HidStatus status = Win32.Function.HidP_GetUsagesEx(Win32.HIDP_REPORT_TYPE.HidP_Input, 0, usages, ref usageCount, preParsedData, hidInputReport, (uint)hidInputReport.Length);
1.68 if (status != Win32.HidStatus.HIDP_STATUS_SUCCESS)
1.69 {
1.70 Debug.WriteLine("Could not parse HID data!");
1.71 - //this.LogError("Twinhan HID remote: failed to get raw input HID usages, device = {0}, status = {1}", device.Name, status);
1.72 - //Dump.DumpBinary(rawInput, (int)input.header.dwSize);
1.73 - //return false;
1.74 }
1.75 else
1.76 {
1.77 Debug.WriteLine("UsagePage: 0x" + usages[0].UsagePage.ToString("X4"));
1.78 Debug.WriteLine("Usage: 0x" + usages[0].Usage.ToString("X4"));
1.79 + //Call on our Usage Page handler
1.80 + usagePageHandler(usages[0].Usage);
1.81 }
1.82 -
1.83 -
1.84 -
1.85 - //Call on our Usage Page handler
1.86 - usagePageHandler(usage);
1.87 }
1.88
1.89 }