diff -r 22b327842add -r d2295c186ce1 Server/ConsumerElectronicControl.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/ConsumerElectronicControl.cs Sat Sep 26 16:35:27 2015 +0200
@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Diagnostics;
+using System.Windows.Forms;
+using CecSharp;
+
+namespace SharpDisplayManager
+{
+ class ConsumerElectronicControl
+ {
+ ///
+ private PowerManager.SettingNotifier iPowerSettingNotifier;
+ ///
+ private Cec.Client iCecClient;
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void Start(IntPtr aWndHandle, string aDeviceName, byte aHdmiPort)
+ {
+ //Create our power setting notifier and register the event we are insterrested in
+ iPowerSettingNotifier = new PowerManager.SettingNotifier(aWndHandle);
+ iPowerSettingNotifier.OnMonitorPowerOn += OnMonitorPowerOn;
+ iPowerSettingNotifier.OnMonitorPowerOff += OnMonitorPowerOff;
+
+ //CEC
+ iCecClient = new Cec.Client(aDeviceName,aHdmiPort);
+ if (!iCecClient.Connect(1000))
+ {
+ Debug.WriteLine("WARNING: No CEC connection!");
+ }
+ }
+
+ //
+ public void Stop()
+ {
+ //
+ iPowerSettingNotifier.OnMonitorPowerOn -= OnMonitorPowerOn;
+ iPowerSettingNotifier.OnMonitorPowerOff -= OnMonitorPowerOff;
+ iPowerSettingNotifier = null;
+ //
+ iCecClient.Close();
+ iCecClient.Dispose();
+ iCecClient = null;
+ }
+
+
+ private void OnMonitorPowerOn()
+ {
+ Debug.WriteLine("ON");
+ //iCecClient.Lib.PowerOnDevices(CecLogicalAddress.Tv);
+ iCecClient.Lib.SetActiveSource(CecDeviceType.Tv);
+ }
+
+ private void OnMonitorPowerOff()
+ {
+ Debug.WriteLine("OFF");
+ iCecClient.Lib.StandbyDevices(CecLogicalAddress.Tv);
+ }
+
+ ///
+ /// We need to handle WM_INPUT.
+ ///
+ ///
+ public void OnWndProc(ref Message message)
+ {
+ //Hook in our power manager
+ if (iPowerSettingNotifier != null)
+ {
+ iPowerSettingNotifier.WndProc(ref message);
+ }
+ }
+
+ }
+}
\ No newline at end of file