12-21-2018 02:05
12-21-2018 02:05
Hi,
I'm new to Fitbit OS programming. To get familiar with the code, I'm trying to create a watch face which displays the time in a binary way. Not usefull, I know, but it's just for testing. Showing the time in binary way is OK, but now I added 2 buttons to toggle between binary and decimal display. The code below is not complete yet, but the problem is that every second the toggle swithes back to Binary. If I click the Decimal button, the values in the console logs change, so they work :). How do I prevent this behaviour, so that the buttons don't toggle back every update of the screen?
thx, Ben
// Update the clock every second
clock.granularity = "seconds";
// Get a handle on the <text> elements
const labelHoursMinutes = document.getElementById("labelHoursMinutes");
const labelSeconds = document.getElementById("labelSeconds");
const buttonBinary = document.getElementById("buttonBinary");
const buttonDecimal = document.getElementById("buttonDecimal");
// Update the <text> element every tick with the current time
clock.ontick = (evt) => {
let today = evt.date;
let hours = today.getHours();
let mins = today.getMinutes();
let seconds = today.getSeconds();
console.log("ButtonBinary: " + buttonBinary.value);
console.log("ButtonDecimal: " + buttonDecimal.value);
if (buttonBinary.value = 1) {
// Convert to bin
hours = util.zeroPad(util.toBin(hours));
mins = util.zeroPad(util.toBin(mins));
seconds = util.zeroPad(util.toBin(seconds));
}
labelHoursMinutes.text = `${hours}:${mins}`;
labelSeconds.text = `${seconds}`;
}
Answered! Go to the Best Answer.
Best Answer01-08-2019 10:26
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.
01-08-2019 10:26
The problem is this line:
if (buttonBinary.value = 1) {
You're actually setting .value to 1, not checking its value.
You want
if (buttonBinary.value === 1) {
01-08-2019 10:26
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.
01-08-2019 10:26
The problem is this line:
if (buttonBinary.value = 1) {
You're actually setting .value to 1, not checking its value.
You want
if (buttonBinary.value === 1) {
01-08-2019 23:09
01-08-2019 23:09
Thx! As I said, new to Fitbit Dev / Java script 🙂 🙂
Best Answer