protected async override void OnApplyTemplate() { base.OnApplyTemplate(); try { // *** // *** Get and cache the current values. // *** _interval = await _dhtTiny.GetIntervalAsync(); _lowerThreshold = await _dhtTiny.GetLowerThresholdAsync(); _upperThreshold = await _dhtTiny.GetUpperThresholdAsync(); _startDelay = await _dhtTiny.GetStartDelayAsync(); _address = await _dhtTiny.GetDeviceAddressAsync(); _model = await _dhtTiny.GetDeviceModelAsync(); // *** // *** Update the dialog. // *** this.interval.Value = _interval; this.lowerThreshold.Value = _lowerThreshold; this.upperThreshold.Value = _upperThreshold; this.startDelay.Value = _startDelay; this.address.Value = _address; this.model.SelectedIndex = _models.Where(t => t.Model == _model).Select(t => t.Index).FirstOrDefault(); } catch (Exception ex) { (new MessageDialog(ex.Message)).ShowAsync().AsTask().Wait(); } }
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(); } }