I use OpenIntents SensorSimulator
In code i wrote
public float accelerometer_shake_threshold = 1.2f;
static final int ACCELEROMETER_FLOAT_TO_INT = 1024;
int mACCELEROMETER_SHAKE_THRESHOLD_SQUARE;
public void onSensorChanged(int sensor, float[] values){
if( sensor == SensorManager.SENSOR_ACCELEROMETER){
int t = (int)(ACCELEROMETER_FLOAT_TO_INT *
accelerometer_shake_threshold);
mACCELEROMETER_SHAKE_THRESHOLD_SQUARE = t * t;
android.util.Log.i("Answer",String.valueOf
(values[0]));
android.util.Log.i("Answer",String.valueOf(values[1]));
android.util.Log.i("Answer",String.valueOf(values[2]));
int ax = (int)(ACCELEROMETER_FLOAT_TO_INT *
values[0]);
int ay = (int)(ACCELEROMETER_FLOAT_TO_INT * values[1]);
int az = (int)(ACCELEROMETER_FLOAT_TO_INT * values[2]);
int len2 = ax * ax + ay * ay + az * az;
android.util.Log.i("LEN is",Integer.toString(len2));
if (len2 < mACCELEROMETER_SHAKE_THRESHOLD_SQUARE) {
Log.v(TAG,"Force Detected");
TextView tv=(TextView)findViewById
(R.id.found);
tv.setText("ViolentForce Detected");
}
I could not get the desired result ,the value of len2
is seems
to be constant for any movement I give through the sensor simulator
(Yaw,Roll and Pitch).If the len2 is constant value then what could be
the purpose of the if statement .
I just blindly followed the code snippet given under" Detecting
"Shake" With The Accelerometer"(
http://www.anddev.org/example_detecting_-und-quotshake-und-quot_with_the_accelerometer-t4451.html
) .
In few examples i came across the len2 values is compared with cube
root of gravity(being a newb its Greek to me ) Help me out to know
the concept to detect a violent shake .What kind of physics is used to
detect this sense .
Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---