El Guapo
El Guapo

Reputation: 5781

Garmin HRM takes a long time to connect

I am writing a new widget for my Garmin FR 920xt... in my view I have enabled the HRM and am going to display HR (amongst other info), however, it seems like it takes quite a while (30 seconds plus) to start displaying information.

Is there a way for me to force it to "connect" quicker?

Here is a snippet of my code where I set up the view.

function initialize()
{
    Snsr.setEnabledSensors( [Snsr.SENSOR_HEARTRATE] );
    Snsr.enableSensorEvents( method(:onSensor) );
    strHR = "HR: --- bpm";
}
function onSensor(sensorInfo) {
    if( sensorInfo.heartRate != null ) {
        strHR = "HR: " + sensorInfo.heartRate.toString() + " bpm";
    } else {
        strHR = "HR: --- bpm";
    }
    Ui.requestUpdate();
}

As you can see this is very rudimentary... after about 30 seconds data does start coming through.

Upvotes: 1

Views: 534

Answers (1)

Travis Vitek
Travis Vitek

Reputation: 226

You should be able to get information via the Activity.Info structure much more quickly than that. Have you tried that?

using Toybox.Activity as Activity;
using Toybox.Timer as Timer;
using Toybox.WatchUi as Ui;

class MyView extends Ui.View {

    hidden var _timer;

    function onShow() {
        _timer = new Timer.Timer();
        _timer.start(method(:onTimer), 1000, true);
    }

    function onUpdate(dc) {
        var info = Activity.getActivityInfo();
        if (info.currentHeartRate != null) {
            // display the heart rate value
        }
        else {
            // display something else
        }
    }

    function onHide() {
        _timer.stop();
        _timer = null;
    }

    function onTimer() {
        Ui.requestUpdate();
    }
}

Upvotes: 2

Related Questions