I made it so it returns a promise, because I think there's a good chance that the code will need changing and may need to do some things (like waiting for an HRM reading) that don't return immediately.
I think there is a potential for the library to emit a 'worn' event as well (which probably makes a lot of sense) but I imagine @splch is thinking that in cases like alarms they might want to just check instantaneously at the point they were thinking of making a noise.
In terms of the checks, I think a few things would need improving:
as @Ganblejs says, temperature may end up being too low
Checking Bangle.getAccel().mag once is unlikely to be a good way to check movement, since it checks movement only over a 1/12.5 sec period. You probably want Bangle.getHealthStatus().movement (see http://www.espruino.com/Reference#l_Bangle_getHealthStatus) but again, this works in 10 minute blocks, so some work probably needs to be done (maybe checking Bangle.getHealthStatus('day').movement once every 10 seconds and comparing?) to ensure that you check the full amount of movement over a period of a few seconds
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.
Comments on the PR at https://github.com/espruino/Espruino/pull/2264 but I just added the code mentioned above as a library: https://github.com/espruino/BangleApps/commit/ff9a5c4c20bc95fd0d628bd7041f71753a1edf6c
I made it so it returns a promise, because I think there's a good chance that the code will need changing and may need to do some things (like waiting for an HRM reading) that don't return immediately.
I think there is a potential for the library to emit a 'worn' event as well (which probably makes a lot of sense) but I imagine @splch is thinking that in cases like alarms they might want to just check instantaneously at the point they were thinking of making a noise.
In terms of the checks, I think a few things would need improving:
Bangle.getAccel().mag
once is unlikely to be a good way to check movement, since it checks movement only over a 1/12.5 sec period. You probably wantBangle.getHealthStatus().movement
(see http://www.espruino.com/Reference#l_Bangle_getHealthStatus) but again, this works in 10 minute blocks, so some work probably needs to be done (maybe checkingBangle.getHealthStatus('day').movement
once every 10 seconds and comparing?) to ensure that you check the full amount of movement over a period of a few seconds