Server/Actions/ActionCecUserControlPressed.cs
author StephaneLenclud
Tue, 30 Aug 2016 16:50:37 +0200
changeset 260 d44943088c67
parent 258 e237c2e33545
child 264 4a08e1b7ba64
permissions -rw-r--r--
Adding user given name to EAR events and enabling User Events.
StephaneLenclud@222
     1
using CecSharp;
StephaneLenclud@222
     2
using SharpLib.Ear;
StephaneLenclud@222
     3
using System;
StephaneLenclud@222
     4
using System.Collections.Generic;
StephaneLenclud@253
     5
using System.Diagnostics;
StephaneLenclud@222
     6
using System.Linq;
StephaneLenclud@222
     7
using System.Runtime.InteropServices;
StephaneLenclud@222
     8
using System.Runtime.Serialization;
StephaneLenclud@222
     9
using System.Text;
StephaneLenclud@222
    10
using System.Threading.Tasks;
StephaneLenclud@222
    11
StephaneLenclud@222
    12
namespace SharpDisplayManager
StephaneLenclud@222
    13
{
StephaneLenclud@222
    14
    /// <summary>
StephaneLenclud@222
    15
    /// Send a user key press event to the given CEC device.
StephaneLenclud@222
    16
    /// </summary>
StephaneLenclud@222
    17
    [DataContract]
StephaneLenclud@231
    18
    [AttributeObject(Id = "Cec.UserControlPressed", Name = "CEC User Control Pressed", Description = "Send user control code to defined CEC device.")]
StephaneLenclud@222
    19
    public class ActionCecUserControlPressed : ActionCecDevice
StephaneLenclud@222
    20
    {
StephaneLenclud@222
    21
StephaneLenclud@222
    22
        public ActionCecUserControlPressed()
StephaneLenclud@222
    23
        {
StephaneLenclud@222
    24
            Wait = true;
StephaneLenclud@222
    25
        }
StephaneLenclud@222
    26
StephaneLenclud@222
    27
        [DataMember]
StephaneLenclud@231
    28
        [AttributeObjectProperty(
StephaneLenclud@222
    29
        Id = "Cec.UserControlPressed.Code",
StephaneLenclud@222
    30
        Name = "Code",
StephaneLenclud@222
    31
        Description = "The key code used by this action."
StephaneLenclud@222
    32
        )]
StephaneLenclud@222
    33
        public CecUserControlCode Code { get; set; }
StephaneLenclud@222
    34
StephaneLenclud@222
    35
        [DataMember]
StephaneLenclud@231
    36
        [AttributeObjectProperty(
StephaneLenclud@222
    37
        Id = "Cec.UserControlPressed.Wait",
StephaneLenclud@222
    38
        Name = "Wait",
StephaneLenclud@222
    39
        Description = "Wait for that command."
StephaneLenclud@222
    40
        )]
StephaneLenclud@222
    41
        public bool Wait { get; set; }
StephaneLenclud@222
    42
StephaneLenclud@222
    43
        /// <summary>
StephaneLenclud@222
    44
        /// 
StephaneLenclud@222
    45
        /// </summary>
StephaneLenclud@222
    46
        /// <returns></returns>
StephaneLenclud@222
    47
        public override string Brief()
StephaneLenclud@222
    48
        {
StephaneLenclud@260
    49
            string brief = AttributeName + ": " + Code.ToString() + " to " + DeviceName;
StephaneLenclud@222
    50
            if (Wait)
StephaneLenclud@222
    51
            {
StephaneLenclud@222
    52
                brief += " (wait)";
StephaneLenclud@222
    53
            }
StephaneLenclud@222
    54
            return brief;
StephaneLenclud@222
    55
        }
StephaneLenclud@222
    56
StephaneLenclud@222
    57
        /// <summary>
StephaneLenclud@222
    58
        /// 
StephaneLenclud@222
    59
        /// </summary>
StephaneLenclud@258
    60
        protected override async Task DoExecute()
StephaneLenclud@222
    61
        {
StephaneLenclud@222
    62
            if (Cec.Client.Static == null)
StephaneLenclud@222
    63
            {
StephaneLenclud@253
    64
                Trace.WriteLine("WARNING: No CEC client installed.");
StephaneLenclud@222
    65
                return;
StephaneLenclud@222
    66
            }
StephaneLenclud@222
    67
StephaneLenclud@222
    68
            Cec.Client.Static.Lib.SendKeypress(Device, Code, Wait);
StephaneLenclud@222
    69
        }
StephaneLenclud@222
    70
    }
StephaneLenclud@222
    71
}