shake.js
shake.js copied to clipboard
Calibrate threshold
I noticed that threshold needs to be adjusted from device to device. There isn't a way to calibrate it?
If yourself or anyone else can find a reliable way to do this pull requests are welcome
You take a direct difference between accelerations (https://github.com/alexgibson/shake.js/blob/master/shake.js#L100) without accounting for the sampling frequency. That means that any variance in sampling frequency will change the effective threshold. You should at a minimum divide the difference by e.interval
, and ideally perform smoothing on the values to simulate a consistent low sampling rate.
Those changes should make this perform near-identically on all devices.