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:step.StepService.java

public void registerDetector() {
    if (mSensorManager != null && mStepDetector != null) {
        mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        mSensorManager.registerListener(mStepDetector, mSensor, SensorManager.SENSOR_DELAY_FASTEST);

        // Step Detector
        mSensorManager.registerListener(mStepDetector2,
                mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER), SensorManager.SENSOR_DELAY_UI);
    }/*  ww  w  . j  a va  2  s .  c  om*/

}

From source file:it.unime.mobility4ckan.MySensor.java

public void registerSensor(Sensor mSensor) {
    LocationListener locationListener = new LocationListener() {
        @Override// ww  w  . j a va  2  s  .  co m
        public void onLocationChanged(Location location) {
            //latitude = location.getLatitude();
            //longitude = location.getLongitude();
            currentSpeed = location.getSpeed();
            //locationText.setText(String.valueOf(latitude)+ "  " +String.valueOf(longitude)+ "  " +String.valueOf(speed));
            //isGPSReady = true;
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            //
        }

        @Override
        public void onProviderEnabled(String provider) {
            //
        }

        @Override
        public void onProviderDisabled(String provider) {
            //
        }
    };

    SensorEventListener sensorListener = new SensorEventListener() {
        @Override
        public void onSensorChanged(SensorEvent event) {

            switch (event.sensor.getType()) {
            case Sensor.TYPE_AMBIENT_TEMPERATURE: // Gradi Celsius (C)
                currentTemp = event.values[0];
                break;

            case Sensor.TYPE_PRESSURE:
                currentPressure = event.values[0]; // hPa o mbar
                break;

            case Sensor.TYPE_LIGHT: // lx
                currentLight = event.values[0];
                break;

            case Sensor.TYPE_ACCELEROMETER: // m/s2
                currentAcceleration[0] = event.values[0];
                currentAcceleration[1] = event.values[1];
                currentAcceleration[2] = event.values[2];
                break;

            case Sensor.TYPE_GYROSCOPE: // rad/s
                currentGyroscope[0] = event.values[0];
                currentGyroscope[1] = event.values[1];
                currentGyroscope[2] = event.values[2];
                break;

            case Sensor.TYPE_MAGNETIC_FIELD: // T
                currentMagnetic[0] = event.values[0];
                currentMagnetic[1] = event.values[1];
                currentMagnetic[2] = event.values[2];
                break;

            case Sensor.TYPE_PROXIMITY: // cm
                currentProximity = event.values[0];
                break;

            case Sensor.TYPE_ROTATION_VECTOR: // unita di misura sconosciuta
                currentRotation[0] = event.values[0];
                currentRotation[1] = event.values[1];
                currentRotation[2] = event.values[2];
                break;

            case Sensor.TYPE_GRAVITY: // m/s2
                currentGravity[0] = event.values[0];
                currentGravity[1] = event.values[1];
                currentGravity[2] = event.values[2];
                break;

            case Sensor.TYPE_LINEAR_ACCELERATION: // m/s2
                currentLinearAcceleration[0] = event.values[0];
                currentLinearAcceleration[1] = event.values[1];
                currentLinearAcceleration[2] = event.values[2];
                break;

            case Sensor.TYPE_RELATIVE_HUMIDITY: // %
                currentHumidity = event.values[0];
                break;

            default:
                break;
            }

        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {

        }
    };

    //sensorManager.registerListener(locationListener, mSensor, LocationManager.GPS_PROVIDER);
    /*        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    // TODO: Consider calling
    //    ActivityCompat#requestPermissions
    // here to request the missing permissions, and then overriding
    //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
    //                                          int[] grantResults)
    // to handle the case where the user grants the permission. See the documentation
    // for ActivityCompat#requestPermissions for more details.
    return;
            }*/
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    sensorManager.registerListener(sensorListener, mSensor, SensorManager.SENSOR_DELAY_FASTEST);
}

From source file:com.phonegap.AccelListener.java

/**
 * Start listening for acceleration sensor.
 * //from ww  w . ja  v a 2s.c  o  m
 * @return          status of listener
 */
public int start() {

    // If already starting or running, then just return
    if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) {
        return this.status;
    }

    // Get accelerometer from sensor manager
    List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);

    // If found, then register as listener
    if ((list != null) && (list.size() > 0)) {
        this.mSensor = list.get(0);
        this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_FASTEST);
        this.setStatus(AccelListener.STARTING);
        this.lastAccessTime = System.currentTimeMillis();
    }

    // If error, then set status to error
    else {
        this.setStatus(AccelListener.ERROR_FAILED_TO_START);
    }

    return this.status;
}

From source file:it.unime.mobility4ckan.MySensor.java

void registerTempSensor() {
    tempSensorListener = new SensorEventListener() {
        @Override/*from w  w w  .j  ava2s. c  om*/
        public void onSensorChanged(SensorEvent event) {
            if (event.sensor.getType() == Sensor.TYPE_AMBIENT_TEMPERATURE)
                currentTemp = event.values[0];
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {

        }
    };

    sensorManager.registerListener(tempSensorListener, tempSensor, SensorManager.SENSOR_DELAY_FASTEST);
}

From source file:it.unime.mobility4ckan.MySensor.java

void registerPressureSensor() {
    pressureSensorListener = new SensorEventListener() {
        @Override/*  ww w.j a v a 2s. c  om*/
        public void onSensorChanged(SensorEvent event) {
            if (event.sensor.getType() == Sensor.TYPE_PRESSURE) {
                currentPressure = event.values[0];
            }
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {

        }
    };

    sensorManager.registerListener(pressureSensorListener, pressureSensor, SensorManager.SENSOR_DELAY_FASTEST);
}

From source file:name.setup.dance.StepService.java

private void registerDetector() {
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER /*| 
                                                                        Sensor.TYPE_MAGNETIC_FIELD | 
                                                                        Sensor.TYPE_ORIENTATION*/);
    mSensorManager.registerListener(mStepDetector, mSensor, SensorManager.SENSOR_DELAY_FASTEST);
}

From source file:it.unime.mobility4ckan.MySensor.java

void registerLightSensor() {
    lightSensorListener = new SensorEventListener() {
        @Override/*from w ww. j  a  v a2 s. c om*/
        public void onSensorChanged(SensorEvent event) {
            if (event.sensor.getType() == Sensor.TYPE_LIGHT) {
                currentLight = event.values[0];
            }
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {

        }
    };

    sensorManager.registerListener(lightSensorListener, lightSensor, SensorManager.SENSOR_DELAY_FASTEST);
}

From source file:com.inloc.dr.StepService.java

private void registerDetector() {
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER /*| 
                                                                        Sensor.TYPE_MAGNETIC_FIELD | 
                                                                        Sensor.TYPE_ORIENTATION*/);
    mSensorManager.registerListener(mStepDetector, mSensor, SensorManager.SENSOR_DELAY_FASTEST);
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mSensorManager.registerListener(mTurnDetector, mSensor, SensorManager.SENSOR_DELAY_GAME);
}

From source file:org.chromium.latency.walt.AccelerometerFragment.java

@Override
public void onResume() {
    super.onResume();
    logTextView.setText(logger.getLogText());
    logger.registerReceiver(logReceiver);
    startButton.setOnClickListener(this);
    sensorManager.registerListener(AccelerometerFragment.this, accelerometer,
            SensorManager.SENSOR_DELAY_FASTEST);
}

From source file:com.bolatu.gezkoncsvlogger.GyroOrientation.GyroscopeOrientation.java

/**
 * Reinitialize the sensor and filter./*  w ww .  ja v a  2  s. c  o m*/
 */
public void reset() {
    // copy the new gyro values into the gyro array
    // convert the raw gyro data into a rotation vector
    deltaVGyroscope = new double[4];

    vOrientation = new float[3];
    qvOrientation = new float[4];

    // rotation matrix from gyro data
    rmGyroscope = new float[9];

    qGyroscopeDelta = null;
    qGyroscope = null;

    isOrientationValidAccelMag = false;

    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);
}