Ejemplo n.º 1
0
        public MainPage()
        {
            this.InitializeComponent();
            IRControl.Init();
            AzureIoTHub.RegisterDirectMethodsAsync();

            IRControl.AddButtonListener(OnButtonValueChanged);

            Unloaded += MainPage_Unloaded;

            /*
             * Task<string> task = hub.ReceiveCloudToDeviceMessageAsync();
             * task.ContinueWith(x => HandleMessage(x.Result));
             */
        }
Ejemplo n.º 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; });
            }
        }