I have a datafield value that updates every second (calories per hr). I'd like this to only update every 3 or 5 seconds.
How do I get a compute function to only update every few seconds instead of every second?
Thanks
class DataField extends Ui.SimpleDataField
{
var value_picked = "---";
var counter = 0;
...
function compute(info)
{
if( counter == 3 )
{
if( info.currentHeartRate != null )
{
value_picked = info.currentHeartRate;
}
else value_picked = "---";
}
counter += 1;
if( counter > 3 )
{
counter = 0;
}
return value_picked;
}
...
}
var counter=0;
var data=null;
var displayData=null;
function compute(info) {
//do whatever you do to calculate "data"
if(counter%3==0 || displayData==null) {
//copy "data" to "displayData" - it happens every 3 seconds with the "%3"
}
counter++;
//return "displayData" here for a simple DF or in onUpdate(), use "displayData" and not "data"
}