Wow, that's really odd. Thanks for looking into this!
I wonder whether in that mode the data reported is somehow the difference in acceleration between that and the last event?
I guess what you could do is use the first motion event as a trigger to put the accelerometer back into continuous mode so you can get good readings - then after a second or two of inactivity you could drop back to the low power mode again.
I think you just need something like:
require("puckjsv2-accel-movement").on();
var idleTimeout;
Puck.on('accel',function(a) {
// If cat door is not level, we're not idle
if (a.acc.x < 15000 && idleTimeout) {
clearTimeout(idleTimeout);
idleTimeout = undefined;
}
if (!idleTimeout) { // first call
LED.set();
Puck.accelWr(0x0D,3); // INT1_CTRL - Gyro/accel data ready IRQ
idleTimeout = setTimeout(function() {
idleTimeout = undefined;
Puck.accelWr(0x0D,0x00); // INT1_CTRL - disable - movement only
LED.reset();
},1000);
}
print(a.acc);
});
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.
Wow, that's really odd. Thanks for looking into this!
I wonder whether in that mode the data reported is somehow the difference in acceleration between that and the last event?
I guess what you could do is use the first motion event as a trigger to put the accelerometer back into continuous mode so you can get good readings - then after a second or two of inactivity you could drop back to the low power mode again.
I think you just need something like: