10-11-2017 07:26
10-11-2017 07:26
I am starting to work on creating my watch face. I am not a developer, just playing around a bit with some coding knowledge.
Here is what I coded. I would like to know the opinion of more experienced developers if this is a good starting point for building on it. Also I am going to test battery drainage, I had some issues before adding the display event.
import clock from "clock";
import { display } from "display";
import document from "document";
import * as util from "../common/utils";
// Update the clock every minute
clock.granularity = "minutes";
let myDate = document.getElementById("myDate");
let myTime = document.getElementById("myTime");
display.addEventListener('change', function() {
if(display.on) {
updateClock();
function updateClock(){
clock.ontick = function(evt) {
myDate.innerText = (evt.date.toString().slice(0,10));
myTime.innerText = ("0" + evt.date.getHours()).slice(-2) + ":" +
("0" + evt.date.getMinutes()).slice(-2);
};
};
} else {
// nothing happens after this
}
});
Answered! Go to the Best Answer.
Best Answer10-12-2017 03:17
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
10-12-2017 03:17
A few points:
You don't need to use the `change` event, the `tick` event only fires when the screen is on anyway.
You shouldn't nest your functions inside the events. Declare them once, then make calls to them from within the events.
Best Answer10-12-2017 03:17
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
10-12-2017 03:17
A few points:
You don't need to use the `change` event, the `tick` event only fires when the screen is on anyway.
You shouldn't nest your functions inside the events. Declare them once, then make calls to them from within the events.
Best Answer10-12-2017 05:17
10-12-2017 05:17
Thanks @JonFitbit !
I'll change and see if the battery drainage from the other post doesn't happen. So far it was working well.
Best Answer