Server/Actions/ActionCecUserControlPressed.cs
author StephaneLenclud
Thu, 25 Aug 2016 13:34:05 +0200
changeset 255 c57b8ac80fc6
parent 231 4c706feaf706
child 258 e237c2e33545
permissions -rw-r--r--
Published v1.0.2.0.
Fixed Harmony async issue prevent the config to be fetched.
     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 Brief()
    48         {
    49             string brief = Name + ": " + 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 void 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 }