Another idea: just look at the accelerometer with a timeout?
(function(){ let timeout; function setWorn(worn) { worn = !!worn; // undefined -> false if (timeout) clearTimeout(timeout); if (Bangle.isWorn === worn) return; // no change Bangle.isWorn = worn; Bangle.emit('worn', worn); } Bangle.on('accel', xyz => { if (Bangle.isCharging()) { setWorn(false); } else if (xyz.diff) { // or Math.abs(xyz.diff) > 0.01? setWorn(true); // no movement for 1 minute timeout = setTimeout(setWorn, 60000); } }); Bangle.on('charging', charging => { // assume charging ends = watch picked up setWorn(!charging); }); })()
But I guess constantly running code for accell events might not be great for battery life :-(
accell
@rigrig started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Another idea: just look at the accelerometer with a timeout?
But I guess constantly running code for
accell
events might not be great for battery life :-(