Example usage for android.hardware SensorManager SENSOR_DELAY_FASTEST

List of usage examples for android.hardware SensorManager SENSOR_DELAY_FASTEST

Introduction

In this page you can find the example usage for android.hardware SensorManager SENSOR_DELAY_FASTEST.

Prototype

int SENSOR_DELAY_FASTEST

To view the source code for android.hardware SensorManager SENSOR_DELAY_FASTEST.

Click Source Link

Document

get sensor data as fast as possible

Usage

From source file:com.kircherelectronics.androidlinearacceleration.sensor.LinearAccelerationSensor.java

/**
 * Register for Sensor.TYPE_ACCELEROMETER measurements.
 * /*from   w  ww . j  a  v  a2 s.co  m*/
 * @param observer
 *            The observer to be registered.
 */
public void registerAccelerationObserver(LinearAccelerationSensorObserver observer) {
    // If there are currently no observers, but one has just requested to be
    // registered, register to listen for sensor events from the device.
    if (observersAcceleration.size() == 0) {
        sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
                SensorManager.SENSOR_DELAY_FASTEST);
    }

    // Only register the observer if it is not already registered.
    int i = observersAcceleration.indexOf(observer);
    if (i == -1) {
        observersAcceleration.add(observer);
    }

}

From source file:ch.bfh.sensordataprocessor.sensor.SensorDisplayFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View layout = inflater.inflate(R.layout.sensor_view, null);

    sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    name = (TextView) layout.findViewById(R.id.name);
    type = (TextView) layout.findViewById(R.id.type);
    maxRange = (TextView) layout.findViewById(R.id.maxRange);
    minDelay = (TextView) layout.findViewById(R.id.minDelay);
    power = (TextView) layout.findViewById(R.id.power);
    resolution = (TextView) layout.findViewById(R.id.resolution);
    vendor = (TextView) layout.findViewById(R.id.vendor);
    version = (TextView) layout.findViewById(R.id.version);
    accuracy = (TextView) layout.findViewById(R.id.accuracy);
    timestampLabel = (TextView) layout.findViewById(R.id.timestampLabel);
    timestamp = (TextView) layout.findViewById(R.id.timestamp);
    timestampUnits = (TextView) layout.findViewById(R.id.timestampUnits);
    dataLabel = (TextView) layout.findViewById(R.id.dataLabel);
    dataUnits = (TextView) layout.findViewById(R.id.dataUnits);
    xAxis = (TextView) layout.findViewById(R.id.xAxis);
    xAxisLabel = (TextView) layout.findViewById(R.id.xAxisLabel);
    yAxis = (TextView) layout.findViewById(R.id.yAxis);
    yAxisLabel = (TextView) layout.findViewById(R.id.yAxisLabel);
    zAxis = (TextView) layout.findViewById(R.id.zAxis);
    zAxisLabel = (TextView) layout.findViewById(R.id.zAxisLabel);
    singleValue = (TextView) layout.findViewById(R.id.singleValue);
    cosLabel = (TextView) layout.findViewById(R.id.cosLabel);
    cos = (TextView) layout.findViewById(R.id.cos);

    layout.findViewById(R.id.delayFastest).setOnClickListener(new OnClickListener() {
        @Override//from   w  ww  . j  a v  a2 s.  c om
        public void onClick(View v) {
            sensorManager.unregisterListener(SensorDisplayFragment.this);
            sensorManager.registerListener(SensorDisplayFragment.this, sensor,
                    SensorManager.SENSOR_DELAY_FASTEST);
        }
    });

    layout.findViewById(R.id.delayGame).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            sensorManager.unregisterListener(SensorDisplayFragment.this);
            sensorManager.registerListener(SensorDisplayFragment.this, sensor, SensorManager.SENSOR_DELAY_GAME);
        }
    });

    layout.findViewById(R.id.delayNormal).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            sensorManager.unregisterListener(SensorDisplayFragment.this);
            sensorManager.registerListener(SensorDisplayFragment.this, sensor,
                    SensorManager.SENSOR_DELAY_NORMAL);
        }
    });

    layout.findViewById(R.id.delayUi).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            sensorManager.unregisterListener(SensorDisplayFragment.this);
            sensorManager.registerListener(SensorDisplayFragment.this, sensor, SensorManager.SENSOR_DELAY_UI);
        }
    });

    return layout;
}

From source file:com.kircherelectronics.fusedgyroscopeexplorer.sensor.MagneticSensor.java

/**
 * Register for Sensor.TYPE_MAGNETIC measurements.
 * //from   www  .java2 s .  c  om
 * @param observer
 *            The observer to be registered.
 */
public void registerMagneticObserver(MagneticSensorObserver observer) {
    if (observersMagnetic.size() == 0) {
        sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                SensorManager.SENSOR_DELAY_FASTEST);
    }

    // Only register the observer if it is not already registered.
    int i = observersMagnetic.indexOf(observer);
    if (i == -1) {
        observersMagnetic.add(observer);
    }
}

From source file:com.kircherelectronics.fusedgyroscopeexplorer.sensor.GyroscopeSensor.java

/**
 * Register for Sensor.TYPE_GYROSCOPE measurements.
 * /*from   ww w .  java2s.co  m*/
 * @param observer
 *            The observer to be registered.
 */
public void registerGyroscopeObserver(GyroscopeSensorObserver observer) {
    if (observersGyroscope.size() == 0) {
        boolean enabled = sensorManager.registerListener(this,
                sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_FASTEST);

        if (!enabled) {
            showGyroscopeNotAvailableAlert();
        }
    }

    // Only register the observer if it is not already registered.
    int i = observersGyroscope.indexOf(observer);
    if (i == -1) {
        observersGyroscope.add(observer);
    }
}

From source file:pl.mrwojtek.sensrec.app.SamplingPeriodDialog.java

@Override
public void onClick(DialogInterface dialog, int which) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    int position = samplingSpinner.getSelectedItemPosition();
    if (position == POSITION_CUSTOM) {
        try {/* w w  w.  j  av  a2  s.  c o m*/
            long delay = Long.valueOf(millisecondsEdit.getText().toString());
            prefs.edit().putLong(SensorsRecorder.PREF_SAMPLING_PERIOD, delay).apply();
        } catch (NumberFormatException ex) {
            Log.i(TAG, "Unable to save sampling delay: " + ex.getMessage());
        }
    } else if (position == POSITION_NORMAL) {
        prefs.edit().putLong(SensorsRecorder.PREF_SAMPLING_PERIOD, SensorManager.SENSOR_DELAY_NORMAL).apply();
    } else if (position == POSITION_UI) {
        prefs.edit().putLong(SensorsRecorder.PREF_SAMPLING_PERIOD, SensorManager.SENSOR_DELAY_UI).apply();
    } else if (position == POSITION_GAME) {
        prefs.edit().putLong(SensorsRecorder.PREF_SAMPLING_PERIOD, SensorManager.SENSOR_DELAY_GAME).apply();
    } else if (position == POSITION_FASTEST) {
        prefs.edit().putLong(SensorsRecorder.PREF_SAMPLING_PERIOD, SensorManager.SENSOR_DELAY_FASTEST).apply();
    }
}

From source file:com.kircherelectronics.fusedgyroscopeexplorer.sensor.GravitySensor.java

/**
 * Register for Sensor.TYPE_GRAVITY measurements.
 * //from www .  j  ava2  s .  c o m
 * @param observer
 *            The observer to be registered.
 */
public void registerGravityObserver(GravitySensorObserver observer) {
    // If there are currently no observers, but one has just requested to be
    // registered, register to listen for sensor events from the device.
    if (observersAcceleration.size() == 0) {
        sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY),
                SensorManager.SENSOR_DELAY_FASTEST);
    }

    // Only register the observer if it is not already registered.
    int i = observersAcceleration.indexOf(observer);
    if (i == -1) {
        observersAcceleration.add(observer);
    }
}

From source file:com.kircherelectronics.gyroscopeexplorer.activity.GyroscopeActivity.java

public void onResume() {
    super.onResume();

    requestPermissions();/*from  w w w  . j  av  a  2 s .  c om*/
    readPrefs();
    reset();

    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_FASTEST);

    // Register for sensor updates.
    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
            SensorManager.SENSOR_DELAY_FASTEST);

    // Register for sensor updates.
    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE),
            SensorManager.SENSOR_DELAY_FASTEST);

    handler.post(runable);
}

From source file:fr.bde_eseo.eseomega.GantierActivity.java

public void initListeners() {
    senSensorManager.registerListener(this, senSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_FASTEST);

    senSensorManager.registerListener(this, senSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE),
            SensorManager.SENSOR_DELAY_FASTEST);

    senSensorManager.registerListener(this, senSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
            SensorManager.SENSOR_DELAY_FASTEST);
}

From source file:com.kircherelectronics.gyroscopeexplorer.activity.filter.Orientation.java

public void onResume() {
    calibratedGyroscopeEnabled = getPrefCalibratedGyroscopeEnabled();
    meanFilterSmoothingEnabled = getPrefMeanFilterSmoothingEnabled();
    meanFilterTimeConstant = getPrefMeanFilterSmoothingTimeConstant();

    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_FASTEST);

    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
            SensorManager.SENSOR_DELAY_FASTEST);

    if (calibratedGyroscopeEnabled) {
        sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE),
                SensorManager.SENSOR_DELAY_FASTEST);
    } else {//from   w  w w .  j  av a  2  s.c o  m
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
            sensorManager.registerListener(this,
                    sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE_UNCALIBRATED),
                    SensorManager.SENSOR_DELAY_FASTEST);
        }
    }
}

From source file:com.kircherelectronics.accelerationexplorer.activity.NoiseActivity.java

@Override
public void onResume() {
    super.onResume();

    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_FASTEST);

    lpf.setTimeConstant(getPrefLpfSmoothingTimeConstant());

    meanFilter.setTimeConstant(getPrefMeanFilterSmoothingTimeConstant());

    medianFilter.setTimeConstant(getPrefMedianFilterSmoothingTimeConstant());

    handler.post(runable);/*from   w w w  .j  a  va 2  s  .  co m*/
}