/// Invoke the event - called whenever exhalation finishes protected virtual void OnExhalationComplete(object sender, ExhalationCompleteEventArgs e) { if (ExhalationComplete != null) { ExhalationComplete(this, e); } }
/// Adds a sample to the BreathAnalyser public bool AddSample(float dt, float value) { if (this.isExhaling && value < this.minBreathThreshold) { // Notify the delegate that the exhaled breath is complete isBreathGood = this.IsBreathGood(this.breathLength, this.maxBreathLength, this.exhaledVolume, this.maxPressure); ExhalationCompleteEventArgs eventArgs = new ExhalationCompleteEventArgs( this.breathLength, this.breathCount, this.exhaledVolume, isBreathGood); this.OnExhalationComplete(this, eventArgs); // Reset the state this.breathLength = 0; this.exhaledVolume = 0; this.isExhaling = false; this.breathCount++; } else if (value >= this.minBreathThreshold) { this.isBreathGood = false; this.isExhaling = true; this.exhaledVolume += dt * value; this.breathLength += dt; } return(isBreathGood); }