Adding HID consumer control event.
authorStephaneLenclud
Wed, 17 Aug 2016 16:39:36 +0200
changeset 2371a1c2ae3a29c
parent 236 6ba20e02d04f
child 238 c92587ddabcd
Adding HID consumer control event.
Server/Events/EventHidConsumerControl.cs
Server/Events/EventHidWindowsMediaCenter.cs
Server/FormMain.Hid.cs
Server/FormMain.cs
Server/SharpDisplayManager.csproj
SharpLibEar/Event.cs
SharpLibEar/Manager.cs
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Server/Events/EventHidConsumerControl.cs	Wed Aug 17 16:39:36 2016 +0200
     1.3 @@ -0,0 +1,51 @@
     1.4 +´╗┐using System;
     1.5 +using System.Collections.Generic;
     1.6 +using System.Linq;
     1.7 +using System.Text;
     1.8 +using System.Threading.Tasks;
     1.9 +using System.Runtime.Serialization;
    1.10 +using Ear = SharpLib.Ear;
    1.11 +using Hid = SharpLib.Hid;
    1.12 +
    1.13 +namespace SharpDisplayManager
    1.14 +{
    1.15 +        [DataContract]
    1.16 +        [Ear.AttributeObject(Id = "Event.Hid.ConsumerControl", Name = "HID Consumer Control", Description = "Corresponding HID message received.")]
    1.17 +        public class EventHidConsumerControl : Ear.Event
    1.18 +        {
    1.19 +            public EventHidConsumerControl()
    1.20 +            {
    1.21 +            }
    1.22 +
    1.23 +        [DataMember]
    1.24 +        [Ear.AttributeObjectProperty
    1.25 +            (
    1.26 +            Id = "HID.ConsumerControl.Usage",
    1.27 +            Name = "Usage",
    1.28 +            Description = "The usage corresponding to your remote button."
    1.29 +            )]
    1.30 +        public Hid.Usage.ConsumerControl Usage { get; set; }
    1.31 +
    1.32 +        /// <summary>
    1.33 +        /// Make sure we distinguish between various configuration of this event 
    1.34 +        /// </summary>
    1.35 +        /// <returns></returns>
    1.36 +        public override string Brief()
    1.37 +        {
    1.38 +            return Name + ": " + Usage.ToString();
    1.39 +        }
    1.40 +
    1.41 +        /// <summary>
    1.42 +        ///
    1.43 +        /// </summary>
    1.44 +        /// <param name="obj"></param>
    1.45 +        /// <returns></returns>
    1.46 +        public override bool Equals(object obj)
    1.47 +        {
    1.48 +            EventHidConsumerControl e = (EventHidConsumerControl) obj;
    1.49 +            bool res = (e != null && e.Usage == Usage);
    1.50 +            return res;
    1.51 +        }
    1.52 +
    1.53 +    }
    1.54 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Server/Events/EventHidWindowsMediaCenter.cs	Wed Aug 17 16:39:36 2016 +0200
     2.3 @@ -0,0 +1,12 @@
     2.4 +´╗┐using System;
     2.5 +using System.Collections.Generic;
     2.6 +using System.Linq;
     2.7 +using System.Text;
     2.8 +using System.Threading.Tasks;
     2.9 +
    2.10 +namespace SharpDisplayManager.Events
    2.11 +{
    2.12 +    class EventHidWindowsMediaCenter
    2.13 +    {
    2.14 +    }
    2.15 +}
     3.1 --- a/Server/FormMain.Hid.cs	Wed Aug 17 13:41:26 2016 +0200
     3.2 +++ b/Server/FormMain.Hid.cs	Wed Aug 17 16:39:36 2016 +0200
     3.3 @@ -138,11 +138,18 @@
     3.4                              break;
     3.5                      }
     3.6                  }
     3.7 +                else if (aHidEvent.UsagePage == (ushort)Hid.UsagePage.Consumer)
     3.8 +                {
     3.9 +                    //Keep this for debug when only ThinkPad keyboard is available
    3.10 +                    //if (aHidEvent.Usages[0] == (ushort)Hid.Usage.ConsumerControl.ThinkPadFullscreenMagnifier)
    3.11 +                    //{
    3.12 +                    //    HandleEject();
    3.13 +                    //}
    3.14  
    3.15 -                //Keep this for debug when only ThinkPad keyboard is available
    3.16 -                if (aHidEvent.UsagePage == (ushort)Hid.UsagePage.Consumer && aHidEvent.Usages[0] == (ushort)Hid.Usage.ConsumerControl.ThinkPadFullscreenMagnifier)
    3.17 -                {
    3.18 -                    HandleEject();
    3.19 +                    EventHidConsumerControl e = new EventHidConsumerControl {Usage = (Hid.Usage.ConsumerControl)aHidEvent.Usages[0]};
    3.20 +                    Properties.Settings.Default.EarManager.TriggerEvent(e);
    3.21 +
    3.22 +
    3.23                  }
    3.24  
    3.25              }
     4.1 --- a/Server/FormMain.cs	Wed Aug 17 13:41:26 2016 +0200
     4.2 +++ b/Server/FormMain.cs	Wed Aug 17 16:39:36 2016 +0200
     4.3 @@ -331,7 +331,7 @@
     4.4              foreach (Ear.Event e in Properties.Settings.Default.EarManager.Events)
     4.5              {
     4.6                  //Create our event node
     4.7 -                TreeNode eventNode = iTreeViewEvents.Nodes.Add(e.Name);
     4.8 +                TreeNode eventNode = iTreeViewEvents.Nodes.Add(e.Brief());
     4.9                  eventNode.Tag = e; //For easy access to our event
    4.10                  if (!e.Enabled)
    4.11                  {
     5.1 --- a/Server/SharpDisplayManager.csproj	Wed Aug 17 13:41:26 2016 +0200
     5.2 +++ b/Server/SharpDisplayManager.csproj	Wed Aug 17 16:39:36 2016 +0200
     5.3 @@ -179,6 +179,8 @@
     5.4      <Compile Include="ConsumerElectronicControl.cs" />
     5.5      <Compile Include="ClientData.cs" />
     5.6      <Compile Include="EarManager.cs" />
     5.7 +    <Compile Include="Events\EventHidConsumerControl.cs" />
     5.8 +    <Compile Include="Events\EventHidWindowsMediaCenter.cs" />
     5.9      <Compile Include="FormEditObject.cs">
    5.10        <SubType>Form</SubType>
    5.11      </Compile>
     6.1 --- a/SharpLibEar/Event.cs	Wed Aug 17 13:41:26 2016 +0200
     6.2 +++ b/SharpLibEar/Event.cs	Wed Aug 17 16:39:36 2016 +0200
     6.3 @@ -38,6 +38,10 @@
     6.4              private set { }
     6.5          }
     6.6  
     6.7 +        public virtual string Brief()
     6.8 +        {
     6.9 +            return Name;
    6.10 +        }
    6.11  
    6.12          protected Event()
    6.13          {
    6.14 @@ -72,6 +76,14 @@
    6.15          {
    6.16              return SharpLib.Utils.Reflection.GetDerivedTypes<Event>();
    6.17          }
    6.18 +
    6.19 +        //
    6.20 +        public override bool Equals(object obj)
    6.21 +        {
    6.22 +            //Default implementation assumes event are the same if types are the same
    6.23 +            bool res=  obj.GetType() == GetType();
    6.24 +            return res;
    6.25 +        }
    6.26      };
    6.27  
    6.28  }
    6.29 \ No newline at end of file
     7.1 --- a/SharpLibEar/Manager.cs	Wed Aug 17 13:41:26 2016 +0200
     7.2 +++ b/SharpLibEar/Manager.cs	Wed Aug 17 16:39:36 2016 +0200
     7.3 @@ -57,6 +57,19 @@
     7.4              }
     7.5          }
     7.6  
     7.7 +        /// <summary>
     7.8 +        /// Trigger the given event.
     7.9 +        /// </summary>
    7.10 +        /// <param name="aEventType"></param>
    7.11 +        public void TriggerEvent<T>(T aEvent) where T : class
    7.12 +        {
    7.13 +            //Only trigger events matching the desired type
    7.14 +            foreach (Event e in Events.Where(e => e.Equals(aEvent) && e.Enabled))
    7.15 +            {
    7.16 +                e.Trigger();
    7.17 +            }
    7.18 +        }
    7.19 +
    7.20  
    7.21          /// <summary>
    7.22          /// Remove the specified action from the event it belongs too.