I am developing shake detecting on Android and I can not deal with one issue - rotating the phone. My algorithm detects shakes properly, but it reacts to rotates also.
It looks like this:
//for every second
if(!alarmed) {
if(Math.abs(oldX - acceleration.x) > threshold ||
Math.abs(oldY - acceleration.y) > threshold ||
Math.abs(oldZ - acceleration.z) > threshold) {
// shake detected
}
}
oldX = acceleration.x;
oldY = acceleration.y;
oldZ = acceleration.z;
It's JavaScript, because I write with Cordova.
Any help would be appreciated.
After few hours, I came up with solution:
Instead of comparing all three acceleration dimensions with threshold, we should compare sum of all three with (modified) threshold. It prevents reacting to rotations.