/// <summary> /// Sets the ActiveMeasurement at the start of a measurement and casts BeginMeasurement events coming from a different thread to the UI thread when necessary. /// </summary> /// <param name="sender">The sender.</param> /// <param name="newMeasurement">The new measurement.</param> /// <exception cref="System.NullReferenceException">Platform not set.</exception> private void _comm_BeginMeasurement(object sender, ActiveMeasurement newMeasurement) { if (_platform == null) { throw new NullReferenceException("Platform not set."); } if (_platform.InvokeIfRequired(new CommManager.BeginMeasurementEventHandler(_comm_BeginMeasurement), sender, newMeasurement)) //Recast event to UI thread when necessary { return; } MeasurementStarted?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Starts measurement process. /// Sets values of fields and properties /// responsible for the correct flow of the measurement process. /// Invokes "MeasurementStarted" event. /// Sets timer to let the application know /// when the measurement process should be stopped automatically. /// Executes the StartHeartRateMonitor method of the HeartRateMonitorModel object. /// </summary> private void StartMeasurement() { IsFinished = false; IsMeasuring = true; MeasurementCountdown = MEASUREMENT_TIME; measurementStartTimestamp = DateTime.Now; measurementValues = new List <int>(); MeasurementStarted?.Invoke(this, new EventArgs()); Device.StartTimer(TimeSpan.FromSeconds(MEASUREMENT_TIME), () => { if (IsMeasuring && measurementLock == 0) { StopMeasurement(); ((Command)ShowSettingsCommand).ChangeCanExecute(); } if (measurementLock > 0) { measurementLock -= 1; } return(false); }); Device.StartTimer(TimeSpan.FromSeconds(1), () => { if (!IsMeasuring) { return(false); } TimeSpan measurementElapsedTime = DateTime.Now - measurementStartTimestamp; MeasurementCountdown = MEASUREMENT_TIME - measurementElapsedTime.Seconds; return(true); }); heartRateMonitorModel.StartHeartRateMonitor(); }
/// <summary> /// 测量开始事件 /// </summary> protected void OnMeasurementStarted() { CanMeasure = false; MeasurementStarted?.Invoke(this, new EventArgs()); }