Esempio n. 1
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                // ***
                // *** Find all devices on the bus.
                // ***
                IEnumerable <byte> address = await DhtTiny.FindAllDhtTinyAsync(this.FindAllDhtTinyCallback);

                if (address.Count() > 0)
                {
                    this.Status = string.Format("{0} device(s) found.", address.Count());

                    // ***
                    // *** Setup the DhtTiny instance.
                    // ***
                    _dhtTiny = new DhtTiny(address.First());
                    var result = await _dhtTiny.InitializeAsync();

                    if (result == InitializationResult.Successful)
                    {
                        await UpdateStatusBarItems();

                        // ***
                        // *** Start the timer.
                        // ***
                        _timer.Start();

                        this.Status = "Connected/Monitoring.";
                    }
                    else
                    {
                        string message = string.Empty;

                        switch (result)
                        {
                        case InitializationResult.None:
                            message = "Initialization has not been performed.";
                            break;

                        case InitializationResult.NoI2cController:
                            message = "Initialization failed due to lack of an I2C controller.";
                            break;

                        case InitializationResult.DeviceInUse:
                            message = "Initialization failed due to device already in use.";
                            break;

                        case InitializationResult.DeviceNotFound:
                            message = "Initialization failed because a device was not found on the I2C bus.";
                            break;
                        }

                        this.Status = string.Format("Initialization Error: {0}", message);
                    }
                }
                else
                {
                    this.Status = "No DHT Tiny devices were found. Check connections and try again.";
                }
            }
            catch (Exception ex)
            {
                ExceptionEvent.Publish(ex);
            }

            base.OnNavigatedTo(e);
        }