CEC TV power on and standby working.
1.1 --- a/Server/App.config Thu Sep 24 22:45:32 2015 +0200
1.2 +++ b/Server/App.config Fri Sep 25 12:28:47 2015 +0200
1.3 @@ -5,7 +5,7 @@
1.4 <section name="SharpDisplayManager.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
1.5 </sectionGroup>
1.6 </configSections>
1.7 - <startup>
1.8 + <startup useLegacyV2RuntimeActivationPolicy="true">
1.9 <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
1.10 </startup>
1.11 <userSettings>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/Server/CecSharpClient.cs Fri Sep 25 12:28:47 2015 +0200
2.3 @@ -0,0 +1,376 @@
2.4 +/*
2.5 + * This file is part of the libCEC(R) library.
2.6 + *
2.7 + * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
2.8 + * libCEC(R) is an original work, containing original code.
2.9 + *
2.10 + * libCEC(R) is a trademark of Pulse-Eight Limited.
2.11 + *
2.12 + * This program is dual-licensed; you can redistribute it and/or modify
2.13 + * it under the terms of the GNU General Public License as published by
2.14 + * the Free Software Foundation; either version 2 of the License, or
2.15 + * (at your option) any later version.
2.16 + *
2.17 + * This program is distributed in the hope that it will be useful,
2.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.20 + * GNU General Public License for more details.
2.21 + *
2.22 + * You should have received a copy of the GNU General Public License
2.23 + * along with this program; if not, write to the Free Software
2.24 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2.25 + *
2.26 + *
2.27 + * Alternatively, you can license this library under a commercial license,
2.28 + * please contact Pulse-Eight Licensing for more information.
2.29 + *
2.30 + * For more information contact:
2.31 + * Pulse-Eight Licensing <license@pulse-eight.com>
2.32 + * http://www.pulse-eight.com/
2.33 + * http://www.pulse-eight.net/
2.34 + */
2.35 +
2.36 +using System;
2.37 +using System.Text;
2.38 +using CecSharp;
2.39 +
2.40 +namespace Cec
2.41 +{
2.42 + class Client : CecCallbackMethods
2.43 + {
2.44 + public Client()
2.45 + {
2.46 + Config = new LibCECConfiguration();
2.47 + Config.DeviceTypes.Types[0] = CecDeviceType.Tv;
2.48 + Config.DeviceName = "CEC";
2.49 + Config.HDMIPort = 2;
2.50 + //Config.ClientVersion = LibCECConfiguration.CurrentVersion;
2.51 + Config.SetCallbacks(this);
2.52 + LogLevel = (int)CecLogLevel.All;
2.53 +
2.54 + Lib = new LibCecSharp(Config);
2.55 + Lib.InitVideoStandalone();
2.56 +
2.57 + //Console.WriteLine("CEC Parser created - libCEC version " + Lib.VersionToString(Config.ServerVersion));
2.58 + Console.WriteLine("CEC Parser created - libCEC version " + Config.ServerVersion);
2.59 + }
2.60 +
2.61 + public override int ReceiveCommand(CecCommand command)
2.62 + {
2.63 + return 1;
2.64 + }
2.65 +
2.66 + public override int ReceiveKeypress(CecKeypress key)
2.67 + {
2.68 + return 1;
2.69 + }
2.70 +
2.71 + public override int ReceiveLogMessage(CecLogMessage message)
2.72 + {
2.73 + if (((int)message.Level & LogLevel) == (int)message.Level)
2.74 + {
2.75 + string strLevel = "";
2.76 + switch (message.Level)
2.77 + {
2.78 + case CecLogLevel.Error:
2.79 + strLevel = "ERROR: ";
2.80 + break;
2.81 + case CecLogLevel.Warning:
2.82 + strLevel = "WARNING: ";
2.83 + break;
2.84 + case CecLogLevel.Notice:
2.85 + strLevel = "NOTICE: ";
2.86 + break;
2.87 + case CecLogLevel.Traffic:
2.88 + strLevel = "TRAFFIC: ";
2.89 + break;
2.90 + case CecLogLevel.Debug:
2.91 + strLevel = "DEBUG: ";
2.92 + break;
2.93 + default:
2.94 + break;
2.95 + }
2.96 + string strLog = string.Format("{0} {1,16} {2}", strLevel, message.Time, message.Message);
2.97 + Console.WriteLine(strLog);
2.98 + }
2.99 + return 1;
2.100 + }
2.101 +
2.102 + /// <summary>
2.103 + ///
2.104 + /// </summary>
2.105 + /// <param name="timeout"></param>
2.106 + /// <returns></returns>
2.107 + public bool Connect(int timeout)
2.108 + {
2.109 + CecAdapter[] adapters = Lib.FindAdapters(string.Empty);
2.110 + if (adapters.Length > 0)
2.111 + return Connect(adapters[0].ComPort, timeout);
2.112 + else
2.113 + {
2.114 + Console.WriteLine("Did not find any CEC adapters");
2.115 + return false;
2.116 + }
2.117 + }
2.118 +
2.119 + public bool Connect(string port, int timeout)
2.120 + {
2.121 + return Lib.Open(port, timeout);
2.122 + }
2.123 +
2.124 + public void Close()
2.125 + {
2.126 + Lib.Close();
2.127 + }
2.128 +
2.129 + public void ListDevices()
2.130 + {
2.131 + int iAdapter = 0;
2.132 + foreach (CecAdapter adapter in Lib.FindAdapters(string.Empty))
2.133 + {
2.134 + Console.WriteLine("Adapter: " + iAdapter++);
2.135 + Console.WriteLine("Path: " + adapter.Path);
2.136 + Console.WriteLine("Com port: " + adapter.ComPort);
2.137 + }
2.138 + }
2.139 +
2.140 + void ShowConsoleHelp()
2.141 + {
2.142 + Console.WriteLine(
2.143 + "================================================================================" + Environment.NewLine +
2.144 + "Available commands:" + Environment.NewLine +
2.145 + Environment.NewLine +
2.146 + "[tx] {bytes} transfer bytes over the CEC line." + Environment.NewLine +
2.147 + "[txn] {bytes} transfer bytes but don't wait for transmission ACK." + Environment.NewLine +
2.148 + "[on] {address} power on the device with the given logical address." + Environment.NewLine +
2.149 + "[standby] {address} put the device with the given address in standby mode." + Environment.NewLine +
2.150 + "[la] {logical_address} change the logical address of the CEC adapter." + Environment.NewLine +
2.151 + "[pa] {physical_address} change the physical address of the CEC adapter." + Environment.NewLine +
2.152 + "[osd] {addr} {string} set OSD message on the specified device." + Environment.NewLine +
2.153 + "[ver] {addr} get the CEC version of the specified device." + Environment.NewLine +
2.154 + "[ven] {addr} get the vendor ID of the specified device." + Environment.NewLine +
2.155 + "[lang] {addr} get the menu language of the specified device." + Environment.NewLine +
2.156 + "[pow] {addr} get the power status of the specified device." + Environment.NewLine +
2.157 + "[poll] {addr} poll the specified device." + Environment.NewLine +
2.158 + "[scan] scan the CEC bus and display device info" + Environment.NewLine +
2.159 + "[mon] {1|0} enable or disable CEC bus monitoring." + Environment.NewLine +
2.160 + "[log] {1 - 31} change the log level. see cectypes.h for values." + Environment.NewLine +
2.161 + "[ping] send a ping command to the CEC adapter." + Environment.NewLine +
2.162 + "[bl] to let the adapter enter the bootloader, to upgrade" + Environment.NewLine +
2.163 + " the flash rom." + Environment.NewLine +
2.164 + "[r] reconnect to the CEC adapter." + Environment.NewLine +
2.165 + "[h] or [help] show this help." + Environment.NewLine +
2.166 + "[q] or [quit] to quit the CEC test client and switch off all" + Environment.NewLine +
2.167 + " connected CEC devices." + Environment.NewLine +
2.168 + "================================================================================");
2.169 + }
2.170 +
2.171 + public void MainLoop()
2.172 + {
2.173 + bool bContinue = true;
2.174 + string command;
2.175 + while (bContinue)
2.176 + {
2.177 + Console.WriteLine("waiting for input");
2.178 +
2.179 + command = Console.ReadLine();
2.180 + if (command != null && command.Length == 0)
2.181 + continue;
2.182 + string[] splitCommand = command.Split(' ');
2.183 + if (splitCommand[0] == "tx" || splitCommand[0] == "txn")
2.184 + {
2.185 + CecCommand bytes = new CecCommand();
2.186 + for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++)
2.187 + {
2.188 + bytes.PushBack(byte.Parse(splitCommand[iPtr], System.Globalization.NumberStyles.HexNumber));
2.189 + }
2.190 +
2.191 + if (command == "txn")
2.192 + bytes.TransmitTimeout = 0;
2.193 +
2.194 + Lib.Transmit(bytes);
2.195 + }
2.196 + else if (splitCommand[0] == "on")
2.197 + {
2.198 + if (splitCommand.Length > 1)
2.199 + Lib.PowerOnDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
2.200 + else
2.201 + Lib.PowerOnDevices(CecLogicalAddress.Broadcast);
2.202 + }
2.203 + else if (splitCommand[0] == "standby")
2.204 + {
2.205 + if (splitCommand.Length > 1)
2.206 + Lib.StandbyDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
2.207 + else
2.208 + Lib.StandbyDevices(CecLogicalAddress.Broadcast);
2.209 + }
2.210 + else if (splitCommand[0] == "poll")
2.211 + {
2.212 + bool bSent = false;
2.213 + if (splitCommand.Length > 1)
2.214 + bSent = Lib.PollDevice((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
2.215 + else
2.216 + bSent = Lib.PollDevice(CecLogicalAddress.Broadcast);
2.217 + if (bSent)
2.218 + Console.WriteLine("POLL message sent");
2.219 + else
2.220 + Console.WriteLine("POLL message not sent");
2.221 + }
2.222 + else if (splitCommand[0] == "la")
2.223 + {
2.224 + if (splitCommand.Length > 1)
2.225 + Lib.SetLogicalAddress((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
2.226 + }
2.227 + else if (splitCommand[0] == "pa")
2.228 + {
2.229 + if (splitCommand.Length > 1)
2.230 + Lib.SetPhysicalAddress(ushort.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
2.231 + }
2.232 + else if (splitCommand[0] == "osd")
2.233 + {
2.234 + if (splitCommand.Length > 2)
2.235 + {
2.236 + StringBuilder osdString = new StringBuilder();
2.237 + for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++)
2.238 + {
2.239 + osdString.Append(splitCommand[iPtr]);
2.240 + if (iPtr != splitCommand.Length - 1)
2.241 + osdString.Append(" ");
2.242 + }
2.243 + Lib.SetOSDString((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber), CecDisplayControl.DisplayForDefaultTime, osdString.ToString());
2.244 + }
2.245 + }
2.246 + else if (splitCommand[0] == "ping")
2.247 + {
2.248 + Lib.PingAdapter();
2.249 + }
2.250 + else if (splitCommand[0] == "mon")
2.251 + {
2.252 + bool enable = splitCommand.Length > 1 ? splitCommand[1] == "1" : false;
2.253 + Lib.SwitchMonitoring(enable);
2.254 + }
2.255 + else if (splitCommand[0] == "bl")
2.256 + {
2.257 + Lib.StartBootloader();
2.258 + }
2.259 + else if (splitCommand[0] == "lang")
2.260 + {
2.261 + if (splitCommand.Length > 1)
2.262 + {
2.263 + string language = Lib.GetDeviceMenuLanguage((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
2.264 + Console.WriteLine("Menu language: " + language);
2.265 + }
2.266 + }
2.267 + else if (splitCommand[0] == "ven")
2.268 + {
2.269 + if (splitCommand.Length > 1)
2.270 + {
2.271 + CecVendorId vendor = Lib.GetDeviceVendorId((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
2.272 + Console.WriteLine("Vendor ID: " + Lib.ToString(vendor));
2.273 + }
2.274 + }
2.275 + else if (splitCommand[0] == "ver")
2.276 + {
2.277 + if (splitCommand.Length > 1)
2.278 + {
2.279 + CecVersion version = Lib.GetDeviceCecVersion((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
2.280 + Console.WriteLine("CEC version: " + Lib.ToString(version));
2.281 + }
2.282 + }
2.283 + else if (splitCommand[0] == "pow")
2.284 + {
2.285 + if (splitCommand.Length > 1)
2.286 + {
2.287 + CecPowerStatus power = Lib.GetDevicePowerStatus((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
2.288 + Console.WriteLine("power status: " + Lib.ToString(power));
2.289 + }
2.290 + }
2.291 + else if (splitCommand[0] == "r")
2.292 + {
2.293 + Console.WriteLine("closing the connection");
2.294 + Lib.Close();
2.295 +
2.296 + Console.WriteLine("opening a new connection");
2.297 + Connect(10000);
2.298 +
2.299 + Console.WriteLine("setting active source");
2.300 + Lib.SetActiveSource(CecDeviceType.PlaybackDevice);
2.301 + }
2.302 + else if (splitCommand[0] == "scan")
2.303 + {
2.304 + StringBuilder output = new StringBuilder();
2.305 + output.AppendLine("CEC bus information");
2.306 + output.AppendLine("===================");
2.307 + CecLogicalAddresses addresses = Lib.GetActiveDevices();
2.308 + for (int iPtr = 0; iPtr < addresses.Addresses.Length; iPtr++)
2.309 + {
2.310 + CecLogicalAddress address = (CecLogicalAddress)iPtr;
2.311 + if (!addresses.IsSet(address))
2.312 + continue;
2.313 +
2.314 + CecVendorId iVendorId = Lib.GetDeviceVendorId(address);
2.315 + bool bActive = Lib.IsActiveDevice(address);
2.316 + ushort iPhysicalAddress = Lib.GetDevicePhysicalAddress(address);
2.317 + string strAddr = "todo: fixme"; //Lib.PhysicalAddressToString(iPhysicalAddress);
2.318 + CecVersion iCecVersion = Lib.GetDeviceCecVersion(address);
2.319 + CecPowerStatus power = Lib.GetDevicePowerStatus(address);
2.320 + string osdName = Lib.GetDeviceOSDName(address);
2.321 + string lang = Lib.GetDeviceMenuLanguage(address);
2.322 +
2.323 + output.AppendLine("device #" + iPtr + ": " + Lib.ToString(address));
2.324 + output.AppendLine("address: " + strAddr);
2.325 + output.AppendLine("active source: " + (bActive ? "yes" : "no"));
2.326 + output.AppendLine("vendor: " + Lib.ToString(iVendorId));
2.327 + output.AppendLine("osd string: " + osdName);
2.328 + output.AppendLine("CEC version: " + Lib.ToString(iCecVersion));
2.329 + output.AppendLine("power status: " + Lib.ToString(power));
2.330 + if (!string.IsNullOrEmpty(lang))
2.331 + output.AppendLine("language: " + lang);
2.332 + output.AppendLine("");
2.333 + }
2.334 + Console.WriteLine(output.ToString());
2.335 + }
2.336 + else if (splitCommand[0] == "h" || splitCommand[0] == "help")
2.337 + ShowConsoleHelp();
2.338 + else if (splitCommand[0] == "q" || splitCommand[0] == "quit")
2.339 + bContinue = false;
2.340 + else if (splitCommand[0] == "log" && splitCommand.Length > 1)
2.341 + LogLevel = int.Parse(splitCommand[1]);
2.342 + }
2.343 + }
2.344 +
2.345 + static void Main(string[] args)
2.346 + {
2.347 + Client p = new Client();
2.348 + if (p.Connect(10000))
2.349 + {
2.350 + p.MainLoop();
2.351 + }
2.352 + else
2.353 + {
2.354 + Console.WriteLine("Could not open a connection to the CEC adapter");
2.355 + }
2.356 + }
2.357 +
2.358 + /// <summary>
2.359 + ///
2.360 + /// </summary>
2.361 + public void PowerOnDevices(CecLogicalAddress aAddress)
2.362 + {
2.363 + Lib.PowerOnDevices(aAddress);
2.364 + }
2.365 +
2.366 + /// <summary>
2.367 + ///
2.368 + /// </summary>
2.369 + public void StandbyDevices(CecLogicalAddress aAddress)
2.370 + {
2.371 + Lib.StandbyDevices(aAddress);
2.372 + }
2.373 +
2.374 +
2.375 + private int LogLevel;
2.376 + private LibCecSharp Lib;
2.377 + private LibCECConfiguration Config;
2.378 + }
2.379 +}
3.1 Binary file Server/LibCecSharp.dll has changed
4.1 --- a/Server/MainForm.Hid.cs Thu Sep 24 22:45:32 2015 +0200
4.2 +++ b/Server/MainForm.Hid.cs Fri Sep 25 12:28:47 2015 +0200
4.3 @@ -34,6 +34,9 @@
4.4 ///
4.5 private PowerManager.SettingNotifier iPowerSettingNotifier;
4.6
4.7 + ///
4.8 + private Cec.Client iCecClient;
4.9 +
4.10 /// <summary>
4.11 /// Register HID devices so that we receive corresponding WM_INPUT messages.
4.12 /// </summary>
4.13 @@ -99,16 +102,25 @@
4.14 iPowerSettingNotifier = new PowerManager.SettingNotifier(Handle);
4.15 iPowerSettingNotifier.OnMonitorPowerOn += MonitorPowerOn;
4.16 iPowerSettingNotifier.OnMonitorPowerOff += MonitorPowerOff;
4.17 +
4.18 + //CEC
4.19 + iCecClient = new Cec.Client();
4.20 + if (!iCecClient.Connect(1000))
4.21 + {
4.22 + Debug.WriteLine("WARNING: No CEC connection!");
4.23 + }
4.24 }
4.25
4.26 - static void MonitorPowerOn()
4.27 + void MonitorPowerOn()
4.28 {
4.29 Debug.WriteLine("ON");
4.30 + iCecClient.PowerOnDevices(CecSharp.CecLogicalAddress.Tv);
4.31 }
4.32
4.33 - static void MonitorPowerOff()
4.34 + void MonitorPowerOff()
4.35 {
4.36 Debug.WriteLine("OFF");
4.37 + iCecClient.StandbyDevices(CecSharp.CecLogicalAddress.Tv);
4.38 }
4.39
4.40
5.1 --- a/Server/SharpDisplayManager.csproj Thu Sep 24 22:45:32 2015 +0200
5.2 +++ b/Server/SharpDisplayManager.csproj Fri Sep 25 12:28:47 2015 +0200
5.3 @@ -69,6 +69,7 @@
5.4 <ErrorReport>prompt</ErrorReport>
5.5 <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
5.6 <Prefer32Bit>false</Prefer32Bit>
5.7 + <UseVSHostingProcess>true</UseVSHostingProcess>
5.8 </PropertyGroup>
5.9 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
5.10 <OutputPath>bin\x86\Release\</OutputPath>
5.11 @@ -105,6 +106,10 @@
5.12 <TargetZone>LocalIntranet</TargetZone>
5.13 </PropertyGroup>
5.14 <ItemGroup>
5.15 + <Reference Include="LibCecSharp, Version=2.2.0.0, Culture=neutral, processorArchitecture=x86">
5.16 + <HintPath>.\LibCecSharp.dll</HintPath>
5.17 + <SpecificVersion>False</SpecificVersion>
5.18 + </Reference>
5.19 <Reference Include="Microsoft.VisualBasic" />
5.20 <Reference Include="Microsoft.VisualBasic.PowerPacks.Vs, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
5.21 <Reference Include="MiniDisplayInterop">
5.22 @@ -141,6 +146,7 @@
5.23 </ItemGroup>
5.24 <ItemGroup>
5.25 <Compile Include="CbtHook.cs" />
5.26 + <Compile Include="CecSharpClient.cs" />
5.27 <Compile Include="ClientData.cs" />
5.28 <Compile Include="MainForm.Hid.cs">
5.29 <DependentUpon>MainForm.cs</DependentUpon>
5.30 @@ -270,7 +276,12 @@
5.31 <WCFMetadata Include="Service References\" />
5.32 </ItemGroup>
5.33 <ItemGroup>
5.34 - <Content Include="MiniDisplay.dll" />
5.35 + <Content Include="libcec.dll">
5.36 + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5.37 + </Content>
5.38 + <Content Include="MiniDisplay.dll">
5.39 + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5.40 + </Content>
5.41 </ItemGroup>
5.42 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5.43 <Import Project="..\packages\LibMiniDisplay.1.1.4\build\LibMiniDisplay.targets" Condition="Exists('..\packages\LibMiniDisplay.1.1.4\build\LibMiniDisplay.targets')" />
6.1 Binary file Server/libcec.dll has changed