Adding empty FX control.
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;
18 ///This flag will only work properly if both on and off events are monitored.
19 ///TODO: have a more solid implementation
20 public bool MonitorPowerOn;
25 /// <param name="aWndHandle"></param>
26 /// <param name="aDeviceName"></param>
27 /// <param name="aHdmiPort"></param>
28 public void Start(IntPtr aWndHandle, string aDeviceName, byte aHdmiPort, bool aMonitorOn, bool aMonitorOff)
30 //Assuming monitor is on when we start up
31 MonitorPowerOn = true;
33 //Create our power setting notifier and register the event we are interested in
34 iPowerSettingNotifier = new PowerManager.SettingNotifier(aWndHandle);
39 iPowerSettingNotifier.OnMonitorPowerOn += OnMonitorPowerOn;
45 iPowerSettingNotifier.OnMonitorPowerOff += OnMonitorPowerOff;
49 iCecClient = new Cec.Client(aDeviceName,aHdmiPort);
50 if (!iCecClient.Connect(1000))
52 Debug.WriteLine("WARNING: No CEC connection!");
60 if (iPowerSettingNotifier != null)
62 iPowerSettingNotifier.OnMonitorPowerOn -= OnMonitorPowerOn;
63 iPowerSettingNotifier.OnMonitorPowerOff -= OnMonitorPowerOff;
64 iPowerSettingNotifier = null;
67 if (iCecClient != null)
76 private void OnMonitorPowerOn()
78 Debug.WriteLine("ON");
79 iCecClient.Lib.PowerOnDevices(CecLogicalAddress.Tv);
80 iCecClient.Lib.SetActiveSource(CecDeviceType.Tv);
81 MonitorPowerOn = true;
84 private void OnMonitorPowerOff()
86 Debug.WriteLine("OFF");
87 iCecClient.Lib.StandbyDevices(CecLogicalAddress.Tv);
88 MonitorPowerOn = false;
92 /// We need to handle WM_POWERBROADCAST.
94 /// <param name="message"></param>
95 public void OnWndProc(ref Message message)
97 //Hook in our power manager
98 if (iPowerSettingNotifier != null)
100 iPowerSettingNotifier.WndProc(ref message);