Exemplo n.º 1
0
 public static void Command(this LibCECClient client, int cmd)
 {
     if (Enum.IsDefined(typeof(CecOpcode), cmd))
     {
         client.Command((CecOpcode)cmd);
     }
 }
Exemplo n.º 2
0
        public static void CommandAsHex(this LibCECClient client, string cmd)
        {
            bool succeded = true;

            if (cmd.StartsWith("0x"))
            {
                cmd = cmd.Remove(0, 2);

                var hexValues = cmd.Split(':');

                if (hexValues.Length == 0)
                {
                    succeded = false;
                }

                byte[] hexParsed = new byte[hexValues.Length];
                for (var i = 0; i < hexValues.Length; i++)
                {
                    var  hexVal = hexValues[i];
                    bool parsed = Byte.TryParse(hexVal, NumberStyles.HexNumber, null, out hexParsed[i]);
                    succeded = parsed;
                }

                client.Command(hexParsed);
            }

            if (!succeded)
            {
                Console.WriteLine($"Tried to parse CMD \"{cmd}\" as hex values, but failed.");
            }
        }
Exemplo n.º 3
0
        public static void Command(this LibCECClient client, params byte[] values)
        {
            var cmd = new CecCommand();

            foreach (byte value in values)
            {
                cmd.PushBack(value);
            }

            client.Transmit(cmd);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Send command via the command enum <see cref="CecOpcode"/>.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="cmd"></param>
        public static void Command(this LibCECClient client, CecOpcode cmd)
        {
            Console.WriteLine($"Received Command: {cmd}");

            CecCommand newCommand = new CecCommand
            {
                Initiator   = CecLogicalAddress.PlaybackDevice1,
                Destination = CecLogicalAddress.Tv,
                Opcode      = cmd
            };

            client.Transmit(newCommand);
        }
Exemplo n.º 5
0
        public static void CommandAsServiceCommand(this LibCECClient client, int cmd)
        {
            var cmdNames = Enum.GetNames(typeof(CecOpcode));
            var index    = cmd - 128;

            if (index < 0 || index > cmdNames.Length)
            {
                Console.WriteLine($"Received Command: {cmd} " +
                                  "Tried to interpret as service command, but couldn\'t. " +
                                  "Value has to be between 128 and 255!");
                return;
            }

            client.Command(cmdNames[index]);
        }
Exemplo n.º 6
0
        public static void CommandAsHex(this LibCECClient client, int cmd)
        {
            string hex = cmd.ToString("X");

            int insertIndex = 1;

            for (var i = 0; i < hex.Length - insertIndex; i++)
            {
                if (i % 2 == 1)
                {
                    hex = hex.Insert(i + insertIndex, ":");
                    insertIndex++;
                }
            }

            client.CommandAsHex($"0x{hex}");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Send command via a string representation of a <see cref="CecOpcode"/>.
        /// <para />
        /// Note: Command is Case Insensitive
        /// <para />
        /// <example>
        /// Ex:
        /// "Standby", "TextViewOn", "standby", "textviewon"
        /// </example>
        /// </summary>
        /// <param name="client"></param>
        /// <param name="cmd"></param>
        public static void Command(this LibCECClient client, string cmd)
        {
            cmd = cmd.ToLower();

            if (cmd == "on")
            {
                client.Lib.PowerOnDevices(CecLogicalAddress.Tv);
                return;
            }

            string[] strings = Enum.GetNames(typeof(CecOpcode));
            if (!strings.Contains(cmd, StringComparer.CurrentCultureIgnoreCase))
            {
                Console.WriteLine($"{cmd} is not a CEC command!");
                return;
            }

            CecOpcode cecCmd = (CecOpcode)Enum.Parse(typeof(CecOpcode), cmd, true);

            client.Command(cecCmd);
        }
Exemplo n.º 8
0
        public bool Start(HostControl hostControl)
        {
#if DEBUG
            if (!Environment.UserInteractive)
            {
                var logDir = Directory.GetCurrentDirectory() + @"\Logs";

                Directory.CreateDirectory(logDir);

                var logName = $@"{logDir}\{DateTime.Now:yyyy-MM-dd - hh;mm tt}.log";
                var sw      = new StreamWriter(logName)
                {
                    AutoFlush = true
                };
                Console.SetOut(sw);
            }
#endif

            client = LibCECClient.Create();

            return(true);
        }