Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Refreshing Active Zone minutes in index.js

Hi all

 

New to posting and coding watch faces for the Versa but being in the UK and in and out of lock down (not being able to perform my photography job) I thought I'd give it a go!

I've managed to get one up and running however, I noticed it's draining the battery pretty quickly so assume it could be down to how much I'm calling things.
I have clock.granularity = "seconds"; which seems to be the accepted normal so I'm not thinking it's this. However I realised that I'm calling for Active Zone Minutes every millisecond (a little excessive) so is there an accepted figure for this please or a FitBit standard? Maybe 60000 (1 minute) or something similar?

 

function refresh_myAzm() {
myAzm.text = today.adjusted.activeZoneMinutes.total
};
setInterval(refresh_myAzm, 1);

Thanks for any help or pointing in the right direction.

Best Answer
0 Votes
6 REPLIES 6

I can empathise with the lockdown woes, I'm in Devon. Hang in there!

 

Rather than using setInterval, use the clock tick event. Interval runs even when the display is off, tick fires only when the display is on. This saves significant battery.

 

You can set your clock tick to minutes if you aren't displaying seconds on screen. That will conserve more power.

 

 

Best Answer
0 Votes

Hi @JonFitbit 

 

Thank you for the answer and hope lockdown 3 is ok for you so far! I think we're all frustratingly used to it now 🙂 

 

Thanks, I'm not displaying seconds so have changed this to minutes now. I had originally changed it as did start with seconds on the display.

Also, can I have multiple tick events or do I just add the azm code into the existing clock.tick please? I tried adding the refresh part of the azm code but it stopped showing the azm at all so reverted back.

This is my current azm code.

//AZM
import { goals, today } from "user-activity";
console.log(`${goals.activeZoneMinutes.total} activeZoneMinutes Goal`);

goals.addEventListener("reachgoal", (evt) => {
if (today.adjusted.activeZoneMinutes.total >= goals.activeZoneMinutes.total)
{
// AZM Goal has been met
}
});

console.log(`${today.local.activeZoneMinutes.fatBurn}`);
console.log(`${today.local.activeZoneMinutes.cardio}`);
console.log(`${today.local.activeZoneMinutes.peak}`);
console.log(`${today.adjusted.activeZoneMinutes.total}`);

let myAzm = document.getElementById("myAzm")
//REFRESH AZM
function refresh_myAzm() {
myAzm.text = today.adjusted.activeZoneMinutes.total
};
setInterval(refresh_myAzm, 1);

 

Apologies for the questions, I've tried following the docs but I seem to be going round in circles as always with code.

 

**EDIT
I've added myAzm.text = today.adjusted.activeZoneMinutes.total;

to

function updateActivity() {
stepsLabel.text = today.adjusted.steps;

 

So it pulls the data when screen comes on?!

Best Answer
0 Votes
import clock from "clock";
import { goals, today } from "user-activity";

clock.granularity = "minutes";
clock.ontick = (evt) => {
  myAzm.text = today.adjusted.activeZoneMinutes.total || 0;
};
Best Answer
0 Votes

Thanks @JonFitbit 

 

For some reason that wouldn't work so I've stuck with adding to updateActivity which seems to work. 🙂

 

Cheers again

 

Best Answer
0 Votes

AZM (and calories) only seems to be updated at the start of every new minute, so if you want to be really efficient, just check it then.

Peter McLennan
Gondwana Software
Best Answer

Thank you @Gondwana, appreciate your response and the info.

Mark. 🙂

Best Answer