Skip to content

SMU-Ubicomp-Lab/OpenSpirometry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

#Open Spirometer in iOS

Spirometry Effort Analyzer for Vortex Whistles

This code is currently in beta and is a work in progress. Many updates will be coming. Also please note that this is in alpha right now. This process is NOT FDA approved device for providing Spirometric measures. While these values might be close to the values you would receive from a Spirometry test, we make no legal guarantees about the measurements. Consult a Doctor if you think your pulmonary ailment is worsening.

In a nutshell, you can use this code in yours by grabbing everything in the group "SpiroAnalysisModel." This has a bunch of classes, but the only one you will use directly is the "SpirometerEffortAnalyzer." For right now, that is.

The ViewController has an example of how to use every public function for the given model: make it a property in your class and set yourself as the delegate. If the delegate is a UIViewController, then some additional functionality is provided for asking permission to use the microphone (i.e., recording). Use the "askPermissionToUseAudioIfNotDone" function to access this.

You control when the effort is started using the function "beginListeningForEffort" and that kicks off the entire test. You can cancel the test at any time using the "requestThatCurrentEffortShouldCancel" function. It will clean up and try to cancel the effort (it might fail if the effort is already analyzing).

Since you are the delegate for the model (of type "SpirometerEffortDelegate") you get access to some notifications of the progress of the test. All notifications are given to you on the main thread because they are mostly meant to be used for updating UI. So if you want to do some intense processing from one of these notifications, you should do it on a separate queue (see Apple's documentation for concurrency, if you are unsure what I mean here). All of these functions are used in the example view controller:

@protocol SpirometerEffortDelegate
didFinishCalibratingSilence:
didTimeoutWaitingForTestToStart:
didStartExhaling: 
willEndTestSoon: 
didCancelEffort:
didEndEffortWithResults: NSDictionary
didUpdateFlow:(float)flow andVolume:(float)volume:

With methods for initiating the effort:
-(void)beginListeningForEffort;
-(void)askPermissionToUseAudioIfNotDone;
-(void)requestThatCurrentEffortShouldCancel;

didFinishCalibratingSilence: get notified when the background noise level has been calibrated. Example: Maybe tell the user they can start exhaling.

didTimeoutWaitingForTestToStart: get notified that no sound was heard for ~5 seconds after silence was calibrated and the effort canceled itself. Example: inform the user that this happened in the UI.

didStartExhaling: notified that the user started blowing. Example: Tell them to keep blasting out.

willEndTestSoon: notified that the test "might" end soon because the audio sounds are getting faint. You can get this notification multiple times, especially if the sound level is getting louder and softer periodically. Example: Tell the user to keep going because the effort is almost over.

didCancelEffort: Get notified that your request to cancel the effort was successful. Example: tell user test was cancelled.

didEndEffortWithResults: Get notified that the test is over and the results are passed in through a dictionary of key/value and key/array pairs. This part of the model is still getting built out so the dictionary only has keys, but the values and arrays are currently just empty NSArrays and NSNumbers. In the future the curves and the measures will be in this dictionary. The efforts will also have errors for the test (Cough is "semi-implemented" but that is the only error you might see--the detection may also be a bit sensitive right now).

didUpdateFlow:(float)flow andVolume:(float)volume: This function is called every time we detect a reasonable flow rate value. So it means you will get notified many times per second (but it not guaranteed to be consistent--if no valid frequency is found or the processing gets bogged down, this could get called at weird times). The flow rate will currently show up (not calibrated, it just moves in response to frequency). Volume will always currently be zero. Example: Update a part of your UI showing flow rate. The example has this connected to a slider and text label.

Right now this code is in beta, so if you post it on GitHub, be sure to say that it is not ready to be forked yet.

Third Party Frameworks/Libraries

  • [Novocaine]:https://github.com/alexbw/novocaine . I manipulated this for iOS8 and built completely for objective-c in iOS. It isn't really backwards compatible with Alex's library anymore--although you should definitely check out Novocaine. I use it in my iOS course here at SMU.

Building Vortex Whistles

Still to come: we are in the process of getting an open source page for building your owm custom whistles via 3D printing. And providing actual calibration of the whistle coefficients and bias.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published