Esempio n. 1
0
File: Client.cs Progetto: tihilv/Vkm
        /// <summary>
        ///     Send a command to the given device through your Harmony Hub.
        ///     The returned task will complete once we receive acknowledgment from the Hub.
        /// </summary>
        /// <param name="deviceId">string with the ID of the device</param>
        /// <param name="command">string with the command for the device</param>
        /// <param name="press">true for press, false for release</param>
        /// <param name="timestamp">Timestamp for the command, e.g. send a press with 0 and a release with 100</param>
        public async Task SendCommandAsync(string deviceId, string command, bool press = true, int?timestamp = null)
        {
            Trace.WriteLine("Harmony-logs: SendCommandAsync");
            var document = HarmonyDocuments.IrCommandDocument(deviceId, command, press, timestamp);

            await SendDocumentAsync(document, TaskType.SendCommmand).ConfigureAwait(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Get cmd string
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="command"></param>
        /// <param name="timespan"></param>
        /// <returns></returns>
        public static string GetPressCmd(string deviceId, string command, int timespan = 100)
        {
            var now = (int)DateTime.Now.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;

            var press = HarmonyDocuments.IrCommandDocument(deviceId, command, true, now - timespan);

            return(press.ToString());
        }
Esempio n. 3
0
        /// <summary>
        ///     Send a message that a button was pressed
        ///     Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="deviceId">string with the ID of the device</param>
        /// <param name="command">string with the command for the device</param>
        /// <param name="timespan">The time between the press and release, default 100ms</param>
        public async Task SendKeyPressAsync(string deviceId, string command, int timespan = 100)
        {
            var now   = (int)DateTime.Now.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
            var press = HarmonyDocuments.IrCommandDocument(deviceId, command, true, now - timespan);

            await FireAndForgetAsync(press).ConfigureAwait(false);

            var release = HarmonyDocuments.IrCommandDocument(deviceId, command, false, timespan);

            await FireAndForgetAsync(release).ConfigureAwait(false);
        }
Esempio n. 4
0
File: Client.cs Progetto: tihilv/Vkm
        /// <summary>
        ///     Send a message that a button was pressed
        ///     Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="deviceId">string with the ID of the device</param>
        /// <param name="command">string with the command for the device</param>
        /// <param name="timespan">The time between the press and release, default 100ms</param>
        public async Task SendKeyPressAsync(string deviceId, string command, int timespan = 100)
        {
            Trace.WriteLine("Harmony: SendKeyPressAsync");
            var now   = (int)DateTime.Now.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
            var press = HarmonyDocuments.IrCommandDocument(deviceId, command, true, now - timespan);

            await SendDocumentAsync(press, TaskType.SendCommmand).ConfigureAwait(false);

            var release = HarmonyDocuments.IrCommandDocument(deviceId, command, false, now);

            await SendDocumentAsync(release, TaskType.SendCommmand).ConfigureAwait(false);
        }
Esempio n. 5
0
        /// <summary>
        /// Send message to HarmonyHub to request to press a button
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="command"></param>
        public void PressButton(string deviceId, string command)
        {
            _clientCommand = ClientCommandType.PressButton;

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.IrCommandDocument(deviceId, command));
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);

            iqGrabber.SendIq(iqToSend, 5);

            WaitForData(5);
        }
Esempio n. 6
0
        /// <summary>
        ///     Send message to HarmonyHub to request to press a button
        ///     Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="deviceId">string with the ID of the device</param>
        /// <param name="command">string with the command for the device</param>
        /// <param name="press">true for press, false for release</param>
        /// <param name="timestamp">Timestamp for the command, e.g. send a press with 0 and a release with 100</param>
        public async Task SendCommandAsync(string deviceId, string command, bool press = true, int?timestamp = null)
        {
            var document = HarmonyDocuments.IrCommandDocument(deviceId, command, press, timestamp);

            await FireAndForgetAsync(document).ConfigureAwait(false);
        }