Gordon Williams 2022-09-08 10:40:03 +01:00
parent 691f10165e
commit ff9a5c4c20
1 changed files with 20 additions and 0 deletions

20
modules/wear_detect.js Normal file
View File

@ -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);
});
};