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?
Answered! Go to the Best Answer.
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 AnswerBased 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
Fitbit Product Experts Alumni are retired members of the Fitbit Product Expert Program. Learn more
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