1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Server/ConsumerElectronicControl.cs Sat Sep 26 16:35:27 2015 +0200
1.3 @@ -0,0 +1,81 @@
1.4 +using System;
1.5 +using System.Collections.Generic;
1.6 +using System.Linq;
1.7 +using System.Text;
1.8 +using System.Threading.Tasks;
1.9 +using System.Diagnostics;
1.10 +using System.Windows.Forms;
1.11 +using CecSharp;
1.12 +
1.13 +namespace SharpDisplayManager
1.14 +{
1.15 + class ConsumerElectronicControl
1.16 + {
1.17 + ///
1.18 + private PowerManager.SettingNotifier iPowerSettingNotifier;
1.19 + ///
1.20 + private Cec.Client iCecClient;
1.21 +
1.22 + /// <summary>
1.23 + ///
1.24 + /// </summary>
1.25 + /// <param name="aWndHandle"></param>
1.26 + /// <param name="aDeviceName"></param>
1.27 + /// <param name="aHdmiPort"></param>
1.28 + public void Start(IntPtr aWndHandle, string aDeviceName, byte aHdmiPort)
1.29 + {
1.30 + //Create our power setting notifier and register the event we are insterrested in
1.31 + iPowerSettingNotifier = new PowerManager.SettingNotifier(aWndHandle);
1.32 + iPowerSettingNotifier.OnMonitorPowerOn += OnMonitorPowerOn;
1.33 + iPowerSettingNotifier.OnMonitorPowerOff += OnMonitorPowerOff;
1.34 +
1.35 + //CEC
1.36 + iCecClient = new Cec.Client(aDeviceName,aHdmiPort);
1.37 + if (!iCecClient.Connect(1000))
1.38 + {
1.39 + Debug.WriteLine("WARNING: No CEC connection!");
1.40 + }
1.41 + }
1.42 +
1.43 + //
1.44 + public void Stop()
1.45 + {
1.46 + //
1.47 + iPowerSettingNotifier.OnMonitorPowerOn -= OnMonitorPowerOn;
1.48 + iPowerSettingNotifier.OnMonitorPowerOff -= OnMonitorPowerOff;
1.49 + iPowerSettingNotifier = null;
1.50 + //
1.51 + iCecClient.Close();
1.52 + iCecClient.Dispose();
1.53 + iCecClient = null;
1.54 + }
1.55 +
1.56 +
1.57 + private void OnMonitorPowerOn()
1.58 + {
1.59 + Debug.WriteLine("ON");
1.60 + //iCecClient.Lib.PowerOnDevices(CecLogicalAddress.Tv);
1.61 + iCecClient.Lib.SetActiveSource(CecDeviceType.Tv);
1.62 + }
1.63 +
1.64 + private void OnMonitorPowerOff()
1.65 + {
1.66 + Debug.WriteLine("OFF");
1.67 + iCecClient.Lib.StandbyDevices(CecLogicalAddress.Tv);
1.68 + }
1.69 +
1.70 + /// <summary>
1.71 + /// We need to handle WM_INPUT.
1.72 + /// </summary>
1.73 + /// <param name="message"></param>
1.74 + public void OnWndProc(ref Message message)
1.75 + {
1.76 + //Hook in our power manager
1.77 + if (iPowerSettingNotifier != null)
1.78 + {
1.79 + iPowerSettingNotifier.WndProc(ref message);
1.80 + }
1.81 + }
1.82 +
1.83 + }
1.84 +}
1.85 \ No newline at end of file