Published v0.8.0.0.
2 using System.Collections.Generic;
5 using System.Threading.Tasks;
6 using System.Diagnostics;
7 using System.Windows.Forms;
10 namespace SharpDisplayManager
12 class ConsumerElectronicControl
15 private PowerManager.SettingNotifier iPowerSettingNotifier;
17 private Cec.Client iCecClient;
22 /// <param name="aWndHandle"></param>
23 /// <param name="aDeviceName"></param>
24 /// <param name="aHdmiPort"></param>
25 public void Start(IntPtr aWndHandle, string aDeviceName, byte aHdmiPort, bool aMonitorOn, bool aMonitorOff)
27 //Create our power setting notifier and register the event we are insterrested in
28 iPowerSettingNotifier = new PowerManager.SettingNotifier(aWndHandle);
33 iPowerSettingNotifier.OnMonitorPowerOn += OnMonitorPowerOn;
39 iPowerSettingNotifier.OnMonitorPowerOff += OnMonitorPowerOff;
43 iCecClient = new Cec.Client(aDeviceName,aHdmiPort);
44 if (!iCecClient.Connect(1000))
46 Debug.WriteLine("WARNING: No CEC connection!");
54 if (iPowerSettingNotifier != null)
56 iPowerSettingNotifier.OnMonitorPowerOn -= OnMonitorPowerOn;
57 iPowerSettingNotifier.OnMonitorPowerOff -= OnMonitorPowerOff;
58 iPowerSettingNotifier = null;
61 if (iCecClient != null)
70 private void OnMonitorPowerOn()
72 Debug.WriteLine("ON");
73 iCecClient.Lib.PowerOnDevices(CecLogicalAddress.Tv);
74 iCecClient.Lib.SetActiveSource(CecDeviceType.Tv);
77 private void OnMonitorPowerOff()
79 Debug.WriteLine("OFF");
80 iCecClient.Lib.StandbyDevices(CecLogicalAddress.Tv);
84 /// We need to handle WM_INPUT.
86 /// <param name="message"></param>
87 public void OnWndProc(ref Message message)
89 //Hook in our power manager
90 if (iPowerSettingNotifier != null)
92 iPowerSettingNotifier.WndProc(ref message);