Event callback for taking a breath?

Is there any way to register an event callback for the user taking a breath? I am new to Connect IQ programming and would like to build a watch app for inspiratory muscle strength training. Each breath should be automatically counted as a separate rep. I am aware of the ActivityMonitor.Info.respirationRate instance member but that's not quite what I want because it won't let me count individual breaths.

  • It’s calculated from the inter beat intervals in the HRV data.  You’d need to use Toybox.sensor and then the HR data.

    developer.garmin.com/.../HeartRateData.html

    Then sensor callback here

    developer.garmin.com/.../Sensor.html

  • Thanks for the explanation. Is there any sample code showing how to detect individual breaths using beat-to-beat intervals? I've never done any HRV calculations before.

  • Not that I’m aware of as it is licensed from Firstbeat.  Black box kind of stuff unless any of their research papers explain how they do it. But basically the intrabeat interval changes as you inhale / exhale.  You could likely write your app to collect the HRV data paying attention to your breathing then look at the collected data to see what it tells you regards your calc.

    www.firstbeatanalytics.com/.../

  • Before you proceed using data from HeartRateData I would do a little check to see if the data is valid or not. As far as I know it might not be accurate when you use the built in optical heart rate sensor. I THINK the milliseconds are based on the heart rate you get, and not on some real measurement. I'll explain: when the reported HR is 60 you'll get 1000ms between the 2 heart beats. However in reality there might have been 999 or 1001ms. I haven't checked this, but you could easily check it by logging the reported HR and the heartBeatIntervals. In reality (unless you're just before dying from exhaustion) the real RR interval is changing between almost every heart beat (even when doing the reverse calculation and you would get "60bpm", the real RR interval numbers in milliseconds would change) If I'm wrong then let me know here :) 

    If I'm right then probably the only way to do it is to use the data you get from an external heart rate monitor strap. I am able to read the RR intervals from a strap paired via ANT. However it is only the 1st step, because then you'll have to do the real magic to get the breath out of all this data. I'm not sure how hard that is (I've read about it when I searched for HRV related papers, but the breaths were not my goal so didn't really paid attention) but IMHO even when you will succeed you'd probably be able to calculate the breaths per minute and not necessarily be able to tell in real time when the breath happens (but maybe you can)

  • I know, but the point is that both HR and breaths per minute are data we get from the device after it processed the underlying raw data (which is more or less the RR-intervals) and for both what nradov is trying to achieve (I guess display something when the user is taking a breath?) and for what I might maybe add to my datafield in the distant future (calculate the breaths per minute myself from the ANT data, because the watch doesn't do it for me when it's connected via ANT to the datafield (not paired to the watch)) we need to do the calculations from the raw data.

  • This is actually a reason to have the HRM paired in the FW vs doing your own ANT interface.  You can miss stuff, which is normally recorded in the fit file.  Breathing and running dynamics for example, plus the HR will be recorded from the OHR and not the external HRM.  Sure you can use fitContrib, but Garmin doesn't really use any of that.