我正在为我的Garmin FR 920 am写一个新的小部件.在我看来,我已经启用了人力资源管理,并将显示人力资源(以及其他信息),然而,似乎需要相当一段时间(30秒以上)才能开始显示信息。
我有没有办法让它更快地“连接”?
下面是我设置视图的代码片段。
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秒后,数据就会开始传输。
发布于 2015-07-06 21:10:39
您应该能够更快地通过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();
}
}https://stackoverflow.com/questions/31127685
复制相似问题