Beispiel #1
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)));
     }
 }
Beispiel #2
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; });
            }
        }