Adding non functional generic EAR HID event.
authorStephaneLenclud
Fri, 19 Aug 2016 19:18:54 +0200
changeset 2442e4d2558bb21
parent 243 cc2251d065db
child 245 448e6a616c22
Adding non functional generic EAR HID event.
Server/Events/EventHid.cs
Server/FormEditObject.cs
Server/SharpDisplayManager.csproj
SharpLibEar/Object.cs
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Server/Events/EventHid.cs	Fri Aug 19 19:18:54 2016 +0200
     1.3 @@ -0,0 +1,147 @@
     1.4 +using System;
     1.5 +using System.Collections.Generic;
     1.6 +using System.Linq;
     1.7 +using System.Reflection;
     1.8 +using System.Text;
     1.9 +using System.Threading.Tasks;
    1.10 +using System.Runtime.Serialization;
    1.11 +using System.Windows.Forms;
    1.12 +using Ear = SharpLib.Ear;
    1.13 +using Hid = SharpLib.Hid;
    1.14 +
    1.15 +namespace SharpDisplayManager
    1.16 +{
    1.17 +    [DataContract]
    1.18 +    [Ear.AttributeObject(Id = "Event.Hid", Name = "HID", Description = "Corresponding HID message received.")]
    1.19 +    public class EventHid: Ear.Event
    1.20 +    {
    1.21 +        public EventHid()
    1.22 +        {
    1.23 +        }
    1.24 +
    1.25 +        [DataMember]
    1.26 +        public ushort UsagePage { get; set; }
    1.27 +
    1.28 +        [DataMember]
    1.29 +        public ushort UsageCollection { get; set; }
    1.30 +
    1.31 +        [DataMember]
    1.32 +        public ushort Usage { get; set; }
    1.33 +
    1.34 +        [DataMember]
    1.35 +        public Keys Key { get; set; }
    1.36 +
    1.37 +        [DataMember]
    1.38 +        [Ear.AttributeObjectProperty
    1.39 +            (
    1.40 +            Id = "HID.Keyboard.IsKeyUp",
    1.41 +            Name = "Key Up",
    1.42 +            Description = "Key up if set, key down otherwise."
    1.43 +            )]
    1.44 +        public bool IsKeyUp { get; set; } = false;
    1.45 +
    1.46 +        [DataMember]
    1.47 +        public bool IsMouse { get; set; }
    1.48 +
    1.49 +        [DataMember]
    1.50 +        public bool IsKeyboard { get; set; }
    1.51 +
    1.52 +        [DataMember]
    1.53 +        public bool IsGeneric { get; set; }
    1.54 +
    1.55 +        [DataMember]
    1.56 +        public bool HasModifierShift { get; set; } = false;
    1.57 +
    1.58 +        [DataMember]
    1.59 +        public bool HasModifierControl { get; set; } = false;
    1.60 +
    1.61 +        [DataMember]
    1.62 +        public bool HasModifierAlt { get; set; } = false;
    1.63 +
    1.64 +        [DataMember]
    1.65 +        public bool HasModifierWindows { get; set; } = false;
    1.66 +
    1.67 +
    1.68 +        protected override void DoConstruct()
    1.69 +        {
    1.70 +            base.DoConstruct();
    1.71 +            UpdateDynamicProperties();
    1.72 +        }
    1.73 +
    1.74 +        private void UpdateDynamicProperties()
    1.75 +        {
    1.76 +            
    1.77 +        }
    1.78 +
    1.79 +
    1.80 +        /// <summary>
    1.81 +        /// Make sure we distinguish between various configuration of this event 
    1.82 +        /// </summary>
    1.83 +        /// <returns></returns>
    1.84 +        public override string Brief()
    1.85 +        {
    1.86 +            string brief = Name + ": ";
    1.87 +
    1.88 +            if (IsKeyboard)
    1.89 +            {
    1.90 +                brief += Key.ToString();
    1.91 +
    1.92 +                if (HasModifierAlt)
    1.93 +                {
    1.94 +                    brief += " + ALT";
    1.95 +                }
    1.96 +
    1.97 +                if (HasModifierControl)
    1.98 +                {
    1.99 +                    brief += " + CTRL";
   1.100 +                }
   1.101 +
   1.102 +                if (HasModifierShift)
   1.103 +                {
   1.104 +                    brief += " + SHIFT";
   1.105 +                }
   1.106 +
   1.107 +                if (HasModifierWindows)
   1.108 +                {
   1.109 +                    brief += " + WIN";
   1.110 +                }
   1.111 +            }
   1.112 +            else if (IsGeneric)
   1.113 +            {
   1.114 +                
   1.115 +            }
   1.116 +
   1.117 +            if (IsKeyUp)
   1.118 +            {
   1.119 +                brief += " (UP)";
   1.120 +            }
   1.121 +            else
   1.122 +            {
   1.123 +                brief += " (DOWN)";
   1.124 +            }
   1.125 +
   1.126 +            return brief;
   1.127 +        }
   1.128 +
   1.129 +        /// <summary>
   1.130 +        ///
   1.131 +        /// </summary>
   1.132 +        /// <param name="obj"></param>
   1.133 +        /// <returns></returns>
   1.134 +        public override bool Equals(object obj)
   1.135 +        {
   1.136 +            if (obj is EventHidKeyboard)
   1.137 +            {
   1.138 +                EventHidKeyboard e = (EventHidKeyboard)obj;
   1.139 +                return e.Key == Key
   1.140 +                        && e.IsKeyUp == IsKeyUp
   1.141 +                        && e.HasModifierAlt == HasModifierAlt
   1.142 +                        && e.HasModifierControl == HasModifierControl
   1.143 +                        && e.HasModifierShift == HasModifierShift
   1.144 +                        && e.HasModifierWindows == HasModifierWindows;
   1.145 +            }
   1.146 +
   1.147 +            return false;
   1.148 +        }
   1.149 +    }
   1.150 +}
     2.1 --- a/Server/FormEditObject.cs	Fri Aug 19 17:12:54 2016 +0200
     2.2 +++ b/Server/FormEditObject.cs	Fri Aug 19 19:18:54 2016 +0200
     2.3 @@ -170,8 +170,10 @@
     2.4              {
     2.5                  ComboBox ctrl = (ComboBox)aControl;
     2.6                  string currentItem = ctrl.SelectedItem.ToString();
     2.7 -                PropertyComboBox pcb = (PropertyComboBox)aInfo.GetValue(aObject);
     2.8 -                pcb.CurrentItem = currentItem;
     2.9 +                PropertyComboBox value = (PropertyComboBox)aInfo.GetValue(aObject);
    2.10 +                value.CurrentItem = currentItem;
    2.11 +                //Not strictly needed but makes sure the set method is called
    2.12 +                aInfo.SetValue(aObject, value);                
    2.13              }
    2.14  
    2.15              //TODO: add support for other types here
     3.1 --- a/Server/SharpDisplayManager.csproj	Fri Aug 19 17:12:54 2016 +0200
     3.2 +++ b/Server/SharpDisplayManager.csproj	Fri Aug 19 19:18:54 2016 +0200
     3.3 @@ -179,6 +179,7 @@
     3.4      <Compile Include="ConsumerElectronicControl.cs" />
     3.5      <Compile Include="ClientData.cs" />
     3.6      <Compile Include="EarManager.cs" />
     3.7 +    <Compile Include="Events\EventHid.cs" />
     3.8      <Compile Include="Events\EventHidConsumerControl.cs" />
     3.9      <Compile Include="Events\EventHidKeyboard.cs" />
    3.10      <Compile Include="Events\EventHidWindowsMediaCenter.cs" />
     4.1 --- a/SharpLibEar/Object.cs	Fri Aug 19 17:12:54 2016 +0200
     4.2 +++ b/SharpLibEar/Object.cs	Fri Aug 19 19:18:54 2016 +0200
     4.3 @@ -8,7 +8,7 @@
     4.4  using System;
     4.5  using System.Collections.Generic;
     4.6  using System.Runtime.Serialization;
     4.7 -
     4.8 +using System.ComponentModel;
     4.9  
    4.10  namespace SharpLib.Ear
    4.11  {
    4.12 @@ -19,11 +19,11 @@
    4.13      /// </summary>
    4.14      [DataContract]
    4.15      [KnownType("DerivedTypes")]
    4.16 -    public abstract class Object: IComparable
    4.17 +    public abstract class Object: IComparable, INotifyPropertyChanged
    4.18      {
    4.19          private bool iConstructed = false;
    4.20  
    4.21 -        public Object()
    4.22 +        protected Object()
    4.23          {
    4.24              Construct();
    4.25          }
    4.26 @@ -106,5 +106,20 @@
    4.27              return SharpLib.Utils.Reflection.GetDerivedTypes<Object>();
    4.28          }
    4.29  
    4.30 +        /// <summary>
    4.31 +        /// 
    4.32 +        /// </summary>
    4.33 +        public event PropertyChangedEventHandler PropertyChanged;
    4.34 +
    4.35 +        /// <summary>
    4.36 +        /// Invoke our event.
    4.37 +        /// </summary>
    4.38 +        /// <param name="name"></param>
    4.39 +        protected void OnPropertyChanged(string name)
    4.40 +        {
    4.41 +            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
    4.42 +        }
    4.43 +
    4.44 +
    4.45      }
    4.46  }