diff --git a/modules/wear_detect.js b/modules/wear_detect.js new file mode 100644 index 0000000000..62b1ae3629 --- /dev/null +++ b/modules/wear_detect.js @@ -0,0 +1,20 @@ +/** Returns a promise that resolves with whether the Bangle +is worn or not. + +Usage: + +require("wear_detect").isWorn().then(worn => { + console.log(worn ? "is worn" : "not worn"); +}); +*/ +exports.isWorn = function() { + return new Promise(resolve => { + if (Bangle.isCharging()) + return resolve(false); + if (E.getTemperature() > 24.625) + return resolve(true); + if (Bangle.getAccel().mag > 1.045) + return resolve(true); + return resolve(false); + }); +};