# HG changeset patch # User Stephane Lenclud # Date 1468621448 -7200 # Node ID 8784c59c784e2b9c71db552a5b900898fdb1d49e # Parent 6213f42f1983d21389cdc8141c0a36a6bd07265e Published v0.9.0.0 HDMI CEC improvements. diff -r 6213f42f1983 -r 8784c59c784e Server/CecClient.cs --- a/Server/CecClient.cs Fri Jul 15 18:31:17 2016 +0200 +++ b/Server/CecClient.cs Sat Jul 16 00:24:08 2016 +0200 @@ -33,6 +33,7 @@ using System; using System.Text; using CecSharp; +using System.Threading; namespace Cec { @@ -43,15 +44,15 @@ /// /// /// - public Client(string aDeviceName, byte aHdmiPort) + public Client(string aDeviceName, byte aHdmiPort, CecLogLevel aLogLevel = CecLogLevel.Warning) { Config = new LibCECConfiguration(); - Config.DeviceTypes.Types[0] = CecDeviceType.Tv; + Config.DeviceTypes.Types[0] = CecDeviceType.RecordingDevice; Config.DeviceName = aDeviceName; Config.HDMIPort = aHdmiPort; //Config.ClientVersion = LibCECConfiguration.CurrentVersion; Config.SetCallbacks(this); - LogLevel = (int)CecLogLevel.All; + LogLevel = (int)aLogLevel; iLib = new LibCecSharp(Config); iLib.InitVideoStandalone(); @@ -67,7 +68,7 @@ /// /// /// - public virtual int ReceiveAlert(CecAlert alert, CecParameter data) + public override int ReceiveAlert(CecAlert alert, CecParameter data) { string log = "CEC alert: " + alert.ToString(); if (data != null && data.Type == CecParameterType.ParameterTypeString) @@ -88,7 +89,7 @@ /// /// /// - public virtual int ReceiveMenuStateChange(CecMenuState newVal) + public override int ReceiveMenuStateChange(CecMenuState newVal) { Console.WriteLine("CEC menu state changed to: " + iLib.ToString(newVal)); return 1; @@ -99,7 +100,7 @@ /// /// /// - public virtual void SourceActivated(CecLogicalAddress logicalAddress, bool activated) + public override void SourceActivated(CecLogicalAddress logicalAddress, bool activated) { Console.WriteLine("CEC source activated: " + iLib.ToString(logicalAddress) + "/" + activated.ToString() ); return; @@ -134,24 +135,24 @@ switch (message.Level) { case CecLogLevel.Error: - strLevel = "ERROR: "; + strLevel = "ERROR: "; break; case CecLogLevel.Warning: strLevel = "WARNING: "; break; case CecLogLevel.Notice: - strLevel = "NOTICE: "; + strLevel = "NOTICE: "; break; case CecLogLevel.Traffic: strLevel = "TRAFFIC: "; break; case CecLogLevel.Debug: - strLevel = "DEBUG: "; + strLevel = "DEBUG: "; break; default: break; } - string strLog = string.Format("{0} {1,16} {2}", strLevel, message.Time, message.Message); + string strLog = string.Format("{0} {1} {2}", strLevel, message.Time, message.Message); Console.WriteLine(strLog); } @@ -186,6 +187,7 @@ if (iConnected) { Scan(); + //TestSendKey(); } return iConnected; } @@ -196,6 +198,66 @@ iConnected = false; } + + public void TestSendKey() + { + //SetupMenu: opens option menu + //RootMenu: opens Android home menu + //ContentsMenu: nop + //FavoriteMenu: nop + + //Philips TopMenu = 16 + //Philips PopupMenu = 17 + + //bool res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.DisplayInformation, true); + //Thread.Sleep(3000); //Wait few seconds for menu to open + //res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.SetupMenu, true); + + for (int i = 0; i < 256; i++) + { + //Thread.Sleep(100); + //res = iLib.SendKeyRelease(CecLogicalAddress.Tv, true); + //Thread.Sleep(100); + switch ((CecUserControlCode)i) + { + case CecUserControlCode.Power: + case CecUserControlCode.PowerOffFunction: + case CecUserControlCode.PowerOnFunction: + case CecUserControlCode.PowerToggleFunction: + case CecUserControlCode.ElectronicProgramGuide: + case CecUserControlCode.InputSelect: + case CecUserControlCode.RootMenu: + + break; + + default: + Console.WriteLine(i.ToString()); + Thread.Sleep(1000); + iLib.SendKeypress(CecLogicalAddress.Tv, (CecUserControlCode)i, true); + + break; + + } + + // + } + + + for (int i=0;i<7;i++) + { + //Thread.Sleep(100); + //res = iLib.SendKeyRelease(CecLogicalAddress.Tv, true); + //Thread.Sleep(100); + //res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.Down, true); + // + } + + //res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.Select, true); + + //res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.Select, true); + //res = iLib.SendKeyRelease(CecLogicalAddress.Tv, true); + } + /// /// /// @@ -451,7 +513,7 @@ /// TODO: remove that static void Main(string[] args) { - Client p = new Client("CEC",2); + Client p = new Client("CEC",2, CecLogLevel.All); if (p.Connect(10000)) { p.MainLoop(); diff -r 6213f42f1983 -r 8784c59c784e Server/ConsumerElectronicControl.cs --- a/Server/ConsumerElectronicControl.cs Fri Jul 15 18:31:17 2016 +0200 +++ b/Server/ConsumerElectronicControl.cs Sat Jul 16 00:24:08 2016 +0200 @@ -19,6 +19,11 @@ ///TODO: have a more solid implementation public bool MonitorPowerOn; + public void TestSendKeys() + { + iCecClient.TestSendKey(); + } + /// /// /// @@ -46,7 +51,7 @@ } //CEC - iCecClient = new Cec.Client(aDeviceName,aHdmiPort); + iCecClient = new Cec.Client(aDeviceName,aHdmiPort, CecLogLevel.Notice); if (!iCecClient.Connect(1000)) { Debug.WriteLine("WARNING: No CEC connection!"); diff -r 6213f42f1983 -r 8784c59c784e Server/MainForm.cs --- a/Server/MainForm.cs Fri Jul 15 18:31:17 2016 +0200 +++ b/Server/MainForm.cs Sat Jul 16 00:24:08 2016 +0200 @@ -115,6 +115,11 @@ /// private SharpLib.Notification.Control iRecordingNotification; + /// + /// + /// + RichTextBoxTextWriter iWriter; + /// /// Allow user to receive window messages; @@ -142,8 +147,8 @@ InitializeComponent(); //Redirect console output - RichTextBoxTextWriter writer = new RichTextBoxTextWriter(richTextBoxLogs); - Console.SetOut(writer); + iWriter = new RichTextBoxTextWriter(richTextBoxLogs); + Console.SetOut(iWriter); //Populate device types PopulateDeviceTypes(); @@ -2480,6 +2485,11 @@ /// protected override void WndProc(ref Message aMessage) { + if (iWriter != null) + { + iWriter.FlushAccumulator(); + } + if (OnWndProc!=null) { OnWndProc(ref aMessage); diff -r 6213f42f1983 -r 8784c59c784e Server/RichTextBoxTextWriter.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/RichTextBoxTextWriter.cs Sat Jul 16 00:24:08 2016 +0200 @@ -0,0 +1,59 @@ +using System; +using System.Text; +using System.IO; +using System.Windows.Forms; + +namespace SharpDisplayManager +{ + public class RichTextBoxTextWriter : TextWriter + { + public delegate void WriteDelegate(char aChar); + + RichTextBox iRichTextBox = null; + string iAccumulator = ""; + + public RichTextBoxTextWriter(RichTextBox aRichTextBox) + { + iRichTextBox = aRichTextBox; + } + + public override void Write(char aChar) + { + base.Write(aChar); + if (iRichTextBox.InvokeRequired) + { + lock (iAccumulator) + { + iAccumulator += aChar; + } + + //WriteDelegate d = new WriteDelegate(Write); + //iRichTextBox.Invoke(d, new object[] { aChar }); + } + else + { + Flush(); + iRichTextBox.AppendText(aChar.ToString()); // When character data is written, append it to the text box. + } + } + + public override Encoding Encoding + { + get { return System.Text.Encoding.UTF8; } + } + + public void FlushAccumulator() + { + lock (iAccumulator) + { + if (!string.IsNullOrEmpty(iAccumulator)) + { + iRichTextBox.AppendText(iAccumulator); // When character data is written, append it to the text box. + iAccumulator = ""; + } + + } + + } + } +} \ No newline at end of file diff -r 6213f42f1983 -r 8784c59c784e Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Fri Jul 15 18:31:17 2016 +0200 +++ b/Server/SharpDisplayManager.csproj Sat Jul 16 00:24:08 2016 +0200 @@ -34,7 +34,7 @@ index.htm false 0 - 0.8.9.0 + 0.9.0.0 false true true