Skip to content

Commit

Permalink
Add wear de4tect library based on http://forum.espruino.com/conversat…
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Sep 8, 2022
1 parent 691f101 commit ff9a5c4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 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);
});
};

0 comments on commit ff9a5c4

Please sign in to comment.