Adding Events tab.
2 using System.Collections.Generic;
5 using System.Threading.Tasks;
6 using System.Diagnostics;
7 using System.Windows.Forms;
11 namespace SharpDisplayManager
13 class ConsumerElectronicControl
16 private PowerManager.SettingNotifier iPowerSettingNotifier;
18 public Cec.Client Client;
19 ///This flag will only work properly if both on and off events are monitored.
20 ///TODO: have a more solid implementation
21 public bool MonitorPowerOn;
23 private bool iReconnectToPowerTv = false;
25 public void TestSendKeys()
33 /// <param name="aWndHandle"></param>
34 /// <param name="aDeviceName"></param>
35 /// <param name="aHdmiPort"></param>
36 public void Start(IntPtr aWndHandle, string aDeviceName, byte aHdmiPort, bool aMonitorOn, bool aMonitorOff, bool aReconnectToPowerTv)
38 //Assuming monitor is on when we start up
39 MonitorPowerOn = true;
41 iReconnectToPowerTv = aReconnectToPowerTv;
43 //Create our power setting notifier and register the event we are interested in
44 iPowerSettingNotifier = new PowerManager.SettingNotifier(aWndHandle);
49 iPowerSettingNotifier.OnMonitorPowerOn += OnMonitorPowerOn;
55 iPowerSettingNotifier.OnMonitorPowerOff += OnMonitorPowerOff;
59 Client = new Cec.Client(aDeviceName,aHdmiPort, CecDeviceType.PlaybackDevice);
67 if (iPowerSettingNotifier != null)
69 iPowerSettingNotifier.OnMonitorPowerOn -= OnMonitorPowerOn;
70 iPowerSettingNotifier.OnMonitorPowerOff -= OnMonitorPowerOff;
71 iPowerSettingNotifier = null;
85 private void ConnectCecClient()
87 //Our client takes care of closing before trying to connect
88 if (!Client.Connect(1000))
90 Debug.WriteLine("WARNING: No CEC connection!");
94 private void OnMonitorPowerOn()
96 EventActionManager.Current.GetEvent<EventMonitorPowerOn>().Trigger();
98 Console.WriteLine("OnMonitorPowerOn");
100 if (iReconnectToPowerTv)
106 //iCecClient.Lib.PowerOnDevices(CecLogicalAddress.Tv);
107 //iCecClient.Lib.SendKeypress(CecLogicalAddress.Tv,CecUserControlCode.PowerOnFunction,true);
108 //Set ourselves as the active source
109 Client.Lib.SetActiveSource(CecDeviceType.PlaybackDevice);
110 MonitorPowerOn = true;
113 private void OnMonitorPowerOff()
115 EventActionManager.Current.GetEvent<EventMonitorPowerOff>().Trigger();
117 Console.WriteLine("OnMonitorPowerOff");
119 if (iReconnectToPowerTv)
124 //Try turning off the TV
125 Client.Lib.StandbyDevices(CecLogicalAddress.Tv);
126 //iCecClient.Lib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.PowerOffFunction, true);
127 //Tell everyone that we are no longer active
128 //iCecClient.Lib.SetInactiveView();
130 MonitorPowerOn = false;
134 /// We need to handle WM_POWERBROADCAST.
136 /// <param name="message"></param>
137 public void OnWndProc(ref Message message)
139 //Hook in our power manager
140 if (iPowerSettingNotifier != null)
142 iPowerSettingNotifier.WndProc(ref message);