简体   繁体   English

如何获得Gear Fit 2 Pro基于Web的表盘的每日步数?

[英]How do I get daily step count in a gear fit 2 pro web based watchface?

I am building a html/js powered watchface for the gear fit 2 pro and I'm having trouble accomplishing what seems like a simple task: getting the daily step count. 我正在为Gear Fit 2 Pro构建一个由html / js驱动的表盘,但在完成看起来很简单的任务时遇到了麻烦:获取每日步数。

I have poured over the documentation, but it only describes how to count either steps since the watchface has started, or steps since the device has been booted. 我已经仔细阅读了文档,但是它仅描述了如何从表盘启动以来或从设备启动以来计算步骤。 Other watchfaces immediately detect the system-wide step count and display it, but I don't see how this is possible! 其他表盘会立即检测并显示系统范围的步数,但我看不出这是怎么可能的!

Does anyone have an example of how to do this? 有没有人举过一个例子? I suspect the stepdifference or readrecorderdata functions might be involved, but the first is impossible to use due to inadequate documentation and the second does not seem to actually be present in the device. 我怀疑可能涉及到stepdifference或readrecorderdata函数,但是由于文档不足,第一个无法使用,而第二个似乎并不存在于设备中。

You can setAccumulativePedometerListener() for the time period sensor data required. 您可以为所需的时间段传感器数据设置AccumulativePedometerListener()。 In you case you can reset the listener at end of the day. 在这种情况下,您可以在一天结束时重置监听器。 I've written a pseudo_code for you to show daily step count. 我为您编写了一个伪代码,以显示每日步数。

var sensor_data = document.getElementById("sensor-data");
var step_count=0,
    offset=0,   // to reduce yesterday's data
    currentDailyStep=0;

function updateTime() {
    var datetime = tizen.time.getCurrentDateTime(),
        hour = datetime.getHours(),
        minute = datetime.getMinutes(),
        second = datetime.getSeconds();

    if(hour === 23 && minute === 59 && second === 59){  // at the end of the day
            tizen.humanactivitymonitor.unsetAccumulativePedometerListener();
            tizen.humanactivitymonitor.stop("PEDOMETER");               
            offset = step_count;    // store today's count

            pedometer_init();   //reset
        }

    /*
     * Other Codes
     * ............
     * .........
     */
}

function onchangedCB(pedometerInfo) {
    step_count = pedometerInfo.accumulativeTotalStepCount;
    currentDailyStep = step_count - offset; // totl count - total count till yesterday
    sensor_data.innerHTML = currentDailyStep;

}

function pedometer_init(){
    tizen.humanactivitymonitor.start("PEDOMETER");
    tizen.humanactivitymonitor.setAccumulativePedometerListener(onchangedCB);
}

function init(){
    pedometer_init();
}

window.onload = init();

You need to reduce offset manually as stop() function don't reset the count. 您需要手动减少偏移量,因为stop()函数不会重置计数。 Store the daily step data If you are interested to show statistics. 如果需要显示统计信息,请存储每日步数数据。

In addition, In Tizen Developers API References there's a Code Sample using HumanActivityRecorder to record Step count daily, Please Check If it helps: 另外,在《 Tizen开发人员API参考》中,有一个使用HumanActivityRecorder的代码示例每天记录步骤计数,请检查是否有帮助:

function onerror(error){
   console.log(error.name + ": " + error.message);
}

function onread(data){
   for (var idx = 0; idx < data.length; ++idx)
   {
      console.log("*** " + idx);
      console.log('totalStepCount: ' + data[idx].totalStepCount);
   }
}

var type = 'PEDOMETER';
var now = new Date();
var startTime = now.setDate(now.getDate() - 7);
var anchorTime = (new Date(2000, 1, 2, 6)).getTime();
var query ={
   startTime: startTime / 1000,
   anchorTime: anchorTime / 1000,
   interval: 1440 /* 1 day */
};

try{
   tizen.humanactivitymonitor.readRecorderData(type, query, onread, onerror);
}
catch (err){
   console.log(err.name + ': ' + err.message);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM