Published v0.9.0.0
authorStephane Lenclud
Sat, 16 Jul 2016 00:24:08 +0200
changeset 2028784c59c784e
parent 201 6213f42f1983
child 203 ce63ebb51da4
Published v0.9.0.0
HDMI CEC improvements.
Server/CecClient.cs
Server/ConsumerElectronicControl.cs
Server/MainForm.cs
Server/RichTextBoxTextWriter.cs
Server/SharpDisplayManager.csproj
     1.1 --- a/Server/CecClient.cs	Fri Jul 15 18:31:17 2016 +0200
     1.2 +++ b/Server/CecClient.cs	Sat Jul 16 00:24:08 2016 +0200
     1.3 @@ -33,6 +33,7 @@
     1.4  using System;
     1.5  using System.Text;
     1.6  using CecSharp;
     1.7 +using System.Threading;
     1.8  
     1.9  namespace Cec
    1.10  {
    1.11 @@ -43,15 +44,15 @@
    1.12          /// </summary>
    1.13          /// <param name="aDeviceName"></param>
    1.14          /// <param name="aHdmiPort"></param>
    1.15 -        public Client(string aDeviceName, byte aHdmiPort)
    1.16 +        public Client(string aDeviceName, byte aHdmiPort, CecLogLevel aLogLevel = CecLogLevel.Warning)
    1.17          {
    1.18              Config = new LibCECConfiguration();
    1.19 -            Config.DeviceTypes.Types[0] = CecDeviceType.Tv;
    1.20 +            Config.DeviceTypes.Types[0] = CecDeviceType.RecordingDevice;
    1.21              Config.DeviceName = aDeviceName;
    1.22              Config.HDMIPort = aHdmiPort;
    1.23              //Config.ClientVersion = LibCECConfiguration.CurrentVersion;
    1.24              Config.SetCallbacks(this);
    1.25 -            LogLevel = (int)CecLogLevel.All;
    1.26 +            LogLevel = (int)aLogLevel;
    1.27  
    1.28              iLib = new LibCecSharp(Config);
    1.29              iLib.InitVideoStandalone();
    1.30 @@ -67,7 +68,7 @@
    1.31          /// <param name="alert"></param>
    1.32          /// <param name="data"></param>
    1.33          /// <returns></returns>
    1.34 -        public virtual int ReceiveAlert(CecAlert alert, CecParameter data)
    1.35 +        public override int ReceiveAlert(CecAlert alert, CecParameter data)
    1.36          {
    1.37              string log = "CEC alert: " + alert.ToString();
    1.38              if (data != null && data.Type == CecParameterType.ParameterTypeString)
    1.39 @@ -88,7 +89,7 @@
    1.40          /// </summary>
    1.41          /// <param name="newVal"></param>
    1.42          /// <returns></returns>
    1.43 -        public virtual int ReceiveMenuStateChange(CecMenuState newVal)
    1.44 +        public override int ReceiveMenuStateChange(CecMenuState newVal)
    1.45          {
    1.46              Console.WriteLine("CEC menu state changed to: " + iLib.ToString(newVal));
    1.47              return 1;
    1.48 @@ -99,7 +100,7 @@
    1.49          /// </summary>
    1.50          /// <param name="logicalAddress"></param>
    1.51          /// <param name="activated"></param>
    1.52 -        public virtual void SourceActivated(CecLogicalAddress logicalAddress, bool activated)
    1.53 +        public override void SourceActivated(CecLogicalAddress logicalAddress, bool activated)
    1.54          {
    1.55              Console.WriteLine("CEC source activated: " + iLib.ToString(logicalAddress) + "/" + activated.ToString() );
    1.56              return;
    1.57 @@ -134,24 +135,24 @@
    1.58                  switch (message.Level)
    1.59                  {
    1.60                      case CecLogLevel.Error:
    1.61 -                        strLevel = "ERROR:     ";
    1.62 +                        strLevel = "ERROR: ";
    1.63                          break;
    1.64                      case CecLogLevel.Warning:
    1.65                          strLevel = "WARNING: ";
    1.66                          break;
    1.67                      case CecLogLevel.Notice:
    1.68 -                        strLevel = "NOTICE:    ";
    1.69 +                        strLevel = "NOTICE: ";
    1.70                          break;
    1.71                      case CecLogLevel.Traffic:
    1.72                          strLevel = "TRAFFIC: ";
    1.73                          break;
    1.74                      case CecLogLevel.Debug:
    1.75 -                        strLevel = "DEBUG:     ";
    1.76 +                        strLevel = "DEBUG: ";
    1.77                          break;
    1.78                      default:
    1.79                          break;
    1.80                  }
    1.81 -                string strLog = string.Format("{0} {1,16} {2}", strLevel, message.Time, message.Message);
    1.82 +                string strLog = string.Format("{0} {1} {2}", strLevel, message.Time, message.Message);
    1.83                  Console.WriteLine(strLog);
    1.84                  
    1.85              }
    1.86 @@ -186,6 +187,7 @@
    1.87              if (iConnected)
    1.88              {
    1.89                  Scan();
    1.90 +                //TestSendKey();
    1.91              }
    1.92              return iConnected;
    1.93          }
    1.94 @@ -196,6 +198,66 @@
    1.95              iConnected = false;
    1.96          }
    1.97  
    1.98 +
    1.99 +        public void TestSendKey()
   1.100 +        {
   1.101 +            //SetupMenu: opens option menu
   1.102 +            //RootMenu: opens Android home menu
   1.103 +            //ContentsMenu: nop
   1.104 +            //FavoriteMenu: nop
   1.105 +
   1.106 +            //Philips TopMenu = 16
   1.107 +            //Philips PopupMenu = 17
   1.108 +
   1.109 +            //bool res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.DisplayInformation, true);
   1.110 +            //Thread.Sleep(3000); //Wait few seconds for menu to open
   1.111 +                                //res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.SetupMenu, true);
   1.112 +
   1.113 +            for (int i = 0; i < 256; i++)
   1.114 +            {
   1.115 +                //Thread.Sleep(100);
   1.116 +                //res = iLib.SendKeyRelease(CecLogicalAddress.Tv, true);
   1.117 +                //Thread.Sleep(100);
   1.118 +                switch ((CecUserControlCode)i)
   1.119 +                {
   1.120 +                    case CecUserControlCode.Power:
   1.121 +                    case CecUserControlCode.PowerOffFunction:
   1.122 +                    case CecUserControlCode.PowerOnFunction:
   1.123 +                    case CecUserControlCode.PowerToggleFunction:
   1.124 +                    case CecUserControlCode.ElectronicProgramGuide:
   1.125 +                    case CecUserControlCode.InputSelect:
   1.126 +                    case CecUserControlCode.RootMenu:
   1.127 +
   1.128 +                        break;
   1.129 +
   1.130 +                    default:
   1.131 +                        Console.WriteLine(i.ToString());
   1.132 +                        Thread.Sleep(1000);
   1.133 +                        iLib.SendKeypress(CecLogicalAddress.Tv, (CecUserControlCode)i, true);
   1.134 +                        
   1.135 +                        break;
   1.136 +
   1.137 +                }
   1.138 +                
   1.139 +                //
   1.140 +            }
   1.141 +
   1.142 +
   1.143 +            for (int i=0;i<7;i++)
   1.144 +            {
   1.145 +                //Thread.Sleep(100);
   1.146 +                //res = iLib.SendKeyRelease(CecLogicalAddress.Tv, true);
   1.147 +                //Thread.Sleep(100);
   1.148 +                //res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.Down, true);
   1.149 +                //
   1.150 +            }
   1.151 +
   1.152 +            //res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.Select, true);
   1.153 +
   1.154 +            //res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.Select, true);
   1.155 +            //res = iLib.SendKeyRelease(CecLogicalAddress.Tv, true);
   1.156 +        }
   1.157 +
   1.158          /// <summary>
   1.159          /// 
   1.160          /// </summary>
   1.161 @@ -451,7 +513,7 @@
   1.162          /// TODO: remove that
   1.163          static void Main(string[] args)
   1.164          {
   1.165 -            Client p = new Client("CEC",2);
   1.166 +            Client p = new Client("CEC",2, CecLogLevel.All);
   1.167              if (p.Connect(10000))
   1.168              {
   1.169                  p.MainLoop();
     2.1 --- a/Server/ConsumerElectronicControl.cs	Fri Jul 15 18:31:17 2016 +0200
     2.2 +++ b/Server/ConsumerElectronicControl.cs	Sat Jul 16 00:24:08 2016 +0200
     2.3 @@ -19,6 +19,11 @@
     2.4          ///TODO: have a more solid implementation
     2.5          public bool MonitorPowerOn;
     2.6  
     2.7 +        public void TestSendKeys()
     2.8 +        {
     2.9 +            iCecClient.TestSendKey();
    2.10 +        }
    2.11 +
    2.12          /// <summary>
    2.13          /// 
    2.14          /// </summary>
    2.15 @@ -46,7 +51,7 @@
    2.16              }
    2.17  
    2.18              //CEC
    2.19 -            iCecClient = new Cec.Client(aDeviceName,aHdmiPort);
    2.20 +            iCecClient = new Cec.Client(aDeviceName,aHdmiPort, CecLogLevel.Notice);
    2.21              if (!iCecClient.Connect(1000))
    2.22              {
    2.23                  Debug.WriteLine("WARNING: No CEC connection!");
     3.1 --- a/Server/MainForm.cs	Fri Jul 15 18:31:17 2016 +0200
     3.2 +++ b/Server/MainForm.cs	Sat Jul 16 00:24:08 2016 +0200
     3.3 @@ -115,6 +115,11 @@
     3.4          /// </summary>
     3.5          private SharpLib.Notification.Control iRecordingNotification;
     3.6  
     3.7 +        /// <summary>
     3.8 +        /// 
     3.9 +        /// </summary>
    3.10 +        RichTextBoxTextWriter iWriter;
    3.11 +
    3.12  
    3.13          /// <summary>
    3.14          /// Allow user to receive window messages;
    3.15 @@ -142,8 +147,8 @@
    3.16              InitializeComponent();
    3.17  
    3.18              //Redirect console output
    3.19 -            RichTextBoxTextWriter writer = new RichTextBoxTextWriter(richTextBoxLogs);
    3.20 -            Console.SetOut(writer);
    3.21 +            iWriter = new RichTextBoxTextWriter(richTextBoxLogs);
    3.22 +            Console.SetOut(iWriter);
    3.23  
    3.24              //Populate device types
    3.25              PopulateDeviceTypes();
    3.26 @@ -2480,6 +2485,11 @@
    3.27          /// <param name="message"></param>
    3.28          protected override void WndProc(ref Message aMessage)
    3.29          {
    3.30 +            if (iWriter != null)
    3.31 +            {
    3.32 +                iWriter.FlushAccumulator();
    3.33 +            }
    3.34 +
    3.35              if (OnWndProc!=null)
    3.36              {
    3.37                  OnWndProc(ref aMessage);
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/Server/RichTextBoxTextWriter.cs	Sat Jul 16 00:24:08 2016 +0200
     4.3 @@ -0,0 +1,59 @@
     4.4 +using System;
     4.5 +using System.Text;
     4.6 +using System.IO;
     4.7 +using System.Windows.Forms;
     4.8 +
     4.9 +namespace SharpDisplayManager
    4.10 +{
    4.11 +    public class RichTextBoxTextWriter : TextWriter
    4.12 +    {
    4.13 +        public delegate void WriteDelegate(char aChar);
    4.14 +
    4.15 +        RichTextBox iRichTextBox = null;
    4.16 +        string iAccumulator = "";
    4.17 +
    4.18 +        public RichTextBoxTextWriter(RichTextBox aRichTextBox)
    4.19 +        {
    4.20 +            iRichTextBox = aRichTextBox;
    4.21 +        }
    4.22 +
    4.23 +        public override void Write(char aChar)
    4.24 +        {
    4.25 +            base.Write(aChar);
    4.26 +            if (iRichTextBox.InvokeRequired)
    4.27 +            {
    4.28 +                lock (iAccumulator)
    4.29 +                {
    4.30 +                    iAccumulator += aChar;
    4.31 +                }
    4.32 +                
    4.33 +                //WriteDelegate d = new WriteDelegate(Write);
    4.34 +                //iRichTextBox.Invoke(d, new object[] { aChar });
    4.35 +            }
    4.36 +            else
    4.37 +            {
    4.38 +                Flush();
    4.39 +                iRichTextBox.AppendText(aChar.ToString()); // When character data is written, append it to the text box.
    4.40 +            }            
    4.41 +        }
    4.42 +
    4.43 +        public override Encoding Encoding
    4.44 +        {
    4.45 +            get { return System.Text.Encoding.UTF8; }
    4.46 +        }
    4.47 +
    4.48 +        public void FlushAccumulator()
    4.49 +        {
    4.50 +            lock (iAccumulator)
    4.51 +            {
    4.52 +                if (!string.IsNullOrEmpty(iAccumulator))
    4.53 +                {
    4.54 +                    iRichTextBox.AppendText(iAccumulator); // When character data is written, append it to the text box.
    4.55 +                    iAccumulator = "";
    4.56 +                }
    4.57 +
    4.58 +            }
    4.59 +
    4.60 +        }
    4.61 +    }
    4.62 +}
    4.63 \ No newline at end of file
     5.1 --- a/Server/SharpDisplayManager.csproj	Fri Jul 15 18:31:17 2016 +0200
     5.2 +++ b/Server/SharpDisplayManager.csproj	Sat Jul 16 00:24:08 2016 +0200
     5.3 @@ -34,7 +34,7 @@
     5.4      <WebPage>index.htm</WebPage>
     5.5      <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
     5.6      <ApplicationRevision>0</ApplicationRevision>
     5.7 -    <ApplicationVersion>0.8.9.0</ApplicationVersion>
     5.8 +    <ApplicationVersion>0.9.0.0</ApplicationVersion>
     5.9      <UseApplicationTrust>false</UseApplicationTrust>
    5.10      <CreateDesktopShortcut>true</CreateDesktopShortcut>
    5.11      <PublishWizardCompleted>true</PublishWizardCompleted>