Browse Source

Threshold angepasst

master
Patrick Halboth 3 years ago
parent
commit
a685f972bf
1 changed files with 7 additions and 5 deletions
  1. 7
    5
      app/src/main/java/de/edotzlaff/detection/MainActivity.java

+ 7
- 5
app/src/main/java/de/edotzlaff/detection/MainActivity.java View File

@@ -69,7 +69,7 @@ public class MainActivity extends AppCompatActivity {
//##########################################################################################################################################################################
//################################################################## vvv SensorParameter vvv ##############################################################################
private SensorManager mSensorManager;
private static final float mUpperThreshold = 1.0f; // für Emulator auf 1.5 setzen
private static final float mUpperThreshold = 0.075f; // für Emulator auf 1.5 setzen
private static final float mLowerThreshold = 0.5f; // für Emulator auf 0.5 setzen
private static final long mShakeDetectionLockTimeMicroSeconds = 3500;
private float mAccel;
@@ -101,15 +101,17 @@ public class MainActivity extends AppCompatActivity {
{
//TextView txtEarthquake = (TextView) findViewById(R.id.txtEarthquake);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
mAccel = 1f;
Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST);
mAccel = 0.05f;
mAccelCurrent = SensorManager.GRAVITY_EARTH;
mAccelLast = SensorManager.GRAVITY_EARTH;
mShakeDetectionIsActive = false;
mShakeDetected = false;

}

private final SensorEventListener mSensorListener = new SensorEventListener() {

@Override
public void onSensorChanged(SensorEvent event) {
float x = event.values[0];
@@ -119,11 +121,11 @@ public class MainActivity extends AppCompatActivity {
mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z));
float delta = mAccelCurrent - mAccelLast;
mAccel = mAccel * 0.9f + delta;
// Log.d(TAG,"mAccel: "+ mAccel);
Log.d(TAG,"mAccel: "+ mAccel);
if (mShakeDetectionIsActive && !mShakeDetected) {
if(Math.abs(mAccel) > mUpperThreshold) {

new CountDownTimer(1000, 10) {
new CountDownTimer(750, 10) {

public void onTick(long millisUntilFinished) {
mShakeDetectionIsActive = false;

Loading…
Cancel
Save