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