# HG changeset patch
# User StephaneLenclud
# Date 1471444776 -7200
# Node ID 1a1c2ae3a29c7ea86f55eda3527cddfad2ca6069
# Parent 6ba20e02d04f5bce296dd1a39f92e0b0c3e1938f
Adding HID consumer control event.
diff -r 6ba20e02d04f -r 1a1c2ae3a29c Server/Events/EventHidConsumerControl.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Events/EventHidConsumerControl.cs Wed Aug 17 16:39:36 2016 +0200
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Runtime.Serialization;
+using Ear = SharpLib.Ear;
+using Hid = SharpLib.Hid;
+
+namespace SharpDisplayManager
+{
+ [DataContract]
+ [Ear.AttributeObject(Id = "Event.Hid.ConsumerControl", Name = "HID Consumer Control", Description = "Corresponding HID message received.")]
+ public class EventHidConsumerControl : Ear.Event
+ {
+ public EventHidConsumerControl()
+ {
+ }
+
+ [DataMember]
+ [Ear.AttributeObjectProperty
+ (
+ Id = "HID.ConsumerControl.Usage",
+ Name = "Usage",
+ Description = "The usage corresponding to your remote button."
+ )]
+ public Hid.Usage.ConsumerControl Usage { get; set; }
+
+ ///
+ /// Make sure we distinguish between various configuration of this event
+ ///
+ ///
+ public override string Brief()
+ {
+ return Name + ": " + Usage.ToString();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override bool Equals(object obj)
+ {
+ EventHidConsumerControl e = (EventHidConsumerControl) obj;
+ bool res = (e != null && e.Usage == Usage);
+ return res;
+ }
+
+ }
+}
diff -r 6ba20e02d04f -r 1a1c2ae3a29c Server/Events/EventHidWindowsMediaCenter.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Events/EventHidWindowsMediaCenter.cs Wed Aug 17 16:39:36 2016 +0200
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SharpDisplayManager.Events
+{
+ class EventHidWindowsMediaCenter
+ {
+ }
+}
diff -r 6ba20e02d04f -r 1a1c2ae3a29c Server/FormMain.Hid.cs
--- a/Server/FormMain.Hid.cs Wed Aug 17 13:41:26 2016 +0200
+++ b/Server/FormMain.Hid.cs Wed Aug 17 16:39:36 2016 +0200
@@ -138,11 +138,18 @@
break;
}
}
+ else if (aHidEvent.UsagePage == (ushort)Hid.UsagePage.Consumer)
+ {
+ //Keep this for debug when only ThinkPad keyboard is available
+ //if (aHidEvent.Usages[0] == (ushort)Hid.Usage.ConsumerControl.ThinkPadFullscreenMagnifier)
+ //{
+ // HandleEject();
+ //}
- //Keep this for debug when only ThinkPad keyboard is available
- if (aHidEvent.UsagePage == (ushort)Hid.UsagePage.Consumer && aHidEvent.Usages[0] == (ushort)Hid.Usage.ConsumerControl.ThinkPadFullscreenMagnifier)
- {
- HandleEject();
+ EventHidConsumerControl e = new EventHidConsumerControl {Usage = (Hid.Usage.ConsumerControl)aHidEvent.Usages[0]};
+ Properties.Settings.Default.EarManager.TriggerEvent(e);
+
+
}
}
diff -r 6ba20e02d04f -r 1a1c2ae3a29c Server/FormMain.cs
--- a/Server/FormMain.cs Wed Aug 17 13:41:26 2016 +0200
+++ b/Server/FormMain.cs Wed Aug 17 16:39:36 2016 +0200
@@ -331,7 +331,7 @@
foreach (Ear.Event e in Properties.Settings.Default.EarManager.Events)
{
//Create our event node
- TreeNode eventNode = iTreeViewEvents.Nodes.Add(e.Name);
+ TreeNode eventNode = iTreeViewEvents.Nodes.Add(e.Brief());
eventNode.Tag = e; //For easy access to our event
if (!e.Enabled)
{
diff -r 6ba20e02d04f -r 1a1c2ae3a29c Server/SharpDisplayManager.csproj
--- a/Server/SharpDisplayManager.csproj Wed Aug 17 13:41:26 2016 +0200
+++ b/Server/SharpDisplayManager.csproj Wed Aug 17 16:39:36 2016 +0200
@@ -179,6 +179,8 @@
+
+
Form
diff -r 6ba20e02d04f -r 1a1c2ae3a29c SharpLibEar/Event.cs
--- a/SharpLibEar/Event.cs Wed Aug 17 13:41:26 2016 +0200
+++ b/SharpLibEar/Event.cs Wed Aug 17 16:39:36 2016 +0200
@@ -38,6 +38,10 @@
private set { }
}
+ public virtual string Brief()
+ {
+ return Name;
+ }
protected Event()
{
@@ -72,6 +76,14 @@
{
return SharpLib.Utils.Reflection.GetDerivedTypes();
}
+
+ //
+ public override bool Equals(object obj)
+ {
+ //Default implementation assumes event are the same if types are the same
+ bool res= obj.GetType() == GetType();
+ return res;
+ }
};
}
\ No newline at end of file
diff -r 6ba20e02d04f -r 1a1c2ae3a29c SharpLibEar/Manager.cs
--- a/SharpLibEar/Manager.cs Wed Aug 17 13:41:26 2016 +0200
+++ b/SharpLibEar/Manager.cs Wed Aug 17 16:39:36 2016 +0200
@@ -57,6 +57,19 @@
}
}
+ ///
+ /// Trigger the given event.
+ ///
+ ///
+ public void TriggerEvent(T aEvent) where T : class
+ {
+ //Only trigger events matching the desired type
+ foreach (Event e in Events.Where(e => e.Equals(aEvent) && e.Enabled))
+ {
+ e.Trigger();
+ }
+ }
+
///
/// Remove the specified action from the event it belongs too.