Beispiel #1
0
        private async void ContentDialog_OkButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            try
            {
                // ***
                // *** Get the new values from the dialog.
                // ***
                UInt32 interval       = Convert.ToUInt32(this.interval.Value);
                float  lowerThreshold = Convert.ToUInt32(this.lowerThreshold.Value);
                float  upperThreshold = Convert.ToUInt32(this.upperThreshold.Value);
                UInt32 startDelay     = Convert.ToUInt32(this.startDelay.Value);
                byte   address        = Convert.ToByte(this.address.Value);
                byte   model          = _models.Where(t => t.Index == this.model.SelectedIndex).Select(t => t.Model).FirstOrDefault();

                // ***
                // *** Update only values that have changed.
                // ***
                if (_interval != interval)
                {
                    await _dhtTiny.SetIntervalAsync(interval);
                }
                if (_lowerThreshold != lowerThreshold)
                {
                    await _dhtTiny.SetLowerThresholdAsync(lowerThreshold);
                }
                if (_upperThreshold != upperThreshold)
                {
                    await _dhtTiny.SetUpperThresholdAsync(upperThreshold);
                }
                if (_startDelay != startDelay)
                {
                    await _dhtTiny.SetStartDelayAsync(startDelay);
                }
                if (_address != address)
                {
                    await _dhtTiny.SetDeviceAddressAsync(address);
                }
                if (_model != model)
                {
                    await _dhtTiny.SetDeviceModelAsync(model);
                }
            }
            catch (Exception ex)
            {
                (new MessageDialog(ex.Message)).ShowAsync().AsTask().Wait();
            }
        }