Пример #1
0
        private async void InitializeI2CDevice()
        {
            try
            {
                //Todo
                string advanced_query_syntax = I2cDevice.GetDeviceSelector(I2C_CONTROLLER_NAME);
                DeviceInformationCollection device_information_collection =
                    await DeviceInformation.FindAllAsync(advanced_query_syntax);

                string deviceId = device_information_collection[0].Id;

                I2cConnectionSettings htdu21d_connection =
                    new I2cConnectionSettings(HTU21D.HTDU21D_I2C_ADDRESS);
                htdu21d_connection.BusSpeed    = I2cBusSpeed.FastMode;
                htdu21d_connection.SharingMode = I2cSharingMode.Shared;

                htdu21d = await I2cDevice.FromIdAsync(deviceId, htdu21d_connection);

                rootPage.NotifyUser("Status is Good", NotifyType.StatusMessage);

                HTU21DSensor = new HTU21D(ref htdu21d);

                if (HTU21DSensor != null)
                {
                    ReadSensorTimer          = new DispatcherTimer();
                    ReadSensorTimer.Interval = TimeSpan.FromMilliseconds(3000);
                    ReadSensorTimer.Tick    += Timer_Tick;
                    ReadSensorTimer.Start();
                }
            }
            catch (Exception e)
            {
                HTU21DSensor = null;
                Debug.WriteLine(e.ToString());
                rootPage.NotifyUser("InitializeI2CDevice error", NotifyType.ErrorMessage);
                return;
            }
        }