0

I have a method to detect is the amplitude below a threshold.

public boolean amplitude_Detection(double ampA) {
    //Thresholds for amplitude acceleration
    double acceAmplitudeTH = 3.0;
    //Compare value with threshold
    if (ampA < acceAmplitudeTH) {

        return true;
    }
    return false;
}

Then next in my onSensorChanged, I have if statement if the code above return true, I want to pause my sensor for 5 seconds. After 5 seconds, resume the sensor again. However, during my experiment by throwing phone on bed 10 times in a same position. The timer sometimes will be fired twice and sometimes just one. Anyone know what's happening?

    if(algo.amplitude_Detection(ampA))
    {
        //Pause sensors
        pauseSensor();
        Toast.makeText(getBaseContext(), "Pause ", Toast.LENGTH_SHORT).show();
        new CountDownTimer(5000, 1000) {
            public void onTick(long millisUntilFinished) {
                ((TextView)findViewById(R.id.timeCalc)).setText("Time Left: "+millisUntilFinished/1000+"\n"+ampA);
            }

            public void onFinish() {
                ((TextView)findViewById(R.id.timeCalc)).setText("Done");
                resumeSensor();
            }
        }.start();
    }
}
public void pauseSensor()
{
    senManager.unregisterListener(this, sensorAccelerometer);
}
public void resumeSensor() {senManager.registerListener(this, sensorAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);}
Enix Low
  • 13
  • 4

0 Answers0