示例#1
0
        private static Task <MethodResponse> OnTransmitCalled(MethodRequest methodRequest, object userContext)
        {
            IRMessage msg = new IRMessage(methodRequest.DataAsJson.Substring(1, methodRequest.DataAsJson.Length - 2));

            IRControl.Transmit(msg);
            string result = "'Transmitted IR signal'";

            return(Task.FromResult(new MethodResponse(Encoding.UTF8.GetBytes(result), 200)));
        }
示例#2
0
 public void HandleData(string data)
 {
     if (data.StartsWith("irMSG:"))
     {
         IRMessage msg = new IRMessage(data.Substring("irMsg:".Length));
         Console.WriteLine("Recording received: '{0}'", msg.ToString());
     }
     else
     {
         Console.WriteLine("Message received: '{0}'", data);
     }
 }
示例#3
0
 private static Task <MethodResponse> OnEndRecordingCalled(MethodRequest methodRequest, object userContext)
 {
     try
     {
         IRMessage msg = IRControl.EndRecording();
         if (msg == null)
         {
             return(Task.FromResult(new MethodResponse(Encoding.UTF8.GetBytes("'The IR reciver did not receive a message'"), 500)));
         }
         string result = "'" + msg.Encode() + "'";
         SendDeviceToCloudMessageAsync(methodRequest.DataAsJson + ";" + msg.Encode()).Wait();
         return(Task.FromResult(new MethodResponse(Encoding.UTF8.GetBytes(result), 200)));
     }
     catch (Exception e)
     {
         return(Task.FromResult(new MethodResponse(Encoding.UTF8.GetBytes("'Error in OnEndRecordingCalled:" + e.Message + "'"), 500)));
     }
 }
示例#4
0
        public static void Transmit(IRMessage message)
        {
            statusLED.Write(GpioPinValue.High);
            stopwatch.Start();
            bool flag = true;

            foreach (double d in message.intervalList)
            {
                if (flag)
                {
                    Send1(d);
                }
                else
                {
                    Send0(d);
                }
                flag = !flag;
            }
            stopwatch.Stop();
            statusLED.Write(GpioPinValue.Low);
        }
示例#5
0
        private void Button_Record(object sender, RoutedEventArgs e)
        {
            if (recordButton.Content.ToString().Equals("Start Recording"))
            {
                IRControl.StartRecording();
                recordButton.Content = "Stop Recording";
            }
            else
            {
                IRMessage msg = IRControl.EndRecording();
                recordButton.Content = "Start Recording";
                if (msg != null)
                {
                    mainText.Text  = msg.ToString() + "\n";
                    mainText.Text += msg.ParseToBits() + "\n";
                }

                else
                {
                    mainText.Text = "Nothing was recorded.";
                }
                recordedByButton = msg;
            }
        }
示例#6
0
        public void OnButtonValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            if (args.Edge == GpioPinEdge.RisingEdge) // Button is opposite to intuition, so that if checks 'if just pressed'
            {
                IRControl.StartRecording();
            }
            else
            {
                IRMessage msg = IRControl.EndRecording();
                string    debugString;
                if (msg != null)
                {
                    debugString  = msg.ToString() + "\n";
                    debugString += msg.ParseToBits() + "\n";
                    AzureIoTHub.SendDeviceToCloudMessageAsync("\"ProductName;Action" + DateTimeOffset.Now.ToUnixTimeMilliseconds() + "\"" + ";" + msg.Encode()).Wait();
                }
                else
                {
                    debugString = "Nothing was recorded.";
                }

                Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { mainText.Text = debugString; });
            }
        }