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

586 Views Asked by At

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.

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.

1

There are 1 best solutions below

0
On

You can setAccumulativePedometerListener() for the time period sensor data required. 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. 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:

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