# HG changeset patch # User StephaneLenclud # Date 1469385367 -7200 # Node ID 4961ede27e0aa00805a0d53749b9ec5a4b980893 # Parent 77092f415c7c7163ef54f588bf1e4a2b89fd9bb3 Adding a bunch of CEC actions. diff -r 77092f415c7c -r 4961ede27e0a Server/Actions/ActionCecActiveSource.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/Actions/ActionCecActiveSource.cs Sun Jul 24 20:36:07 2016 +0200 @@ -0,0 +1,26 @@ +using CecSharp; +using SharpLib.Ear; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace SharpDisplayManager +{ + [DataContract] + [AttributeAction(Id = "Cec.ActiveSource", Name = "CEC Active Source", Description = "Set this CEC device as active source.")] + class ActionCecActiveSource : SharpLib.Ear.Action + { + public override void Execute() + { + if (Cec.Client.Static == null) + { + Console.WriteLine("WARNING: No CEC client installed."); + } + + Cec.Client.Static.Lib.SetActiveSource(CecDeviceType.PlaybackDevice); + } + } +} diff -r 77092f415c7c -r 4961ede27e0a Server/Actions/ActionCecClose.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/Actions/ActionCecClose.cs Sun Jul 24 20:36:07 2016 +0200 @@ -0,0 +1,26 @@ +using CecSharp; +using SharpLib.Ear; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace SharpDisplayManager +{ + [DataContract] + [AttributeAction(Id = "Cec.Close", Name = "CEC Close", Description = "Close CEC connection.")] + class ActionCecClose : SharpLib.Ear.Action + { + public override void Execute() + { + if (Cec.Client.Static == null) + { + Console.WriteLine("WARNING: No CEC client installed."); + } + + Cec.Client.Static.Close(); + } + } +} diff -r 77092f415c7c -r 4961ede27e0a Server/Actions/ActionCecInactiveSource.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/Actions/ActionCecInactiveSource.cs Sun Jul 24 20:36:07 2016 +0200 @@ -0,0 +1,26 @@ +using CecSharp; +using SharpLib.Ear; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace SharpDisplayManager +{ + [DataContract] + [AttributeAction(Id = "Cec.InactiveSource", Name = "CEC Inactive Source", Description = "Set this CEC device as inactive source.")] + class ActionCecInactiveSource : SharpLib.Ear.Action + { + public override void Execute() + { + if (Cec.Client.Static == null) + { + Console.WriteLine("WARNING: No CEC client installed."); + } + + Cec.Client.Static.Lib.SetInactiveView(); + } + } +} diff -r 77092f415c7c -r 4961ede27e0a Server/Actions/ActionCecOpen.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/Actions/ActionCecOpen.cs Sun Jul 24 20:36:07 2016 +0200 @@ -0,0 +1,26 @@ +using CecSharp; +using SharpLib.Ear; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace SharpDisplayManager +{ + [DataContract] + [AttributeAction(Id = "Cec.Open", Name = "CEC Open", Description = "Open CEC connection.")] + class ActionCecOpen : SharpLib.Ear.Action + { + public override void Execute() + { + if (Cec.Client.Static == null) + { + Console.WriteLine("WARNING: No CEC client installed."); + } + + Cec.Client.Static.Open(1000); + } + } +} diff -r 77092f415c7c -r 4961ede27e0a Server/Actions/ActionCecPowerOnTv.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/Actions/ActionCecPowerOnTv.cs Sun Jul 24 20:36:07 2016 +0200 @@ -0,0 +1,26 @@ +using CecSharp; +using SharpLib.Ear; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace SharpDisplayManager +{ + [DataContract] + [AttributeAction(Id = "Cec.PowerOnTv", Name = "CEC Power On TV", Description = "Power on TVs on your CEC HDMI network.")] + class ActionCecPowerOnTv : SharpLib.Ear.Action + { + public override void Execute() + { + if (Cec.Client.Static == null) + { + Console.WriteLine("WARNING: No CEC client installed."); + } + + Cec.Client.Static.Lib.PowerOnDevices(CecLogicalAddress.Tv); + } + } +} diff -r 77092f415c7c -r 4961ede27e0a Server/Actions/ActionCecScan.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/Actions/ActionCecScan.cs Sun Jul 24 20:36:07 2016 +0200 @@ -0,0 +1,27 @@ +using CecSharp; +using SharpLib.Ear; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace SharpDisplayManager +{ + + [DataContract] + [AttributeAction(Id = "Cec.Scan", Name = "CEC Scan", Description = "Scan devices on your CEC HDMI network.")] + class ActionCecScan : SharpLib.Ear.Action + { + public override void Execute() + { + if (Cec.Client.Static == null) + { + Console.WriteLine("WARNING: No CEC client installed."); + } + + Cec.Client.Static.Scan(); + } + } +} diff -r 77092f415c7c -r 4961ede27e0a Server/Actions/ActionCecSendKeypressTvPowerOff.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/Actions/ActionCecSendKeypressTvPowerOff.cs Sun Jul 24 20:36:07 2016 +0200 @@ -0,0 +1,27 @@ + +using CecSharp; +using SharpLib.Ear; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace SharpDisplayManager +{ + [DataContract] + [AttributeAction(Id = "Cec.SendKepressTvPowerOff", Name = "CEC Send Keypress TV Power Off", Description = "Send Power Off keypress to your TV.")] + class ActionCecSendKeypressTvPowerOff : SharpLib.Ear.Action + { + public override void Execute() + { + if (Cec.Client.Static == null) + { + Console.WriteLine("WARNING: No CEC client installed."); + } + + Cec.Client.Static.Lib.SendKeypress(CecLogicalAddress.Tv,CecUserControlCode.PowerOffFunction,true); + } + } +} diff -r 77092f415c7c -r 4961ede27e0a Server/Actions/ActionCecSendKeypressTvPowerOn.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/Actions/ActionCecSendKeypressTvPowerOn.cs Sun Jul 24 20:36:07 2016 +0200 @@ -0,0 +1,27 @@ + +using CecSharp; +using SharpLib.Ear; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace SharpDisplayManager +{ + [DataContract] + [AttributeAction(Id = "Cec.SendKepressTvPowerOn", Name = "CEC Send Keypress TV Power On", Description = "Send Power On keypress to your TV.")] + class ActionCecSendKeypressTvPowerOn : SharpLib.Ear.Action + { + public override void Execute() + { + if (Cec.Client.Static == null) + { + Console.WriteLine("WARNING: No CEC client installed."); + } + + Cec.Client.Static.Lib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.PowerOnFunction, true); + } + } +} diff -r 77092f415c7c -r 4961ede27e0a Server/Actions/ActionCecStandbyTv.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/Actions/ActionCecStandbyTv.cs Sun Jul 24 20:36:07 2016 +0200 @@ -0,0 +1,26 @@ +using CecSharp; +using SharpLib.Ear; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace SharpDisplayManager +{ + [DataContract] + [AttributeAction(Id = "Cec.StandbyTv", Name = "CEC Standby TV", Description = "Standby TVs on your CEC HDMI network.")] + class ActionCecStandbyTv : SharpLib.Ear.Action + { + public override void Execute() + { + if (Cec.Client.Static == null) + { + Console.WriteLine("WARNING: No CEC client installed."); + } + + Cec.Client.Static.Lib.StandbyDevices(CecLogicalAddress.Tv); + } + } +} diff -r 77092f415c7c -r 4961ede27e0a Server/CecClient.cs --- a/Server/CecClient.cs Sun Jul 24 14:22:56 2016 +0200 +++ b/Server/CecClient.cs Sun Jul 24 20:36:07 2016 +0200 @@ -40,6 +40,11 @@ class Client : CecCallbackMethods { /// + /// Enable public static access + /// + public static Client Static; + + /// /// Provide direct access to CEC library /// public LibCecSharp Lib @@ -91,8 +96,18 @@ iLib = new LibCecSharp(Config); iLib.InitVideoStandalone(); + if (Static != null) + { + Console.WriteLine("WARNING: CEC client static already exists"); + } + else + { + Static = this; + } + + //Console.WriteLine("CEC Parser created - libCEC version " + Lib.VersionToString(Config.ServerVersion)); - Console.WriteLine("CEC Parser created - libCEC version " + Config.ServerVersion); + Console.WriteLine("INFO: CEC Parser created - libCEC version " + Config.ServerVersion); } @@ -114,7 +129,7 @@ Close(); //Try reconnect - Connect(1000); + Open(1000); return 1; } @@ -203,13 +218,13 @@ /// /// /// - public bool Connect(int timeout) + public bool Open(int timeout) { Close(); CecAdapter[] adapters = iLib.FindAdapters(string.Empty); if (adapters.Length > 0) { - Connect(adapters[0].ComPort, timeout); + Open(adapters[0].ComPort, timeout); } else { @@ -219,15 +234,10 @@ return iConnected; } - public bool Connect(string port, int timeout) + public bool Open(string port, int timeout) { Close(); iConnected = iLib.Open(port, timeout); - if (iConnected) - { - Scan(); - //TestSendKey(); - } return iConnected; } @@ -504,7 +514,7 @@ iLib.Close(); Console.WriteLine("opening a new connection"); - Connect(10000); + Open(10000); Console.WriteLine("setting active source"); iLib.SetActiveSource(CecDeviceType.PlaybackDevice); diff -r 77092f415c7c -r 4961ede27e0a Server/ConsumerElectronicControl.cs --- a/Server/ConsumerElectronicControl.cs Sun Jul 24 14:22:56 2016 +0200 +++ b/Server/ConsumerElectronicControl.cs Sun Jul 24 20:36:07 2016 +0200 @@ -85,7 +85,7 @@ private void ConnectCecClient() { //Our client takes care of closing before trying to connect - if (!Client.Connect(1000)) + if (!Client.Open(1000)) { Debug.WriteLine("WARNING: No CEC connection!"); } diff -r 77092f415c7c -r 4961ede27e0a Server/FormEditAction.cs --- a/Server/FormEditAction.cs Sun Jul 24 14:22:56 2016 +0200 +++ b/Server/FormEditAction.cs Sun Jul 24 20:36:07 2016 +0200 @@ -11,6 +11,31 @@ namespace SharpDisplayManager { + /// + /// Used to populate our action type combobox with friendly names + /// + class ItemActionType + { + public Type Type; + + public ItemActionType(Type type) + { + this.Type = type; + } + + public override string ToString() + { + //Get friendly action name from action attribute. + //That we then show up in our combobox + return SharpLib.Utils.Reflection.GetAttribute(Type).Name; + } + } + + + + /// + /// Action edit dialog form. + /// public partial class FormEditAction : Form { public SharpLib.Ear.Action Action = null; @@ -25,8 +50,8 @@ //Populate registered actions foreach (string key in ManagerEventAction.Current.ActionTypes.Keys) { - Type t = ManagerEventAction.Current.ActionTypes[key]; - comboBoxActionType.Items.Add(t); + ItemActionType item = new ItemActionType(ManagerEventAction.Current.ActionTypes[key]); + comboBoxActionType.Items.Add(item); } comboBoxActionType.SelectedIndex = 0; @@ -34,7 +59,7 @@ private void buttonOk_Click(object sender, EventArgs e) { - Action = (SharpLib.Ear.Action)Activator.CreateInstance((Type)comboBoxActionType.SelectedItem); + Action = (SharpLib.Ear.Action)Activator.CreateInstance(((ItemActionType)comboBoxActionType.SelectedItem).Type); } private void FormEditAction_Validating(object sender, CancelEventArgs e) diff -r 77092f415c7c -r 4961ede27e0a Server/MainForm.Designer.cs --- a/Server/MainForm.Designer.cs Sun Jul 24 14:22:56 2016 +0200 +++ b/Server/MainForm.Designer.cs Sun Jul 24 20:36:07 2016 +0200 @@ -1027,6 +1027,7 @@ this.buttonDeleteAction.TabIndex = 21; this.buttonDeleteAction.Text = "Delete Action"; this.buttonDeleteAction.UseVisualStyleBackColor = true; + this.buttonDeleteAction.Click += new System.EventHandler(this.buttonDeleteAction_Click); // // buttonAddAction // diff -r 77092f415c7c -r 4961ede27e0a Server/MainForm.cs --- a/Server/MainForm.cs Sun Jul 24 14:22:56 2016 +0200 +++ b/Server/MainForm.cs Sun Jul 24 20:36:07 2016 +0200 @@ -315,12 +315,16 @@ eventNode.Nodes.Add(key + ".Description", e.Description); TreeNode actionsNodes = eventNode.Nodes.Add(key + ".Actions", "Actions"); + // Add our actions for that event foreach (SharpLib.Ear.Action a in e.Actions) { - actionsNodes.Nodes.Add(a.Name); + TreeNode actionNode = actionsNodes.Nodes.Add(a.Name); + actionNode.Tag = a; } } + iTreeViewEvents.ExpandAll(); + } /// @@ -2666,7 +2670,8 @@ private void buttonAddAction_Click(object sender, EventArgs e) { - if (iTreeViewEvents.SelectedNode==null) + if (iTreeViewEvents.SelectedNode==null + || !(iTreeViewEvents.SelectedNode.Tag is Event)) { return; } @@ -2688,5 +2693,26 @@ SetupEvents(); } } + + private void buttonDeleteAction_Click(object sender, EventArgs e) + { + if (iTreeViewEvents.SelectedNode == null + || !(iTreeViewEvents.SelectedNode.Tag is SharpLib.Ear.Action)) + { + return; + } + + SharpLib.Ear.Action action = (SharpLib.Ear.Action)iTreeViewEvents.SelectedNode.Tag; + if (action == null) + { + //Must select action node + return; + } + + ManagerEventAction.Current.RemoveAction(action); + Properties.Settings.Default.Actions = ManagerEventAction.Current; + Properties.Settings.Default.Save(); + SetupEvents(); + } } } diff -r 77092f415c7c -r 4961ede27e0a Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Sun Jul 24 14:22:56 2016 +0200 +++ b/Server/SharpDisplayManager.csproj Sun Jul 24 20:36:07 2016 +0200 @@ -153,13 +153,20 @@ + + + + + + + + + - - Form - + FormEditAction.cs diff -r 77092f415c7c -r 4961ede27e0a SharpLibEar/ManagerEventAction.cs --- a/SharpLibEar/ManagerEventAction.cs Sun Jul 24 14:22:56 2016 +0200 +++ b/SharpLibEar/ManagerEventAction.cs Sun Jul 24 20:36:07 2016 +0200 @@ -38,8 +38,7 @@ Events = Utils.Reflection.GetConcreteClassesInstanceDerivedFromByName(); if (ActionsByEvents == null) - { - + { ActionsByEvents = new Dictionary>(); } @@ -61,10 +60,33 @@ } } + /// + /// Get and event instance from its type. + /// + /// + /// public Event GetEvent() where T : class { return Events[typeof(T).Name]; } + /// + /// + /// + /// + public void RemoveAction(Action aAction) + { + foreach (string key in Events.Keys) + { + Event e = Events[key]; + if (e.Actions.Remove(aAction)) + { + //We removed our action, we are done here. + return; + } + + } + } + } } \ No newline at end of file