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