Adding option to reconnect CEC before TV power action.
authorStephaneLenclud
Mon, 18 Jul 2016 15:11:33 +0200
changeset 2046345461600d7
parent 203 ce63ebb51da4
child 205 127382a596e7
Adding option to reconnect CEC before TV power action.
Server/App.config
Server/ConsumerElectronicControl.cs
Server/MainForm.Designer.cs
Server/MainForm.cs
Server/Properties/Settings.Designer.cs
Server/Properties/Settings.settings
     1.1 --- a/Server/App.config	Sun Jul 17 19:35:29 2016 +0200
     1.2 +++ b/Server/App.config	Mon Jul 18 15:11:33 2016 +0200
     1.3 @@ -46,6 +46,9 @@
     1.4              <setting name="StartIdleClient" serializeAs="String">
     1.5                  <value>True</value>
     1.6              </setting>
     1.7 +            <setting name="CecReconnectToPowerTv" serializeAs="String">
     1.8 +                <value>False</value>
     1.9 +            </setting>
    1.10          </SharpDisplayManager.Properties.Settings>
    1.11      </userSettings>
    1.12  </configuration>
     2.1 --- a/Server/ConsumerElectronicControl.cs	Sun Jul 17 19:35:29 2016 +0200
     2.2 +++ b/Server/ConsumerElectronicControl.cs	Mon Jul 18 15:11:33 2016 +0200
     2.3 @@ -19,6 +19,8 @@
     2.4          ///TODO: have a more solid implementation
     2.5          public bool MonitorPowerOn;
     2.6  
     2.7 +        private bool iReconnectToPowerTv = false;
     2.8 +
     2.9          public void TestSendKeys()
    2.10          {
    2.11              iCecClient.TestSendKey();
    2.12 @@ -30,11 +32,13 @@
    2.13          /// <param name="aWndHandle"></param>
    2.14          /// <param name="aDeviceName"></param>
    2.15          /// <param name="aHdmiPort"></param>
    2.16 -        public void Start(IntPtr aWndHandle, string aDeviceName, byte aHdmiPort, bool aMonitorOn, bool aMonitorOff)
    2.17 +        public void Start(IntPtr aWndHandle, string aDeviceName, byte aHdmiPort, bool aMonitorOn, bool aMonitorOff, bool aReconnectToPowerTv)
    2.18          {
    2.19              //Assuming monitor is on when we start up
    2.20              MonitorPowerOn = true;
    2.21  
    2.22 +            iReconnectToPowerTv = aReconnectToPowerTv;
    2.23 +
    2.24              //Create our power setting notifier and register the event we are interested in
    2.25              iPowerSettingNotifier = new PowerManager.SettingNotifier(aWndHandle);
    2.26  
    2.27 @@ -52,10 +56,7 @@
    2.28  
    2.29              //CEC
    2.30              iCecClient = new Cec.Client(aDeviceName,aHdmiPort, CecDeviceType.PlaybackDevice, CecLogLevel.All&~CecLogLevel.Traffic&~CecLogLevel.Debug);
    2.31 -            if (!iCecClient.Connect(1000))
    2.32 -            {
    2.33 -                Debug.WriteLine("WARNING: No CEC connection!");
    2.34 -            }
    2.35 +            ConnectCecClient();
    2.36          }
    2.37  
    2.38          //
    2.39 @@ -77,10 +78,27 @@
    2.40              }
    2.41          }
    2.42  
    2.43 +        /// <summary>
    2.44 +        /// 
    2.45 +        /// </summary>
    2.46 +        private void ConnectCecClient()
    2.47 +        {
    2.48 +            //Our client takes care of closing before trying to connect
    2.49 +            if (!iCecClient.Connect(1000))
    2.50 +            {
    2.51 +                Debug.WriteLine("WARNING: No CEC connection!");
    2.52 +            }
    2.53 +        }
    2.54  
    2.55          private void OnMonitorPowerOn()
    2.56          {
    2.57              Console.WriteLine("ON");
    2.58 +
    2.59 +            if (iReconnectToPowerTv)
    2.60 +            {
    2.61 +                ConnectCecClient();
    2.62 +            }
    2.63 +
    2.64              //Turn on the TV
    2.65              //iCecClient.Lib.PowerOnDevices(CecLogicalAddress.Tv);
    2.66              //iCecClient.Lib.SendKeypress(CecLogicalAddress.Tv,CecUserControlCode.PowerOnFunction,true);
    2.67 @@ -92,6 +110,12 @@
    2.68          private void OnMonitorPowerOff()
    2.69          {
    2.70              Console.WriteLine("OFF");
    2.71 +
    2.72 +            if (iReconnectToPowerTv)
    2.73 +            {
    2.74 +                ConnectCecClient();
    2.75 +            }
    2.76 +
    2.77              //Try turning off the TV
    2.78              iCecClient.Lib.StandbyDevices(CecLogicalAddress.Tv);
    2.79              //iCecClient.Lib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.PowerOffFunction, true);
     3.1 --- a/Server/MainForm.Designer.cs	Sun Jul 17 19:35:29 2016 +0200
     3.2 +++ b/Server/MainForm.Designer.cs	Mon Jul 18 15:11:33 2016 +0200
     3.3 @@ -99,6 +99,7 @@
     3.4              this.labelStartFileName = new System.Windows.Forms.Label();
     3.5              this.buttonSelectFile = new System.Windows.Forms.Button();
     3.6              this.tabPageCec = new System.Windows.Forms.TabPage();
     3.7 +            this.checkBoxCecReconnectToPowerTv = new System.Windows.Forms.CheckBox();
     3.8              this.checkBoxCecMonitorOn = new System.Windows.Forms.CheckBox();
     3.9              this.checkBoxCecMonitorOff = new System.Windows.Forms.CheckBox();
    3.10              this.checkBoxCecEnabled = new System.Windows.Forms.CheckBox();
    3.11 @@ -109,12 +110,12 @@
    3.12              this.checkBoxMinimizeToTray = new System.Windows.Forms.CheckBox();
    3.13              this.checkBoxAutoStart = new System.Windows.Forms.CheckBox();
    3.14              this.buttonUpdate = new System.Windows.Forms.Button();
    3.15 +            this.tabPageLogs = new System.Windows.Forms.TabPage();
    3.16 +            this.richTextBoxLogs = new System.Windows.Forms.RichTextBox();
    3.17              this.labelFontWidth = new System.Windows.Forms.Label();
    3.18              this.labelFontHeight = new System.Windows.Forms.Label();
    3.19              this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    3.20              this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
    3.21 -            this.tabPageLogs = new System.Windows.Forms.TabPage();
    3.22 -            this.richTextBoxLogs = new System.Windows.Forms.RichTextBox();
    3.23              this.panelDisplay.SuspendLayout();
    3.24              this.iTableLayoutPanel.SuspendLayout();
    3.25              this.statusStrip.SuspendLayout();
    3.26 @@ -802,6 +803,7 @@
    3.27              // 
    3.28              // tabPageCec
    3.29              // 
    3.30 +            this.tabPageCec.Controls.Add(this.checkBoxCecReconnectToPowerTv);
    3.31              this.tabPageCec.Controls.Add(this.checkBoxCecMonitorOn);
    3.32              this.tabPageCec.Controls.Add(this.checkBoxCecMonitorOff);
    3.33              this.tabPageCec.Controls.Add(this.checkBoxCecEnabled);
    3.34 @@ -815,6 +817,18 @@
    3.35              this.tabPageCec.Text = "CEC";
    3.36              this.tabPageCec.UseVisualStyleBackColor = true;
    3.37              // 
    3.38 +            // checkBoxCecReconnectToPowerTv
    3.39 +            // 
    3.40 +            this.checkBoxCecReconnectToPowerTv.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    3.41 +            this.checkBoxCecReconnectToPowerTv.AutoSize = true;
    3.42 +            this.checkBoxCecReconnectToPowerTv.Location = new System.Drawing.Point(6, 115);
    3.43 +            this.checkBoxCecReconnectToPowerTv.Name = "checkBoxCecReconnectToPowerTv";
    3.44 +            this.checkBoxCecReconnectToPowerTv.Size = new System.Drawing.Size(194, 17);
    3.45 +            this.checkBoxCecReconnectToPowerTv.TabIndex = 24;
    3.46 +            this.checkBoxCecReconnectToPowerTv.Text = "Reconnect before TV power switch";
    3.47 +            this.checkBoxCecReconnectToPowerTv.UseVisualStyleBackColor = true;
    3.48 +            this.checkBoxCecReconnectToPowerTv.CheckedChanged += new System.EventHandler(this.checkBoxCecReconnectToPowerTv_CheckedChanged);
    3.49 +            // 
    3.50              // checkBoxCecMonitorOn
    3.51              // 
    3.52              this.checkBoxCecMonitorOn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    3.53 @@ -940,28 +954,6 @@
    3.54              this.buttonUpdate.UseVisualStyleBackColor = true;
    3.55              this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
    3.56              // 
    3.57 -            // labelFontWidth
    3.58 -            // 
    3.59 -            this.labelFontWidth.AutoSize = true;
    3.60 -            this.labelFontWidth.Location = new System.Drawing.Point(13, 29);
    3.61 -            this.labelFontWidth.Name = "labelFontWidth";
    3.62 -            this.labelFontWidth.Size = new System.Drawing.Size(56, 13);
    3.63 -            this.labelFontWidth.TabIndex = 19;
    3.64 -            this.labelFontWidth.Text = "Font width";
    3.65 -            // 
    3.66 -            // labelFontHeight
    3.67 -            // 
    3.68 -            this.labelFontHeight.AutoSize = true;
    3.69 -            this.labelFontHeight.Location = new System.Drawing.Point(13, 46);
    3.70 -            this.labelFontHeight.Name = "labelFontHeight";
    3.71 -            this.labelFontHeight.Size = new System.Drawing.Size(60, 13);
    3.72 -            this.labelFontHeight.TabIndex = 20;
    3.73 -            this.labelFontHeight.Text = "Font height";
    3.74 -            // 
    3.75 -            // openFileDialog
    3.76 -            // 
    3.77 -            this.openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*";
    3.78 -            // 
    3.79              // tabPageLogs
    3.80              // 
    3.81              this.tabPageLogs.Controls.Add(this.richTextBoxLogs);
    3.82 @@ -989,6 +981,28 @@
    3.83              this.richTextBoxLogs.Text = "";
    3.84              this.richTextBoxLogs.WordWrap = false;
    3.85              // 
    3.86 +            // labelFontWidth
    3.87 +            // 
    3.88 +            this.labelFontWidth.AutoSize = true;
    3.89 +            this.labelFontWidth.Location = new System.Drawing.Point(13, 29);
    3.90 +            this.labelFontWidth.Name = "labelFontWidth";
    3.91 +            this.labelFontWidth.Size = new System.Drawing.Size(56, 13);
    3.92 +            this.labelFontWidth.TabIndex = 19;
    3.93 +            this.labelFontWidth.Text = "Font width";
    3.94 +            // 
    3.95 +            // labelFontHeight
    3.96 +            // 
    3.97 +            this.labelFontHeight.AutoSize = true;
    3.98 +            this.labelFontHeight.Location = new System.Drawing.Point(13, 46);
    3.99 +            this.labelFontHeight.Name = "labelFontHeight";
   3.100 +            this.labelFontHeight.Size = new System.Drawing.Size(60, 13);
   3.101 +            this.labelFontHeight.TabIndex = 20;
   3.102 +            this.labelFontHeight.Text = "Font height";
   3.103 +            // 
   3.104 +            // openFileDialog
   3.105 +            // 
   3.106 +            this.openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*";
   3.107 +            // 
   3.108              // MainForm
   3.109              // 
   3.110              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
   3.111 @@ -1115,6 +1129,7 @@
   3.112          private System.Windows.Forms.CheckBox iCheckBoxStartIdleClient;
   3.113          private System.Windows.Forms.TabPage tabPageLogs;
   3.114          private System.Windows.Forms.RichTextBox richTextBoxLogs;
   3.115 +        private System.Windows.Forms.CheckBox checkBoxCecReconnectToPowerTv;
   3.116      }
   3.117  }
   3.118  
     4.1 --- a/Server/MainForm.cs	Sun Jul 17 19:35:29 2016 +0200
     4.2 +++ b/Server/MainForm.cs	Mon Jul 18 15:11:33 2016 +0200
     4.3 @@ -1145,6 +1145,7 @@
     4.4              checkBoxCecEnabled.Checked = Properties.Settings.Default.CecEnabled;
     4.5              checkBoxCecMonitorOn.Checked = Properties.Settings.Default.CecMonitorOn;
     4.6              checkBoxCecMonitorOff.Checked = Properties.Settings.Default.CecMonitorOff;
     4.7 +		    checkBoxCecReconnectToPowerTv.Checked = Properties.Settings.Default.CecReconnectToPowerTv;
     4.8              comboBoxHdmiPort.SelectedIndex = Properties.Settings.Default.CecHdmiPort - 1;
     4.9  
    4.10              //Mini Display settings
    4.11 @@ -2533,6 +2534,14 @@
    4.12              ResetCec();
    4.13          }
    4.14  
    4.15 +        private void checkBoxCecReconnectToPowerTv_CheckedChanged(object sender, EventArgs e)
    4.16 +        {
    4.17 +            Properties.Settings.Default.CecReconnectToPowerTv = checkBoxCecReconnectToPowerTv.Checked;
    4.18 +            Properties.Settings.Default.Save();
    4.19 +            //
    4.20 +            ResetCec();
    4.21 +        }
    4.22 +
    4.23          /// <summary>
    4.24          /// 
    4.25          /// </summary>
    4.26 @@ -2551,7 +2560,8 @@
    4.27                  iCecManager.Start(Handle, "CEC",
    4.28                  Properties.Settings.Default.CecHdmiPort,
    4.29                  Properties.Settings.Default.CecMonitorOn,
    4.30 -                Properties.Settings.Default.CecMonitorOff);
    4.31 +                Properties.Settings.Default.CecMonitorOff,
    4.32 +                Properties.Settings.Default.CecReconnectToPowerTv);
    4.33              }
    4.34          }
    4.35  
    4.36 @@ -2559,5 +2569,7 @@
    4.37          {
    4.38              StartIdleClient();
    4.39          }
    4.40 +
    4.41 +
    4.42      }
    4.43  }
     5.1 --- a/Server/Properties/Settings.Designer.cs	Sun Jul 17 19:35:29 2016 +0200
     5.2 +++ b/Server/Properties/Settings.Designer.cs	Mon Jul 18 15:11:33 2016 +0200
     5.3 @@ -177,5 +177,17 @@
     5.4                  this["StartIdleClient"] = value;
     5.5              }
     5.6          }
     5.7 +        
     5.8 +        [global::System.Configuration.UserScopedSettingAttribute()]
     5.9 +        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    5.10 +        [global::System.Configuration.DefaultSettingValueAttribute("False")]
    5.11 +        public bool CecReconnectToPowerTv {
    5.12 +            get {
    5.13 +                return ((bool)(this["CecReconnectToPowerTv"]));
    5.14 +            }
    5.15 +            set {
    5.16 +                this["CecReconnectToPowerTv"] = value;
    5.17 +            }
    5.18 +        }
    5.19      }
    5.20  }
     6.1 --- a/Server/Properties/Settings.settings	Sun Jul 17 19:35:29 2016 +0200
     6.2 +++ b/Server/Properties/Settings.settings	Mon Jul 18 15:11:33 2016 +0200
     6.3 @@ -41,5 +41,8 @@
     6.4      <Setting Name="StartIdleClient" Type="System.Boolean" Scope="User">
     6.5        <Value Profile="(Default)">True</Value>
     6.6      </Setting>
     6.7 +    <Setting Name="CecReconnectToPowerTv" Type="System.Boolean" Scope="User">
     6.8 +      <Value Profile="(Default)">False</Value>
     6.9 +    </Setting>
    6.10    </Settings>
    6.11  </SettingsFile>
    6.12 \ No newline at end of file