Garmin HRM 需要很长时间才能连接

Garmin HRM takes a long time to connect

我正在为我的 Garmin FR 920xt 编写一个新的小部件...在我看来,我已经启用了 HRM 并打算显示 HR(以及其他信息),但是,这似乎需要相当长的时间( 30 秒以上)开始显示信息。

有没有办法让它更快地"connect"?

这是我设置视图的代码片段。

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();
}

如您所见,这是非常初级的...大约 30 秒后,数据开始通过。

您应该能够通过 Activity.Info 结构更快地获取信息。你试过了吗?

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();
    }
}