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

setInterval()/setTimeout() not firing on time when display is off

ANSWERED

I'm working on a metronome app for my Fitbit Sense, and I want the watch to vibrate at regular intervals. It works great while the display is on, or while the developer bridge is enabled. Once the display turns off, however, the interval fires unreliably (e.g., when set to 500 ms, it only fires once a second or so).

 

This is a trivial reproducer:

 

import { vibration } from "haptics";
setInterval(() => vibration.start("nudge-max"), 500);

 

Sideload this, then disable the developer bridge in settings, then start the app. While the display is on, it will vibrate twice a second. Once the display turns off, it will be sporadic.

 

The Fitbit Sense doesn't seem to allow display.autoOff = false, so I can't use that as a workaround. setTimeout() seems to suffer from the same issue.

 

I found a similar issue, but it had no solution. So, I'll ask again: how can I use setInterval() reliably while the display is off?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

In the end, I got it to work by adding a delayed vibration.stop:

import { vibration } from "haptics";
setInterval(() => {
  vibration.start("nudge-max");
  setTimeout(vibration.stop, 150);
}, 500);

 I still don't understand why this workaround is only needed when the display is off.

View best answer in original post

Best Answer
0 Votes
4 REPLIES 4

Based on another post and my own testing, it looks like the intervals themselves are actually firing. It's the vibration that doesn't go through. vibration.start() is returning false. I don't understand why this only happens when the screen is off, since that return value isn't documented.

Best Answer
0 Votes

Try display.poke every 7 seconds. 

 

This will keep the display on permanently and it should be reliable enough.

Author | ch, passion for improvement.

Best Answer
0 Votes

I wonder, whether the problem might be, that the call itself "consumes" and so might produce a delay on device ... (just a thought)

Best Answer
0 Votes

In the end, I got it to work by adding a delayed vibration.stop:

import { vibration } from "haptics";
setInterval(() => {
  vibration.start("nudge-max");
  setTimeout(vibration.stop, 150);
}, 500);

 I still don't understand why this workaround is only needed when the display is off.

Best Answer
0 Votes