コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: porrey/DhtTiny
        private async void Timer_Tick(object sender, object e)
        {
            try
            {
                _busy.Reset();

                this.Interval = await _dhtTiny.GetIntervalAsync();

                this.ReadingId = await _dhtTiny.GetReadingIdAsync();

                this.Temperature    = string.Format("{0:0.0}°C", await _dhtTiny.GetTemperatureAsync());
                this.Humidity       = string.Format("{0:0.0}%", await _dhtTiny.GetHumidityAsync());
                this.UpperThreshold = await _dhtTiny.GetUpperThresholdAsync();

                this.LowerThreshold = await _dhtTiny.GetLowerThresholdAsync();

                this.StartDelay = await _dhtTiny.GetStartDelayAsync();

                byte statusBits = await _dhtTiny.GetStatusAsync();

                byte configurationBits = await _dhtTiny.GetConfigurationAsync();

                this.StatusEnabled = _dhtTiny.GetStatusBit(statusBits, DhtTiny.StatusBit.IsEnabled) ? "1" : "0";
                this.StatusUpperThresholdExceeded = _dhtTiny.GetStatusBit(statusBits, DhtTiny.StatusBit.UpperThresholdExceeded) ? "1" : "0";
                this.StatusLowerThresholdExceeded = _dhtTiny.GetStatusBit(statusBits, DhtTiny.StatusBit.LowerThresholdExceeded) ? "1" : "0";
                this.StatusDhtReadError           = _dhtTiny.GetStatusBit(statusBits, DhtTiny.StatusBit.DhtReadError) ? "1" : "0";
                this.StatusReserved2          = _dhtTiny.GetStatusBit(statusBits, DhtTiny.StatusBit.Reserved2) ? "1" : "0";
                this.StatusConfigurationSaved = _dhtTiny.GetStatusBit(statusBits, DhtTiny.StatusBit.ConfigSaved) ? "1" : "0";
                this.StatusReadError          = _dhtTiny.GetStatusBit(statusBits, DhtTiny.StatusBit.ReadError) ? "1" : "0";
                this.StatusWriteError         = _dhtTiny.GetStatusBit(statusBits, DhtTiny.StatusBit.WriteError) ? "1" : "0";

                this.configEnabled.IsChecked          = _dhtTiny.GetConfigurationBit(configurationBits, DhtTiny.ConfigBit.SensorEnabled) ? true : false;
                this.configThresholdEnabled.IsChecked = _dhtTiny.GetConfigurationBit(configurationBits, DhtTiny.ConfigBit.ThresholdEnabled) ? true : false;
                this.configTriggerReading.IsChecked   = _dhtTiny.GetConfigurationBit(configurationBits, DhtTiny.ConfigBit.TriggerReading) ? true : false;
                this.reserved1.IsChecked          = _dhtTiny.GetConfigurationBit(configurationBits, DhtTiny.ConfigBit.Reserved1) ? true : false;
                this.reserved2.IsChecked          = _dhtTiny.GetConfigurationBit(configurationBits, DhtTiny.ConfigBit.Reserved2) ? true : false;
                this.reserved3.IsChecked          = _dhtTiny.GetConfigurationBit(configurationBits, DhtTiny.ConfigBit.Reserved3) ? true : false;
                this.writeConfiguration.IsChecked = _dhtTiny.GetConfigurationBit(configurationBits, DhtTiny.ConfigBit.WriteConfig) ? true : false;
                this.resetConfiguration.IsChecked = _dhtTiny.GetConfigurationBit(configurationBits, DhtTiny.ConfigBit.ResetConfig) ? true : false;

                this.EnabledCommand.RaiseCanExecuteChanged();
                this.EnableThresholdsCommand.RaiseCanExecuteChanged();
                this.TriggerReadingCommand.RaiseCanExecuteChanged();
                this.Reserved1Command.RaiseCanExecuteChanged();
                this.Reserved2Command.RaiseCanExecuteChanged();
                this.Reserved3Command.RaiseCanExecuteChanged();
                this.WriteConfigurationCommand.RaiseCanExecuteChanged();
                this.ResetConfigurationCommand.RaiseCanExecuteChanged();
                this.SettingsCommand.RaiseCanExecuteChanged();
            }
            catch (Exception ex)
            {
                ExceptionEvent.Publish(ex);
            }
            finally
            {
                this.EnabledCommand.RaiseCanExecuteChanged();
                this.EnableThresholdsCommand.RaiseCanExecuteChanged();
                this.TriggerReadingCommand.RaiseCanExecuteChanged();
                this.Reserved1Command.RaiseCanExecuteChanged();
                this.Reserved2Command.RaiseCanExecuteChanged();
                this.Reserved3Command.RaiseCanExecuteChanged();
                this.WriteConfigurationCommand.RaiseCanExecuteChanged();
                this.ResetConfigurationCommand.RaiseCanExecuteChanged();
                this.SettingsCommand.RaiseCanExecuteChanged();

                _busy.Set();
            }
        }