I developed an application that tracks when I am moving with the accelerometer, and I can vibrate the phone depending on the various thresholds that I may have pressed. One of the problems that I have encountered is that this vibration directly distorts the accelerometer data.
This answer suggested using a low-pass filter, but I don’t think it would work in this application (I need relatively fast response times and vibrations cause big bursts in the data).
The solution I am currently using is to set the flag to true before the phone vibrates, call a function postDelayedthat will return it false after a certain time (1 second is ok) and in onSensorChanged, just return if the flag is true.
In other words:
isPhoneVibrating = true; // Start to vibrate
phoneVibrator.vibrate(VibratePattern, -1);
mHandler.postDelayed(vibrateSensorOff, 1000); // 1 seconds wait before making false
vibrateSensorOff contains only
isPhoneVibrating = false;
and, as I said, in the function onSensorChangedI return if the flag isPhoneVibratingis true.
I do not like this solution because I need to manage this extra flag in different states of this application. Are there other possible solutions that do not require an additional flag?
source
share