Adding a bunch of CEC actions.
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Server/Actions/ActionCecActiveSource.cs Sun Jul 24 20:36:07 2016 +0200
1.3 @@ -0,0 +1,26 @@
1.4 +using CecSharp;
1.5 +using SharpLib.Ear;
1.6 +using System;
1.7 +using System.Collections.Generic;
1.8 +using System.Linq;
1.9 +using System.Runtime.Serialization;
1.10 +using System.Text;
1.11 +using System.Threading.Tasks;
1.12 +
1.13 +namespace SharpDisplayManager
1.14 +{
1.15 + [DataContract]
1.16 + [AttributeAction(Id = "Cec.ActiveSource", Name = "CEC Active Source", Description = "Set this CEC device as active source.")]
1.17 + class ActionCecActiveSource : SharpLib.Ear.Action
1.18 + {
1.19 + public override void Execute()
1.20 + {
1.21 + if (Cec.Client.Static == null)
1.22 + {
1.23 + Console.WriteLine("WARNING: No CEC client installed.");
1.24 + }
1.25 +
1.26 + Cec.Client.Static.Lib.SetActiveSource(CecDeviceType.PlaybackDevice);
1.27 + }
1.28 + }
1.29 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/Server/Actions/ActionCecClose.cs Sun Jul 24 20:36:07 2016 +0200
2.3 @@ -0,0 +1,26 @@
2.4 +using CecSharp;
2.5 +using SharpLib.Ear;
2.6 +using System;
2.7 +using System.Collections.Generic;
2.8 +using System.Linq;
2.9 +using System.Runtime.Serialization;
2.10 +using System.Text;
2.11 +using System.Threading.Tasks;
2.12 +
2.13 +namespace SharpDisplayManager
2.14 +{
2.15 + [DataContract]
2.16 + [AttributeAction(Id = "Cec.Close", Name = "CEC Close", Description = "Close CEC connection.")]
2.17 + class ActionCecClose : SharpLib.Ear.Action
2.18 + {
2.19 + public override void Execute()
2.20 + {
2.21 + if (Cec.Client.Static == null)
2.22 + {
2.23 + Console.WriteLine("WARNING: No CEC client installed.");
2.24 + }
2.25 +
2.26 + Cec.Client.Static.Close();
2.27 + }
2.28 + }
2.29 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/Server/Actions/ActionCecInactiveSource.cs Sun Jul 24 20:36:07 2016 +0200
3.3 @@ -0,0 +1,26 @@
3.4 +using CecSharp;
3.5 +using SharpLib.Ear;
3.6 +using System;
3.7 +using System.Collections.Generic;
3.8 +using System.Linq;
3.9 +using System.Runtime.Serialization;
3.10 +using System.Text;
3.11 +using System.Threading.Tasks;
3.12 +
3.13 +namespace SharpDisplayManager
3.14 +{
3.15 + [DataContract]
3.16 + [AttributeAction(Id = "Cec.InactiveSource", Name = "CEC Inactive Source", Description = "Set this CEC device as inactive source.")]
3.17 + class ActionCecInactiveSource : SharpLib.Ear.Action
3.18 + {
3.19 + public override void Execute()
3.20 + {
3.21 + if (Cec.Client.Static == null)
3.22 + {
3.23 + Console.WriteLine("WARNING: No CEC client installed.");
3.24 + }
3.25 +
3.26 + Cec.Client.Static.Lib.SetInactiveView();
3.27 + }
3.28 + }
3.29 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/Server/Actions/ActionCecOpen.cs Sun Jul 24 20:36:07 2016 +0200
4.3 @@ -0,0 +1,26 @@
4.4 +using CecSharp;
4.5 +using SharpLib.Ear;
4.6 +using System;
4.7 +using System.Collections.Generic;
4.8 +using System.Linq;
4.9 +using System.Runtime.Serialization;
4.10 +using System.Text;
4.11 +using System.Threading.Tasks;
4.12 +
4.13 +namespace SharpDisplayManager
4.14 +{
4.15 + [DataContract]
4.16 + [AttributeAction(Id = "Cec.Open", Name = "CEC Open", Description = "Open CEC connection.")]
4.17 + class ActionCecOpen : SharpLib.Ear.Action
4.18 + {
4.19 + public override void Execute()
4.20 + {
4.21 + if (Cec.Client.Static == null)
4.22 + {
4.23 + Console.WriteLine("WARNING: No CEC client installed.");
4.24 + }
4.25 +
4.26 + Cec.Client.Static.Open(1000);
4.27 + }
4.28 + }
4.29 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/Server/Actions/ActionCecPowerOnTv.cs Sun Jul 24 20:36:07 2016 +0200
5.3 @@ -0,0 +1,26 @@
5.4 +using CecSharp;
5.5 +using SharpLib.Ear;
5.6 +using System;
5.7 +using System.Collections.Generic;
5.8 +using System.Linq;
5.9 +using System.Runtime.Serialization;
5.10 +using System.Text;
5.11 +using System.Threading.Tasks;
5.12 +
5.13 +namespace SharpDisplayManager
5.14 +{
5.15 + [DataContract]
5.16 + [AttributeAction(Id = "Cec.PowerOnTv", Name = "CEC Power On TV", Description = "Power on TVs on your CEC HDMI network.")]
5.17 + class ActionCecPowerOnTv : SharpLib.Ear.Action
5.18 + {
5.19 + public override void Execute()
5.20 + {
5.21 + if (Cec.Client.Static == null)
5.22 + {
5.23 + Console.WriteLine("WARNING: No CEC client installed.");
5.24 + }
5.25 +
5.26 + Cec.Client.Static.Lib.PowerOnDevices(CecLogicalAddress.Tv);
5.27 + }
5.28 + }
5.29 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/Server/Actions/ActionCecScan.cs Sun Jul 24 20:36:07 2016 +0200
6.3 @@ -0,0 +1,27 @@
6.4 +using CecSharp;
6.5 +using SharpLib.Ear;
6.6 +using System;
6.7 +using System.Collections.Generic;
6.8 +using System.Linq;
6.9 +using System.Runtime.Serialization;
6.10 +using System.Text;
6.11 +using System.Threading.Tasks;
6.12 +
6.13 +namespace SharpDisplayManager
6.14 +{
6.15 +
6.16 + [DataContract]
6.17 + [AttributeAction(Id = "Cec.Scan", Name = "CEC Scan", Description = "Scan devices on your CEC HDMI network.")]
6.18 + class ActionCecScan : SharpLib.Ear.Action
6.19 + {
6.20 + public override void Execute()
6.21 + {
6.22 + if (Cec.Client.Static == null)
6.23 + {
6.24 + Console.WriteLine("WARNING: No CEC client installed.");
6.25 + }
6.26 +
6.27 + Cec.Client.Static.Scan();
6.28 + }
6.29 + }
6.30 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/Server/Actions/ActionCecSendKeypressTvPowerOff.cs Sun Jul 24 20:36:07 2016 +0200
7.3 @@ -0,0 +1,27 @@
7.4 +
7.5 +using CecSharp;
7.6 +using SharpLib.Ear;
7.7 +using System;
7.8 +using System.Collections.Generic;
7.9 +using System.Linq;
7.10 +using System.Runtime.Serialization;
7.11 +using System.Text;
7.12 +using System.Threading.Tasks;
7.13 +
7.14 +namespace SharpDisplayManager
7.15 +{
7.16 + [DataContract]
7.17 + [AttributeAction(Id = "Cec.SendKepressTvPowerOff", Name = "CEC Send Keypress TV Power Off", Description = "Send Power Off keypress to your TV.")]
7.18 + class ActionCecSendKeypressTvPowerOff : SharpLib.Ear.Action
7.19 + {
7.20 + public override void Execute()
7.21 + {
7.22 + if (Cec.Client.Static == null)
7.23 + {
7.24 + Console.WriteLine("WARNING: No CEC client installed.");
7.25 + }
7.26 +
7.27 + Cec.Client.Static.Lib.SendKeypress(CecLogicalAddress.Tv,CecUserControlCode.PowerOffFunction,true);
7.28 + }
7.29 + }
7.30 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/Server/Actions/ActionCecSendKeypressTvPowerOn.cs Sun Jul 24 20:36:07 2016 +0200
8.3 @@ -0,0 +1,27 @@
8.4 +
8.5 +using CecSharp;
8.6 +using SharpLib.Ear;
8.7 +using System;
8.8 +using System.Collections.Generic;
8.9 +using System.Linq;
8.10 +using System.Runtime.Serialization;
8.11 +using System.Text;
8.12 +using System.Threading.Tasks;
8.13 +
8.14 +namespace SharpDisplayManager
8.15 +{
8.16 + [DataContract]
8.17 + [AttributeAction(Id = "Cec.SendKepressTvPowerOn", Name = "CEC Send Keypress TV Power On", Description = "Send Power On keypress to your TV.")]
8.18 + class ActionCecSendKeypressTvPowerOn : SharpLib.Ear.Action
8.19 + {
8.20 + public override void Execute()
8.21 + {
8.22 + if (Cec.Client.Static == null)
8.23 + {
8.24 + Console.WriteLine("WARNING: No CEC client installed.");
8.25 + }
8.26 +
8.27 + Cec.Client.Static.Lib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.PowerOnFunction, true);
8.28 + }
8.29 + }
8.30 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/Server/Actions/ActionCecStandbyTv.cs Sun Jul 24 20:36:07 2016 +0200
9.3 @@ -0,0 +1,26 @@
9.4 +using CecSharp;
9.5 +using SharpLib.Ear;
9.6 +using System;
9.7 +using System.Collections.Generic;
9.8 +using System.Linq;
9.9 +using System.Runtime.Serialization;
9.10 +using System.Text;
9.11 +using System.Threading.Tasks;
9.12 +
9.13 +namespace SharpDisplayManager
9.14 +{
9.15 + [DataContract]
9.16 + [AttributeAction(Id = "Cec.StandbyTv", Name = "CEC Standby TV", Description = "Standby TVs on your CEC HDMI network.")]
9.17 + class ActionCecStandbyTv : SharpLib.Ear.Action
9.18 + {
9.19 + public override void Execute()
9.20 + {
9.21 + if (Cec.Client.Static == null)
9.22 + {
9.23 + Console.WriteLine("WARNING: No CEC client installed.");
9.24 + }
9.25 +
9.26 + Cec.Client.Static.Lib.StandbyDevices(CecLogicalAddress.Tv);
9.27 + }
9.28 + }
9.29 +}
10.1 --- a/Server/CecClient.cs Sun Jul 24 14:22:56 2016 +0200
10.2 +++ b/Server/CecClient.cs Sun Jul 24 20:36:07 2016 +0200
10.3 @@ -40,6 +40,11 @@
10.4 class Client : CecCallbackMethods
10.5 {
10.6 /// <summary>
10.7 + /// Enable public static access
10.8 + /// </summary>
10.9 + public static Client Static;
10.10 +
10.11 + /// <summary>
10.12 /// Provide direct access to CEC library
10.13 /// </summary>
10.14 public LibCecSharp Lib
10.15 @@ -91,8 +96,18 @@
10.16 iLib = new LibCecSharp(Config);
10.17 iLib.InitVideoStandalone();
10.18
10.19 + if (Static != null)
10.20 + {
10.21 + Console.WriteLine("WARNING: CEC client static already exists");
10.22 + }
10.23 + else
10.24 + {
10.25 + Static = this;
10.26 + }
10.27 +
10.28 +
10.29 //Console.WriteLine("CEC Parser created - libCEC version " + Lib.VersionToString(Config.ServerVersion));
10.30 - Console.WriteLine("CEC Parser created - libCEC version " + Config.ServerVersion);
10.31 + Console.WriteLine("INFO: CEC Parser created - libCEC version " + Config.ServerVersion);
10.32 }
10.33
10.34
10.35 @@ -114,7 +129,7 @@
10.36
10.37 Close();
10.38 //Try reconnect
10.39 - Connect(1000);
10.40 + Open(1000);
10.41 return 1;
10.42 }
10.43
10.44 @@ -203,13 +218,13 @@
10.45 /// </summary>
10.46 /// <param name="timeout"></param>
10.47 /// <returns></returns>
10.48 - public bool Connect(int timeout)
10.49 + public bool Open(int timeout)
10.50 {
10.51 Close();
10.52 CecAdapter[] adapters = iLib.FindAdapters(string.Empty);
10.53 if (adapters.Length > 0)
10.54 {
10.55 - Connect(adapters[0].ComPort, timeout);
10.56 + Open(adapters[0].ComPort, timeout);
10.57 }
10.58 else
10.59 {
10.60 @@ -219,15 +234,10 @@
10.61 return iConnected;
10.62 }
10.63
10.64 - public bool Connect(string port, int timeout)
10.65 + public bool Open(string port, int timeout)
10.66 {
10.67 Close();
10.68 iConnected = iLib.Open(port, timeout);
10.69 - if (iConnected)
10.70 - {
10.71 - Scan();
10.72 - //TestSendKey();
10.73 - }
10.74 return iConnected;
10.75 }
10.76
10.77 @@ -504,7 +514,7 @@
10.78 iLib.Close();
10.79
10.80 Console.WriteLine("opening a new connection");
10.81 - Connect(10000);
10.82 + Open(10000);
10.83
10.84 Console.WriteLine("setting active source");
10.85 iLib.SetActiveSource(CecDeviceType.PlaybackDevice);
11.1 --- a/Server/ConsumerElectronicControl.cs Sun Jul 24 14:22:56 2016 +0200
11.2 +++ b/Server/ConsumerElectronicControl.cs Sun Jul 24 20:36:07 2016 +0200
11.3 @@ -85,7 +85,7 @@
11.4 private void ConnectCecClient()
11.5 {
11.6 //Our client takes care of closing before trying to connect
11.7 - if (!Client.Connect(1000))
11.8 + if (!Client.Open(1000))
11.9 {
11.10 Debug.WriteLine("WARNING: No CEC connection!");
11.11 }
12.1 --- a/Server/FormEditAction.cs Sun Jul 24 14:22:56 2016 +0200
12.2 +++ b/Server/FormEditAction.cs Sun Jul 24 20:36:07 2016 +0200
12.3 @@ -11,6 +11,31 @@
12.4
12.5 namespace SharpDisplayManager
12.6 {
12.7 + /// <summary>
12.8 + /// Used to populate our action type combobox with friendly names
12.9 + /// </summary>
12.10 + class ItemActionType
12.11 + {
12.12 + public Type Type;
12.13 +
12.14 + public ItemActionType(Type type)
12.15 + {
12.16 + this.Type = type;
12.17 + }
12.18 +
12.19 + public override string ToString()
12.20 + {
12.21 + //Get friendly action name from action attribute.
12.22 + //That we then show up in our combobox
12.23 + return SharpLib.Utils.Reflection.GetAttribute<AttributeAction>(Type).Name;
12.24 + }
12.25 + }
12.26 +
12.27 +
12.28 +
12.29 + /// <summary>
12.30 + /// Action edit dialog form.
12.31 + /// </summary>
12.32 public partial class FormEditAction : Form
12.33 {
12.34 public SharpLib.Ear.Action Action = null;
12.35 @@ -25,8 +50,8 @@
12.36 //Populate registered actions
12.37 foreach (string key in ManagerEventAction.Current.ActionTypes.Keys)
12.38 {
12.39 - Type t = ManagerEventAction.Current.ActionTypes[key];
12.40 - comboBoxActionType.Items.Add(t);
12.41 + ItemActionType item = new ItemActionType(ManagerEventAction.Current.ActionTypes[key]);
12.42 + comboBoxActionType.Items.Add(item);
12.43 }
12.44
12.45 comboBoxActionType.SelectedIndex = 0;
12.46 @@ -34,7 +59,7 @@
12.47
12.48 private void buttonOk_Click(object sender, EventArgs e)
12.49 {
12.50 - Action = (SharpLib.Ear.Action)Activator.CreateInstance((Type)comboBoxActionType.SelectedItem);
12.51 + Action = (SharpLib.Ear.Action)Activator.CreateInstance(((ItemActionType)comboBoxActionType.SelectedItem).Type);
12.52 }
12.53
12.54 private void FormEditAction_Validating(object sender, CancelEventArgs e)
13.1 --- a/Server/MainForm.Designer.cs Sun Jul 24 14:22:56 2016 +0200
13.2 +++ b/Server/MainForm.Designer.cs Sun Jul 24 20:36:07 2016 +0200
13.3 @@ -1027,6 +1027,7 @@
13.4 this.buttonDeleteAction.TabIndex = 21;
13.5 this.buttonDeleteAction.Text = "Delete Action";
13.6 this.buttonDeleteAction.UseVisualStyleBackColor = true;
13.7 + this.buttonDeleteAction.Click += new System.EventHandler(this.buttonDeleteAction_Click);
13.8 //
13.9 // buttonAddAction
13.10 //
14.1 --- a/Server/MainForm.cs Sun Jul 24 14:22:56 2016 +0200
14.2 +++ b/Server/MainForm.cs Sun Jul 24 20:36:07 2016 +0200
14.3 @@ -315,12 +315,16 @@
14.4 eventNode.Nodes.Add(key + ".Description", e.Description);
14.5 TreeNode actionsNodes = eventNode.Nodes.Add(key + ".Actions", "Actions");
14.6
14.7 + // Add our actions for that event
14.8 foreach (SharpLib.Ear.Action a in e.Actions)
14.9 {
14.10 - actionsNodes.Nodes.Add(a.Name);
14.11 + TreeNode actionNode = actionsNodes.Nodes.Add(a.Name);
14.12 + actionNode.Tag = a;
14.13 }
14.14 }
14.15
14.16 + iTreeViewEvents.ExpandAll();
14.17 +
14.18 }
14.19
14.20 /// <summary>
14.21 @@ -2666,7 +2670,8 @@
14.22
14.23 private void buttonAddAction_Click(object sender, EventArgs e)
14.24 {
14.25 - if (iTreeViewEvents.SelectedNode==null)
14.26 + if (iTreeViewEvents.SelectedNode==null
14.27 + || !(iTreeViewEvents.SelectedNode.Tag is Event))
14.28 {
14.29 return;
14.30 }
14.31 @@ -2688,5 +2693,26 @@
14.32 SetupEvents();
14.33 }
14.34 }
14.35 +
14.36 + private void buttonDeleteAction_Click(object sender, EventArgs e)
14.37 + {
14.38 + if (iTreeViewEvents.SelectedNode == null
14.39 + || !(iTreeViewEvents.SelectedNode.Tag is SharpLib.Ear.Action))
14.40 + {
14.41 + return;
14.42 + }
14.43 +
14.44 + SharpLib.Ear.Action action = (SharpLib.Ear.Action)iTreeViewEvents.SelectedNode.Tag;
14.45 + if (action == null)
14.46 + {
14.47 + //Must select action node
14.48 + return;
14.49 + }
14.50 +
14.51 + ManagerEventAction.Current.RemoveAction(action);
14.52 + Properties.Settings.Default.Actions = ManagerEventAction.Current;
14.53 + Properties.Settings.Default.Save();
14.54 + SetupEvents();
14.55 + }
14.56 }
14.57 }
15.1 --- a/Server/SharpDisplayManager.csproj Sun Jul 24 14:22:56 2016 +0200
15.2 +++ b/Server/SharpDisplayManager.csproj Sun Jul 24 20:36:07 2016 +0200
15.3 @@ -153,13 +153,20 @@
15.4 <Reference Include="System.Xml.Serialization" />
15.5 </ItemGroup>
15.6 <ItemGroup>
15.7 + <Compile Include="Actions\ActionCecClose.cs" />
15.8 + <Compile Include="Actions\ActionCecInactiveSource.cs" />
15.9 + <Compile Include="Actions\ActionCecOpen.cs" />
15.10 + <Compile Include="Actions\ActionCecPowerOnTv.cs" />
15.11 + <Compile Include="Actions\ActionCecActiveSource.cs" />
15.12 + <Compile Include="Actions\ActionCecScan.cs" />
15.13 + <Compile Include="Actions\ActionCecSendKeypressTvPowerOff.cs" />
15.14 + <Compile Include="Actions\ActionCecStandbyTv.cs" />
15.15 + <Compile Include="Actions\ActionCecSendKeypressTvPowerOn.cs" />
15.16 <Compile Include="CbtHook.cs" />
15.17 <Compile Include="CecClient.cs" />
15.18 <Compile Include="ConsumerElectronicControl.cs" />
15.19 <Compile Include="ClientData.cs" />
15.20 - <Compile Include="FormEditAction.cs">
15.21 - <SubType>Form</SubType>
15.22 - </Compile>
15.23 + <Compile Include="FormEditAction.cs" />
15.24 <Compile Include="FormEditAction.Designer.cs">
15.25 <DependentUpon>FormEditAction.cs</DependentUpon>
15.26 </Compile>
16.1 --- a/SharpLibEar/ManagerEventAction.cs Sun Jul 24 14:22:56 2016 +0200
16.2 +++ b/SharpLibEar/ManagerEventAction.cs Sun Jul 24 20:36:07 2016 +0200
16.3 @@ -38,8 +38,7 @@
16.4 Events = Utils.Reflection.GetConcreteClassesInstanceDerivedFromByName<Event>();
16.5
16.6 if (ActionsByEvents == null)
16.7 - {
16.8 -
16.9 + {
16.10 ActionsByEvents = new Dictionary<string, List<Action>>();
16.11 }
16.12
16.13 @@ -61,10 +60,33 @@
16.14 }
16.15 }
16.16
16.17 + /// <summary>
16.18 + /// Get and event instance from its type.
16.19 + /// </summary>
16.20 + /// <typeparam name="T"></typeparam>
16.21 + /// <returns></returns>
16.22 public Event GetEvent<T>() where T : class
16.23 {
16.24 return Events[typeof(T).Name];
16.25 }
16.26
16.27 + /// <summary>
16.28 + ///
16.29 + /// </summary>
16.30 + /// <param name="aAction"></param>
16.31 + public void RemoveAction(Action aAction)
16.32 + {
16.33 + foreach (string key in Events.Keys)
16.34 + {
16.35 + Event e = Events[key];
16.36 + if (e.Actions.Remove(aAction))
16.37 + {
16.38 + //We removed our action, we are done here.
16.39 + return;
16.40 + }
16.41 +
16.42 + }
16.43 + }
16.44 +
16.45 }
16.46 }
16.47 \ No newline at end of file