Skip to content

Commit

Permalink
5.1.0 - Fix issues with first incorrect mesure of respiration rate. A…
Browse files Browse the repository at this point in the history
…lso some improvements in respiration rate chart
  • Loading branch information
dliedke committed Feb 2, 2023
1 parent 200cc99 commit 08ca68f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
28 changes: 28 additions & 0 deletions HrvAlgorithms/sources/activity/RrActivity.mc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module HrvAlgorithms {

// Check if device supports respiration rate
if (isRespirationRateSupported()) {
//DEBUG
//PopulateFakeRRHistory();
me.respirationRateSupported = true;
me.rrSummary = new RrSummary();
me.rrSummary.maxRr = 0;
Expand All @@ -27,6 +29,7 @@ module HrvAlgorithms {
private var totalRespirationRateSum;
private var rrSummary;
private var mRRHistory = [];
private var firstBadMesure = true;

// Method to be used without class instance
function isRespirationRateSupported(){
Expand All @@ -47,6 +50,13 @@ module HrvAlgorithms {
// If device supports respiration rate
if (me.respirationRateSupported) {

// Usually device returns 15 or 14 incorrectly as first mesure and should be ignored
if (firstBadMesure)
{
firstBadMesure = false;
return -1;
}

// Retrieves respiration rate
var respirationRate = ActivityMonitor.getInfo().respirationRate;

Expand Down Expand Up @@ -92,5 +102,23 @@ module HrvAlgorithms {
rrSummary.rrHistory = me.mRRHistory;
return rrSummary;
}


//DEBUG - start - test the respiration rate chart instantaneously for X minutes
// also change min/max HR fixed in class RespirationRateGraphView and
// call this method in initialize() of this class
/*var numMinutes = 1;
var mRRHistory1Min = [10,10,10,10,10,10,10,10,10,10,12,12,12,12,12,12,12,12,12,12,14,14,14,14,14,14,14,14,14,14,11,11,11,11,11,11,11,11,11,11,8,8,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7,7,7,7];
private function PopulateFakeRRHistory() {
for (var f=1;f<=numMinutes;f++) {
for (var i=0;i<mRRHistory1Min.size();i++)
{
mRRHistory.add(mRRHistory1Min[i]);
}
}
}*/
//DEBUG - end
}
}
2 changes: 1 addition & 1 deletion Meditate/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. -->
<iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="3">
<iq:application entry="MeditateApp" id="9abb375dcf7c4ace87ff66f4f774f6c8" launcherIcon="@Drawables.launcherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watch-app" version="5.0.0">
<iq:application entry="MeditateApp" id="9abb375dcf7c4ace87ff66f4f774f6c8" launcherIcon="@Drawables.launcherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watch-app" version="5.1.0">
<iq:products>
<iq:product id="approachs62"/>
<iq:product id="d2air"/>
Expand Down
2 changes: 1 addition & 1 deletion Meditate/source/summaryScreen/HeartRateGraphView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class HeartRateGraphView extends ScreenPicker.ScreenPickerView {
dc.drawText(position_x + App.getApp().getProperty("heartRateChartXPosLabel"),
position_y - (lineSpacing * i),
Gfx.FONT_SYSTEM_XTINY,
Math.round(HistoryMin + (minMaxDiff / 4) * i).toNumber(),
Math.round(HistoryMin + (minMaxDiff / 4) * i).toNumber().toString(),
Graphics.TEXT_JUSTIFY_CENTER|Graphics.TEXT_JUSTIFY_VCENTER);
}
}
Expand Down
36 changes: 28 additions & 8 deletions Meditate/source/summaryScreen/RespirationRateGraphView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class RespirationRateGraphView extends ScreenPicker.ScreenPickerView {
}

//DEBUG
//me.summaryModel.minRr = 6;
//me.summaryModel.minRr = 7;
//me.summaryModel.maxRr = 14;

// Get min and max RR and check if they are valid
Expand All @@ -106,11 +106,30 @@ class RespirationRateGraphView extends ScreenPicker.ScreenPickerView {
}

// Reduce a bit the min respiration rate so it will show in the chart
HistoryMin-=3;
HistoryMin-=1;

// Calculate different between min and max RR
var minMaxDiff = (HistoryMax - HistoryMin).toFloat();


// Calculate number of horizontal lines that will be required for chart
var numberHorizontalLines = 4;

// If we only have 3 numbers to draw, draw 3 lines
if (minMaxDiff <=3 ) {
numberHorizontalLines = 3;
}

// If we only have 2 numbers to draw, draw 2 lines
if (minMaxDiff <=2 ) {
numberHorizontalLines = 2;
}

// If we only have 1 number to draw, draw 1 lines
if (minMaxDiff <=1 ) {
numberHorizontalLines = 1;
}


// Chart as light blue
dc.setPenWidth(1);
dc.setColor(0x27a0c4, Graphics.COLOR_TRANSPARENT);
Expand Down Expand Up @@ -140,7 +159,7 @@ class RespirationRateGraphView extends ScreenPicker.ScreenPickerView {
if (respirationRate!=null && respirationRate > 1) {

var lineHeight = (respirationRate-HistoryMin) * (graph_height.toFloat() / minMaxDiff.toFloat());

dc.drawLine(position_x + xStep,
position_y - lineHeight.toNumber(),
position_x + xStep,
Expand All @@ -161,11 +180,12 @@ class RespirationRateGraphView extends ScreenPicker.ScreenPickerView {
dc.setPenWidth(1);
dc.setColor(Gfx.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);

var lineSpacing = graph_height / 4;

for(var i = 0; i <= 4; i++){
var lineSpacing = graph_height / numberHorizontalLines;

for(var i = 0; i <= numberHorizontalLines; i++){

// Draw lines over chart
// Draw horizontal lines over chart
dc.drawLine(position_x + 3,
position_y - (lineSpacing * i),
position_x + graph_width,
Expand All @@ -177,7 +197,7 @@ class RespirationRateGraphView extends ScreenPicker.ScreenPickerView {
dc.drawText(position_x + App.getApp().getProperty("heartRateChartXPosLabel"),
position_y - (lineSpacing * i),
Gfx.FONT_SYSTEM_XTINY,
Math.round(HistoryMin + (minMaxDiff / 4) * i).toNumber(),
Math.ceil(HistoryMin + (minMaxDiff / numberHorizontalLines) * i).toNumber().toString(),
Graphics.TEXT_JUSTIFY_CENTER|Graphics.TEXT_JUSTIFY_VCENTER);
}
}
Expand Down

0 comments on commit 08ca68f

Please sign in to comment.