示例#1
0
        /// <summary>
        /// Resets the device and clears current measurements.
        /// </summary>
        public void Reset()
        {
            // Thread-safe lock
            lock (_lock)
            {
                // Reset device
                _device.Reset();

                // Clear measurement
                Measurement = new BarometerMeasurement();
            }
        }
示例#2
0
        /// <summary>
        /// Updates the display when the <see cref="Device"/> channels change.
        /// </summary>
        private void OnMeasurementUpdated(object sender, BarometerMeasurement measurement)
        {
            // Dump statistics to output
            WriteOutput(measurement.ToString());

            // Add data point to graph
            Graph.Add(measurement);

            // Update display
            DoPropertyChanged(nameof(Device));
            DoPropertyChanged(nameof(Graph));
        }
示例#3
0
        /// <summary>
        /// Performs calculation on the device then fires the <see cref="MeasurementUpdated"/> event.
        /// </summary>
        public BarometerMeasurement Update()
        {
            // Thread-safe lock
            lock (_lock)
            {
                // Perform calculation
                _device.Update();
                var measurement = new BarometerMeasurement(_device.Pressure, _device.Temperature);

                // Update property
                Measurement = measurement;

                // Fire event
                MeasurementUpdated?.Invoke(this, measurement);

                // Return result
                return(measurement);
            }
        }
示例#4
0
        private void SaveMeasurements_Clicked(object sender, EventArgs e)
        {
            BarometerMeasurement barometer = new BarometerMeasurement();

            barometer.Altitude = CurrentAltitude;
            barometer.Pressure = CurrentPressure;
            barometer.Label    = EntryLabelName.Text;

            if (measurements.Count > 0)
            {
                barometer.HeightChange = measurements.LastOrDefault().Altitude + barometer.Altitude;
            }
            else
            {
                barometer.HeightChange = barometer.Altitude;
            }

            measurements.Add(barometer);
        }