Ejemplo n.º 1
0
        private Task InitializeAsync()
        {
            if (_initializeTask == null || !_initializeTask.IsCompletedSuccessfully)
            {
                _initializeTask = Task.Run(async() =>
                {
                    try
                    {
                        var devices = await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector());

                        var settings = new I2cConnectionSettings(118)
                        {
                            BusSpeed = I2cBusSpeed.FastMode
                        };

                        _device = await I2cDevice.FromIdAsync(devices[0].Id, settings);

                        _bme280 = await Bme280.CreateAsync(_device).ConfigureAwait(false);
                    }
                    catch
                    {
                        _device         = null;
                        _bme280         = null;
                        _initializeTask = null;
                        throw;
                    }
                });
            }

            return(_initializeTask);
        }