1.1 --- a/RemoteControlDevice.cs Sat Nov 08 12:01:19 2014 +0100
1.2 +++ b/RemoteControlDevice.cs Sat Nov 08 12:40:05 2014 +0100
1.3 @@ -54,7 +54,8 @@
1.4 RecordedTV,
1.5 Guide,
1.6 LiveTV,
1.7 - Details,
1.8 + MoreInfo,
1.9 + Print,
1.10 DVDMenu,
1.11 DVDAngle,
1.12 DVDAudio,
1.13 @@ -155,6 +156,9 @@
1.14 public delegate void RemoteControlDeviceEventHandler(object sender, RemoteControlEventArgs e);
1.15 public event RemoteControlDeviceEventHandler ButtonPressed;
1.16
1.17 + public delegate void HidUsageHandler(ushort aUsage);
1.18 +
1.19 +
1.20
1.21 //-------------------------------------------------------------
1.22 // constructors
1.23 @@ -196,7 +200,7 @@
1.24
1.25 public void ProcessMessage(Message message)
1.26 {
1.27 - int param;
1.28 + int param;
1.29
1.30 switch (message.Msg)
1.31 {
1.32 @@ -341,6 +345,71 @@
1.33 this.ButtonPressed(this, new RemoteControlEventArgs(rcb, GetDevice(param)));
1.34 }
1.35
1.36 + /// <summary>
1.37 + ///
1.38 + /// </summary>
1.39 + /// <param name="aUsage"></param>
1.40 + private void HidConsumerDeviceHandler(ushort aUsage)
1.41 + {
1.42 + if (aUsage == 0)
1.43 + {
1.44 + //Just skip those
1.45 + return;
1.46 + }
1.47 +
1.48 + if (Enum.IsDefined(typeof(ConsumerControl), aUsage) && aUsage != 0) //Our button is a known consumer control
1.49 + {
1.50 + if (this.ButtonPressed != null)
1.51 + {
1.52 + RemoteControlButton button=RemoteControlButton.Unknown;
1.53 + if (aUsage== (ushort)ConsumerControl.AppCtrlProperties)
1.54 + {
1.55 + button = RemoteControlButton.MoreInfo;
1.56 + }
1.57 + else if (aUsage==(ushort)ConsumerControl.AppCtrlPrint)
1.58 + {
1.59 + button = RemoteControlButton.Print;
1.60 + }
1.61 + else if (aUsage==(ushort)ConsumerControl.MediaSelectProgramGuide)
1.62 + {
1.63 + button = RemoteControlButton.Guide;
1.64 + }
1.65 + this.ButtonPressed(this, new RemoteControlEventArgs(button, InputDevice.OEM));
1.66 + }
1.67 + }
1.68 + else
1.69 + {
1.70 + Debug.WriteLine("Unknown Consumer Control!");
1.71 + }
1.72 + }
1.73 +
1.74 + /// <summary>
1.75 + ///
1.76 + /// </summary>
1.77 + /// <param name="aUsage"></param>
1.78 + private void HidMceRemoteHandler(ushort aUsage)
1.79 + {
1.80 + if (aUsage == 0)
1.81 + {
1.82 + //Just skip those
1.83 + return;
1.84 + }
1.85 +
1.86 +
1.87 + if (Enum.IsDefined(typeof(MceButton), aUsage) && aUsage != 0) //Our button is a known MCE button
1.88 + {
1.89 + if (this.ButtonPressed != null)
1.90 + {
1.91 + this.ButtonPressed(this, new RemoteControlEventArgs((MceButton)aUsage, InputDevice.OEM));
1.92 + }
1.93 + }
1.94 + else
1.95 + {
1.96 + Debug.WriteLine("Unknown MCE button!");
1.97 + }
1.98 +
1.99 + }
1.100 +
1.101
1.102 private void ProcessInputCommand(ref Message message)
1.103 {
1.104 @@ -373,9 +442,20 @@
1.105 //Get Usage Page and Usage
1.106 Debug.WriteLine("Usage Page: 0x" + deviceInfo.hid.usUsagePage.ToString("X4") + " Usage: 0x" + deviceInfo.hid.usUsage.ToString("X4"));
1.107
1.108 + //
1.109 + HidUsageHandler handler=null;
1.110 +
1.111 //Make sure both usage page and usage are matching MCE remote
1.112 //TODO: handle more that just MCE usage page.
1.113 - if (deviceInfo.hid.usUsagePage != (ushort)Hid.UsagePage.MceRemote || deviceInfo.hid.usUsage != (ushort)Hid.UsageId.MceRemoteUsage)
1.114 + if (deviceInfo.hid.usUsagePage == (ushort)Hid.UsagePage.MceRemote || deviceInfo.hid.usUsage == (ushort)Hid.UsageId.MceRemoteUsage)
1.115 + {
1.116 + handler = HidMceRemoteHandler;
1.117 + }
1.118 + else if (deviceInfo.hid.usUsagePage == (ushort)Hid.UsagePage.Consumer || deviceInfo.hid.usUsage == (ushort)Hid.UsageId.ConsumerControl)
1.119 + {
1.120 + handler = HidConsumerDeviceHandler;
1.121 + }
1.122 + else
1.123 {
1.124 Debug.WriteLine("Not MCE remote page and usage.");
1.125 return;
1.126 @@ -424,17 +504,11 @@
1.127 else if (hidInput.Length > 2) //Defensive
1.128 {
1.129 //Assuming double bytes code
1.130 - usage = (ushort)((hidInput[1] << 2) + hidInput[2]);
1.131 + usage = (ushort)((hidInput[2] << 8) + hidInput[1]);
1.132 }
1.133
1.134 //
1.135 - if (Enum.IsDefined(typeof(MceButton), usage) && usage != 0) //Our button is a known MCE button
1.136 - {
1.137 - if (this.ButtonPressed != null) //What's that?
1.138 - {
1.139 - this.ButtonPressed(this, new RemoteControlEventArgs((MceButton)usage, InputDevice.OEM));
1.140 - }
1.141 - }
1.142 + handler(usage);
1.143 }
1.144
1.145 }