StephaneLenclud@167: using System;
StephaneLenclud@167: using System.Collections.Generic;
StephaneLenclud@167: using System.Linq;
StephaneLenclud@167: using System.Text;
StephaneLenclud@167: using System.Threading.Tasks;
StephaneLenclud@167: using System.Diagnostics;
StephaneLenclud@167: using System.Windows.Forms;
StephaneLenclud@167: using CecSharp;
StephaneLenclud@167:
StephaneLenclud@167: namespace SharpDisplayManager
StephaneLenclud@167: {
StephaneLenclud@167: class ConsumerElectronicControl
StephaneLenclud@167: {
StephaneLenclud@167: ///
StephaneLenclud@167: private PowerManager.SettingNotifier iPowerSettingNotifier;
StephaneLenclud@167: ///
StephaneLenclud@167: private Cec.Client iCecClient;
StephaneLenclud@167:
StephaneLenclud@167: ///
StephaneLenclud@167: ///
StephaneLenclud@167: ///
StephaneLenclud@167: ///
StephaneLenclud@167: ///
StephaneLenclud@167: ///
StephaneLenclud@168: public void Start(IntPtr aWndHandle, string aDeviceName, byte aHdmiPort, bool aMonitorOn, bool aMonitorOff)
StephaneLenclud@167: {
StephaneLenclud@167: //Create our power setting notifier and register the event we are insterrested in
StephaneLenclud@167: iPowerSettingNotifier = new PowerManager.SettingNotifier(aWndHandle);
StephaneLenclud@168:
StephaneLenclud@168: //
StephaneLenclud@168: if (aMonitorOn)
StephaneLenclud@168: {
StephaneLenclud@168: iPowerSettingNotifier.OnMonitorPowerOn += OnMonitorPowerOn;
StephaneLenclud@168: }
StephaneLenclud@168:
StephaneLenclud@168: //
StephaneLenclud@168: if (aMonitorOff)
StephaneLenclud@168: {
StephaneLenclud@168: iPowerSettingNotifier.OnMonitorPowerOff += OnMonitorPowerOff;
StephaneLenclud@168: }
StephaneLenclud@167:
StephaneLenclud@167: //CEC
StephaneLenclud@167: iCecClient = new Cec.Client(aDeviceName,aHdmiPort);
StephaneLenclud@167: if (!iCecClient.Connect(1000))
StephaneLenclud@167: {
StephaneLenclud@167: Debug.WriteLine("WARNING: No CEC connection!");
StephaneLenclud@167: }
StephaneLenclud@167: }
StephaneLenclud@167:
StephaneLenclud@167: //
StephaneLenclud@167: public void Stop()
StephaneLenclud@167: {
StephaneLenclud@167: //
StephaneLenclud@168: if (iPowerSettingNotifier != null)
StephaneLenclud@168: {
StephaneLenclud@168: iPowerSettingNotifier.OnMonitorPowerOn -= OnMonitorPowerOn;
StephaneLenclud@168: iPowerSettingNotifier.OnMonitorPowerOff -= OnMonitorPowerOff;
StephaneLenclud@168: iPowerSettingNotifier = null;
StephaneLenclud@168: }
StephaneLenclud@167: //
StephaneLenclud@168: if (iCecClient != null)
StephaneLenclud@168: {
StephaneLenclud@168: iCecClient.Close();
StephaneLenclud@168: iCecClient.Dispose();
StephaneLenclud@168: iCecClient = null;
StephaneLenclud@168: }
StephaneLenclud@167: }
StephaneLenclud@167:
StephaneLenclud@167:
StephaneLenclud@167: private void OnMonitorPowerOn()
StephaneLenclud@167: {
StephaneLenclud@167: Debug.WriteLine("ON");
StephaneLenclud@169: iCecClient.Lib.PowerOnDevices(CecLogicalAddress.Tv);
StephaneLenclud@167: iCecClient.Lib.SetActiveSource(CecDeviceType.Tv);
StephaneLenclud@167: }
StephaneLenclud@167:
StephaneLenclud@167: private void OnMonitorPowerOff()
StephaneLenclud@167: {
StephaneLenclud@167: Debug.WriteLine("OFF");
StephaneLenclud@167: iCecClient.Lib.StandbyDevices(CecLogicalAddress.Tv);
StephaneLenclud@167: }
StephaneLenclud@167:
StephaneLenclud@167: ///
StephaneLenclud@167: /// We need to handle WM_INPUT.
StephaneLenclud@167: ///
StephaneLenclud@167: ///
StephaneLenclud@167: public void OnWndProc(ref Message message)
StephaneLenclud@167: {
StephaneLenclud@167: //Hook in our power manager
StephaneLenclud@167: if (iPowerSettingNotifier != null)
StephaneLenclud@167: {
StephaneLenclud@167: iPowerSettingNotifier.WndProc(ref message);
StephaneLenclud@167: }
StephaneLenclud@167: }
StephaneLenclud@167:
StephaneLenclud@167: }
StephaneLenclud@167: }