Add wear de4tect library based on http://forum.espruino.com/conversations/379538/ and https://github.com/espruino/Espruino/pull/2264
parent
691f10165e
commit
ff9a5c4c20
|
|
@ -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);
|
||||||
|
});
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue