# HG changeset patch # User StephaneLenclud # Date 1468847493 -7200 # Node ID 6345461600d75859e8a2e3c19c6ffe35e3cebaec # Parent ce63ebb51da4816a28042767a688cbe79b2d1247 Adding option to reconnect CEC before TV power action. diff -r ce63ebb51da4 -r 6345461600d7 Server/App.config --- a/Server/App.config Sun Jul 17 19:35:29 2016 +0200 +++ b/Server/App.config Mon Jul 18 15:11:33 2016 +0200 @@ -46,6 +46,9 @@ True + + False + diff -r ce63ebb51da4 -r 6345461600d7 Server/ConsumerElectronicControl.cs --- a/Server/ConsumerElectronicControl.cs Sun Jul 17 19:35:29 2016 +0200 +++ b/Server/ConsumerElectronicControl.cs Mon Jul 18 15:11:33 2016 +0200 @@ -19,6 +19,8 @@ ///TODO: have a more solid implementation public bool MonitorPowerOn; + private bool iReconnectToPowerTv = false; + public void TestSendKeys() { iCecClient.TestSendKey(); @@ -30,11 +32,13 @@ /// /// /// - public void Start(IntPtr aWndHandle, string aDeviceName, byte aHdmiPort, bool aMonitorOn, bool aMonitorOff) + public void Start(IntPtr aWndHandle, string aDeviceName, byte aHdmiPort, bool aMonitorOn, bool aMonitorOff, bool aReconnectToPowerTv) { //Assuming monitor is on when we start up MonitorPowerOn = true; + iReconnectToPowerTv = aReconnectToPowerTv; + //Create our power setting notifier and register the event we are interested in iPowerSettingNotifier = new PowerManager.SettingNotifier(aWndHandle); @@ -52,10 +56,7 @@ //CEC iCecClient = new Cec.Client(aDeviceName,aHdmiPort, CecDeviceType.PlaybackDevice, CecLogLevel.All&~CecLogLevel.Traffic&~CecLogLevel.Debug); - if (!iCecClient.Connect(1000)) - { - Debug.WriteLine("WARNING: No CEC connection!"); - } + ConnectCecClient(); } // @@ -77,10 +78,27 @@ } } + /// + /// + /// + private void ConnectCecClient() + { + //Our client takes care of closing before trying to connect + if (!iCecClient.Connect(1000)) + { + Debug.WriteLine("WARNING: No CEC connection!"); + } + } private void OnMonitorPowerOn() { Console.WriteLine("ON"); + + if (iReconnectToPowerTv) + { + ConnectCecClient(); + } + //Turn on the TV //iCecClient.Lib.PowerOnDevices(CecLogicalAddress.Tv); //iCecClient.Lib.SendKeypress(CecLogicalAddress.Tv,CecUserControlCode.PowerOnFunction,true); @@ -92,6 +110,12 @@ private void OnMonitorPowerOff() { Console.WriteLine("OFF"); + + if (iReconnectToPowerTv) + { + ConnectCecClient(); + } + //Try turning off the TV iCecClient.Lib.StandbyDevices(CecLogicalAddress.Tv); //iCecClient.Lib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.PowerOffFunction, true); diff -r ce63ebb51da4 -r 6345461600d7 Server/MainForm.Designer.cs --- a/Server/MainForm.Designer.cs Sun Jul 17 19:35:29 2016 +0200 +++ b/Server/MainForm.Designer.cs Mon Jul 18 15:11:33 2016 +0200 @@ -99,6 +99,7 @@ this.labelStartFileName = new System.Windows.Forms.Label(); this.buttonSelectFile = new System.Windows.Forms.Button(); this.tabPageCec = new System.Windows.Forms.TabPage(); + this.checkBoxCecReconnectToPowerTv = new System.Windows.Forms.CheckBox(); this.checkBoxCecMonitorOn = new System.Windows.Forms.CheckBox(); this.checkBoxCecMonitorOff = new System.Windows.Forms.CheckBox(); this.checkBoxCecEnabled = new System.Windows.Forms.CheckBox(); @@ -109,12 +110,12 @@ this.checkBoxMinimizeToTray = new System.Windows.Forms.CheckBox(); this.checkBoxAutoStart = new System.Windows.Forms.CheckBox(); this.buttonUpdate = new System.Windows.Forms.Button(); + this.tabPageLogs = new System.Windows.Forms.TabPage(); + this.richTextBoxLogs = new System.Windows.Forms.RichTextBox(); this.labelFontWidth = new System.Windows.Forms.Label(); this.labelFontHeight = new System.Windows.Forms.Label(); this.toolTip = new System.Windows.Forms.ToolTip(this.components); this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); - this.tabPageLogs = new System.Windows.Forms.TabPage(); - this.richTextBoxLogs = new System.Windows.Forms.RichTextBox(); this.panelDisplay.SuspendLayout(); this.iTableLayoutPanel.SuspendLayout(); this.statusStrip.SuspendLayout(); @@ -802,6 +803,7 @@ // // tabPageCec // + this.tabPageCec.Controls.Add(this.checkBoxCecReconnectToPowerTv); this.tabPageCec.Controls.Add(this.checkBoxCecMonitorOn); this.tabPageCec.Controls.Add(this.checkBoxCecMonitorOff); this.tabPageCec.Controls.Add(this.checkBoxCecEnabled); @@ -815,6 +817,18 @@ this.tabPageCec.Text = "CEC"; this.tabPageCec.UseVisualStyleBackColor = true; // + // checkBoxCecReconnectToPowerTv + // + this.checkBoxCecReconnectToPowerTv.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.checkBoxCecReconnectToPowerTv.AutoSize = true; + this.checkBoxCecReconnectToPowerTv.Location = new System.Drawing.Point(6, 115); + this.checkBoxCecReconnectToPowerTv.Name = "checkBoxCecReconnectToPowerTv"; + this.checkBoxCecReconnectToPowerTv.Size = new System.Drawing.Size(194, 17); + this.checkBoxCecReconnectToPowerTv.TabIndex = 24; + this.checkBoxCecReconnectToPowerTv.Text = "Reconnect before TV power switch"; + this.checkBoxCecReconnectToPowerTv.UseVisualStyleBackColor = true; + this.checkBoxCecReconnectToPowerTv.CheckedChanged += new System.EventHandler(this.checkBoxCecReconnectToPowerTv_CheckedChanged); + // // checkBoxCecMonitorOn // this.checkBoxCecMonitorOn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -940,28 +954,6 @@ this.buttonUpdate.UseVisualStyleBackColor = true; this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); // - // labelFontWidth - // - this.labelFontWidth.AutoSize = true; - this.labelFontWidth.Location = new System.Drawing.Point(13, 29); - this.labelFontWidth.Name = "labelFontWidth"; - this.labelFontWidth.Size = new System.Drawing.Size(56, 13); - this.labelFontWidth.TabIndex = 19; - this.labelFontWidth.Text = "Font width"; - // - // labelFontHeight - // - this.labelFontHeight.AutoSize = true; - this.labelFontHeight.Location = new System.Drawing.Point(13, 46); - this.labelFontHeight.Name = "labelFontHeight"; - this.labelFontHeight.Size = new System.Drawing.Size(60, 13); - this.labelFontHeight.TabIndex = 20; - this.labelFontHeight.Text = "Font height"; - // - // openFileDialog - // - this.openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*"; - // // tabPageLogs // this.tabPageLogs.Controls.Add(this.richTextBoxLogs); @@ -989,6 +981,28 @@ this.richTextBoxLogs.Text = ""; this.richTextBoxLogs.WordWrap = false; // + // labelFontWidth + // + this.labelFontWidth.AutoSize = true; + this.labelFontWidth.Location = new System.Drawing.Point(13, 29); + this.labelFontWidth.Name = "labelFontWidth"; + this.labelFontWidth.Size = new System.Drawing.Size(56, 13); + this.labelFontWidth.TabIndex = 19; + this.labelFontWidth.Text = "Font width"; + // + // labelFontHeight + // + this.labelFontHeight.AutoSize = true; + this.labelFontHeight.Location = new System.Drawing.Point(13, 46); + this.labelFontHeight.Name = "labelFontHeight"; + this.labelFontHeight.Size = new System.Drawing.Size(60, 13); + this.labelFontHeight.TabIndex = 20; + this.labelFontHeight.Text = "Font height"; + // + // openFileDialog + // + this.openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*"; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1115,6 +1129,7 @@ private System.Windows.Forms.CheckBox iCheckBoxStartIdleClient; private System.Windows.Forms.TabPage tabPageLogs; private System.Windows.Forms.RichTextBox richTextBoxLogs; + private System.Windows.Forms.CheckBox checkBoxCecReconnectToPowerTv; } } diff -r ce63ebb51da4 -r 6345461600d7 Server/MainForm.cs --- a/Server/MainForm.cs Sun Jul 17 19:35:29 2016 +0200 +++ b/Server/MainForm.cs Mon Jul 18 15:11:33 2016 +0200 @@ -1145,6 +1145,7 @@ checkBoxCecEnabled.Checked = Properties.Settings.Default.CecEnabled; checkBoxCecMonitorOn.Checked = Properties.Settings.Default.CecMonitorOn; checkBoxCecMonitorOff.Checked = Properties.Settings.Default.CecMonitorOff; + checkBoxCecReconnectToPowerTv.Checked = Properties.Settings.Default.CecReconnectToPowerTv; comboBoxHdmiPort.SelectedIndex = Properties.Settings.Default.CecHdmiPort - 1; //Mini Display settings @@ -2533,6 +2534,14 @@ ResetCec(); } + private void checkBoxCecReconnectToPowerTv_CheckedChanged(object sender, EventArgs e) + { + Properties.Settings.Default.CecReconnectToPowerTv = checkBoxCecReconnectToPowerTv.Checked; + Properties.Settings.Default.Save(); + // + ResetCec(); + } + /// /// /// @@ -2551,7 +2560,8 @@ iCecManager.Start(Handle, "CEC", Properties.Settings.Default.CecHdmiPort, Properties.Settings.Default.CecMonitorOn, - Properties.Settings.Default.CecMonitorOff); + Properties.Settings.Default.CecMonitorOff, + Properties.Settings.Default.CecReconnectToPowerTv); } } @@ -2559,5 +2569,7 @@ { StartIdleClient(); } + + } } diff -r ce63ebb51da4 -r 6345461600d7 Server/Properties/Settings.Designer.cs --- a/Server/Properties/Settings.Designer.cs Sun Jul 17 19:35:29 2016 +0200 +++ b/Server/Properties/Settings.Designer.cs Mon Jul 18 15:11:33 2016 +0200 @@ -177,5 +177,17 @@ this["StartIdleClient"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool CecReconnectToPowerTv { + get { + return ((bool)(this["CecReconnectToPowerTv"])); + } + set { + this["CecReconnectToPowerTv"] = value; + } + } } } diff -r ce63ebb51da4 -r 6345461600d7 Server/Properties/Settings.settings --- a/Server/Properties/Settings.settings Sun Jul 17 19:35:29 2016 +0200 +++ b/Server/Properties/Settings.settings Mon Jul 18 15:11:33 2016 +0200 @@ -41,5 +41,8 @@ True + + False + \ No newline at end of file