Example usage for android.hardware Sensor TYPE_GYROSCOPE

List of usage examples for android.hardware Sensor TYPE_GYROSCOPE

Introduction

In this page you can find the example usage for android.hardware Sensor TYPE_GYROSCOPE.

Prototype

int TYPE_GYROSCOPE

To view the source code for android.hardware Sensor TYPE_GYROSCOPE.

Click Source Link

Document

A constant describing a gyroscope sensor type.

Usage

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

@Override
public void onSensorChanged(SensorEvent event) {

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        // Get a local copy of the raw magnetic values from the device
        // sensor.

        event.values[2] = event.values[2] + 90;
        System.arraycopy(event.values, 0, this.vAcceleration, 0, this.vGyroscope.length);

        if (meanFilterSmoothingEnabled) {

            this.vAcceleration = meanFilterAcceleration.addSamples(this.vAcceleration);
        }//from ww w.  j a va2  s .  c o m

        // We fuse the orientation of the magnetic and acceleration sensor
        // based on acceleration sensor updates. It could be done when the
        // magnetic sensor updates or when they both have updated if you
        // want to spend the resources to make the checks.
        calculateOrientationAccelMag();
    }

    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        // Get a local copy of the raw magnetic values from the device
        // sensor.
        System.arraycopy(event.values, 0, this.vMagnetic, 0, this.vGyroscope.length);

        if (meanFilterSmoothingEnabled) {
            this.vMagnetic = meanFilterMagnetic.addSamples(this.vMagnetic);
        }
    }

    if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
        System.arraycopy(event.values, 0, this.vGyroscope, 0, this.vGyroscope.length);

        if (meanFilterSmoothingEnabled) {
            this.vGyroscope = meanFilterGyroscope.addSamples(this.vGyroscope);
        }

        timeStampGyroscope = event.timestamp;

        onGyroscopeChanged();
    }

    if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) {
        System.arraycopy(event.values, 0, this.vGyroscope, 0, this.vGyroscope.length);

        if (meanFilterSmoothingEnabled) {
            this.vGyroscope = meanFilterGyroscope.addSamples(this.vGyroscope);
        }

        timeStampGyroscope = event.timestamp;

        onGyroscopeChanged();
    }

}

From source file:com.android.plugins.GyroscopeListener.java

/**
 * Start listening for speed sensor.//from  w  ww.j  ava2 s . co m
 *
 * @return          status of listener
*/
private int start() {
    // If already starting or running, then just return
    if ((this.status == GyroscopeListener.RUNNING) || (this.status == GyroscopeListener.STARTING)) {
        return this.status;
    }

    this.setStatus(GyroscopeListener.STARTING);

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

    // 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_UI);
        this.setStatus(GyroscopeListener.STARTING);
    } else {
        this.setStatus(GyroscopeListener.ERROR_FAILED_TO_START);
        this.fail(GyroscopeListener.ERROR_FAILED_TO_START,
                "No sensors found to register gyroscope listening to.");
        return this.status;
    }

    // Set a timeout callback on the main thread.
    stopTimeout();
    mainHandler = new Handler(Looper.getMainLooper());
    mainHandler.postDelayed(mainRunnable, 2000);

    return this.status;
}

From source file:org.dartlang.phonegap.gyroscope.GyroscopeListener.java

/**
 * Start listening for speed sensor./*  w w w  .  j a  va2s.  c  om*/
 * 
 * @return          status of listener
*/
private int start() {
    // If already starting or running, then just return
    if ((this.status == GyroscopeListener.RUNNING) || (this.status == GyroscopeListener.STARTING)) {
        return this.status;
    }

    this.setStatus(GyroscopeListener.STARTING);

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

    // 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_GAME);
        this.setStatus(GyroscopeListener.STARTING);
    } else {
        this.setStatus(GyroscopeListener.ERROR_FAILED_TO_START);
        this.fail(GyroscopeListener.ERROR_FAILED_TO_START,
                "No sensors found to register gyroscope listening to.");
        return this.status;
    }

    // Set a timeout callback on the main thread.
    stopTimeout();
    mainHandler = new Handler(Looper.getMainLooper());
    mainHandler.postDelayed(mainRunnable, 2000);

    return this.status;
}

From source file:com.example.appf.CS3570.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();//from  www .  j a  va2s .c  o  m
    Bundle extras = intent.getExtras();
    cam = false;

    // Just in case we are coming from the ServerActivity
    if (extras != null) {
        if (extras.containsKey("server_name"))
            SERVER_IP = extras.getString("server_name");
        if (extras.containsKey("server_port"))
            SERVERPORT = Integer.parseInt(extras.getString("server_port"));
    }
    filter = new IMUfilter(.1f, 5);
    filter.reset();

    // Set up reset button
    Button b = new Button(this);
    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            filter.reset();
        }
    });
    b.setText("Reset");

    // Set up camera mode. Are we going to use this?
    Button c = new Button(this);
    c.setText("Camera Mode");
    c.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            filter.reset();
            mGLView.mRenderer.mCamera = new Camera();
            cam = !cam;
        }
    });
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.setBackgroundColor(Color.parseColor("#21C9FF"));
    ll.addView(b);
    ll.addView(c);
    // Create a GLSurfaceView instance and set it
    // as the ContentView for this Activity
    mGLView = new MyGLSurfaceView(this, this);
    ll.addView(mGLView);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    gyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    setContentView(ll);
    new Thread(new SocketThread()).start();
}

From source file:com.microsoft.band.sdksample.SensorsFragment.java

@Override
public void onSensorChanged(SensorEvent sensorEvent) {
    Sensor mySensor = sensorEvent.sensor;

    if (mySensor.getType() == Sensor.TYPE_GYROSCOPE) {
        temp_list[3] = (double) sensorEvent.values[0] * 180 / Math.PI;
        temp_list[4] = (double) sensorEvent.values[1] * 180 / Math.PI;
        temp_list[5] = (double) sensorEvent.values[2] * 180 / Math.PI;
        mTextAngX.setText(String.format("%.2f", temp_list[3]));
        mTextAngY.setText(String.format("%.2f", temp_list[4]));
        mTextAngZ.setText(String.format("%.2f", temp_list[5]));
    } else if (mySensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        temp_list[0] = (double) sensorEvent.values[0];
        temp_list[1] = (double) sensorEvent.values[1];
        temp_list[2] = (double) sensorEvent.values[2];
        mTextAccX.setText(String.format("%.3f", temp_list[0]));
        mTextAccY.setText(String.format("%.3f", temp_list[1]));
        mTextAccZ.setText(String.format("%.3f", temp_list[2]));
    }//from  w w w.  j a v a2 s . co m
}

From source file:devbox.com.br.minercompanion.ProfileActivity.java

@Override
protected void onResume() {
    super.onResume();
    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), sensorManager.SENSOR_DELAY_GAME);
    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), sensorManager.SENSOR_DELAY_GAME);
    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), sensorManager.SENSOR_DELAY_NORMAL);
    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT), sensorManager.SENSOR_DELAY_NORMAL);
}

From source file:com.vonglasow.michael.satstat.SensorSectionFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mainActivity = (MainActivity) this.getContext();
    View rootView = inflater.inflate(R.layout.fragment_main_sensors, container, false);

    Sensor mAccSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    Sensor mGyroSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    Sensor mMagSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    Sensor mLightSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    Sensor mProximitySensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    Sensor mPressureSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
    Sensor mHumiditySensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);
    Sensor mTempSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);

    mAccSensorRes = getSensorDecimals(mAccSensor, mAccSensorRes);
    mGyroSensorRes = getSensorDecimals(mGyroSensor, mGyroSensorRes);
    mMagSensorRes = getSensorDecimals(mMagSensor, mMagSensorRes);
    mLightSensorRes = getSensorDecimals(mLightSensor, mLightSensorRes);
    mProximitySensorRes = getSensorDecimals(mProximitySensor, mProximitySensorRes);
    mPressureSensorRes = getSensorDecimals(mPressureSensor, mPressureSensorRes);
    mHumiditySensorRes = getSensorDecimals(mHumiditySensor, mHumiditySensorRes);
    mTempSensorRes = getSensorDecimals(mTempSensor, mTempSensorRes);

    // Initialize controls
    accStatus = (TextView) rootView.findViewById(R.id.accStatus);
    accHeader = (TextView) rootView.findViewById(R.id.accHeader);
    accX = (TextView) rootView.findViewById(R.id.accX);
    accY = (TextView) rootView.findViewById(R.id.accY);
    accZ = (TextView) rootView.findViewById(R.id.accZ);
    accTotal = (TextView) rootView.findViewById(R.id.accTotal);
    rotStatus = (TextView) rootView.findViewById(R.id.rotStatus);
    rotHeader = (TextView) rootView.findViewById(R.id.rotHeader);
    rotX = (TextView) rootView.findViewById(R.id.rotX);
    rotY = (TextView) rootView.findViewById(R.id.rotY);
    rotZ = (TextView) rootView.findViewById(R.id.rotZ);
    rotTotal = (TextView) rootView.findViewById(R.id.rotTotal);
    magStatus = (TextView) rootView.findViewById(R.id.magStatus);
    magHeader = (TextView) rootView.findViewById(R.id.magHeader);
    magX = (TextView) rootView.findViewById(R.id.magX);
    magY = (TextView) rootView.findViewById(R.id.magY);
    magZ = (TextView) rootView.findViewById(R.id.magZ);
    magTotal = (TextView) rootView.findViewById(R.id.magTotal);
    orStatus = (TextView) rootView.findViewById(R.id.orStatus);
    orHeader = (TextView) rootView.findViewById(R.id.orHeader);
    orAzimuth = (TextView) rootView.findViewById(R.id.orAzimuth);
    orAziText = (TextView) rootView.findViewById(R.id.orAziText);
    orPitch = (TextView) rootView.findViewById(R.id.orPitch);
    orRoll = (TextView) rootView.findViewById(R.id.orRoll);
    miscHeader = (TextView) rootView.findViewById(R.id.miscHeader);
    tempStatus = (TextView) rootView.findViewById(R.id.tempStatus);
    tempHeader = (TextView) rootView.findViewById(R.id.tempHeader);
    metTemp = (TextView) rootView.findViewById(R.id.metTemp);
    pressureStatus = (TextView) rootView.findViewById(R.id.pressureStatus);
    pressureHeader = (TextView) rootView.findViewById(R.id.pressureHeader);
    metPressure = (TextView) rootView.findViewById(R.id.metPressure);
    humidStatus = (TextView) rootView.findViewById(R.id.humidStatus);
    humidHeader = (TextView) rootView.findViewById(R.id.humidHeader);
    metHumid = (TextView) rootView.findViewById(R.id.metHumid);
    lightStatus = (TextView) rootView.findViewById(R.id.lightStatus);
    lightHeader = (TextView) rootView.findViewById(R.id.lightHeader);
    light = (TextView) rootView.findViewById(R.id.light);
    proximityStatus = (TextView) rootView.findViewById(R.id.proximityStatus);
    proximityHeader = (TextView) rootView.findViewById(R.id.proximityHeader);
    proximity = (TextView) rootView.findViewById(R.id.proximity);

    mainActivity.sensorSectionFragment = this;

    return rootView;
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.InternalSensorService.java

@Override
public void onCreate() {
    // The service is being created
    Log.e(TAG, "onCreate");

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    if (pref.getBoolean(getResources().getString(R.string.in_acc), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }/* w w  w .j  av  a2 s.  c  o  m*/
    if (pref.getBoolean(getResources().getString(R.string.in_lig), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_pres), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_prox), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_mag), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_gyrs), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_grav), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_hum), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_lin_acc), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_tem), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }

}

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.GyroscopeActivity.java

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

    requestPermissions();// w w  w  .  j av  a2s.co  m
    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);
}