List of usage examples for android.hardware Sensor TYPE_GYROSCOPE
int TYPE_GYROSCOPE
To view the source code for android.hardware Sensor TYPE_GYROSCOPE.
Click Source Link
From source file:io.authme.sdk.widget.LockPatternView.java
@Override public void onSensorChanged(SensorEvent event) { if (collectSensor) { Sensor sensor = event.sensor;/*from w w w . ja v a 2 s .co m*/ if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) { mGravity = event.values; Accelerometer sensordata = new Accelerometer(mGravity[0], mGravity[1], mGravity[2], event.timestamp); accelList.add(sensordata); } if (sensor.getType() == Sensor.TYPE_GRAVITY) { mGravity = event.values; Accelerometer sensordata = new Accelerometer(mGravity[0], mGravity[1], mGravity[2], event.timestamp); accelList.add(sensordata); } if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { mGeomagnetic = event.values; Magnetic magnetic = new Magnetic(mGeomagnetic[0], mGeomagnetic[1], mGeomagnetic[2], event.timestamp); magnetics.add(magnetic); } if (sensor.getType() == Sensor.TYPE_GYROSCOPE) { float x = event.values[0]; float y = event.values[1]; float z = event.values[2]; Gyroscope gyro = new Gyroscope(x, y, z, event.timestamp); gyrolist.add(gyro); } if (mGravity != null && mGeomagnetic != null) { float R[] = new float[9]; float I[] = new float[9]; boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic); if (success) { float orientation[] = new float[3]; SensorManager.getOrientation(R, orientation); Orientation orientationObj = new Orientation(orientation[0], orientation[1], orientation[2], event.timestamp); orientationArrayList.add(orientationObj); } } } }
From source file:com.kircherelectronics.fusedgyroscopeexplorer.sensor.GyroscopeSensor.java
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) { System.arraycopy(event.values, 0, this.gyroscope, 0, event.values.length); this.timeStamp = event.timestamp; if (vehicleMode) { this.gyroscope = quaternionToDeviceVehicleMode(this.gyroscope); }/*from www. j a va 2 s. com*/ notifyGyroscopeObserver(); } }
From source file:uk.ac.horizon.ubihelper.service.Service.java
@Override public void onCreate() { // One-time set-up... Log.d(TAG, "onCreate()"); // TODO/*ww w .j av a2s . com*/ super.onCreate(); // handler for requests mHandler = new Handler(); // create taskbar notification int icon = R.drawable.service_notification_icon; CharSequence tickerText = getText(R.string.notification_start_message); long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context context = this; CharSequence contentTitle = getText(R.string.notification_title); CharSequence contentText = getText(R.string.notification_description); Intent notificationIntent = new Intent(this, MainPreferences.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); startForeground(RUNNING_ID, notification); channelManager = new ChannelManager(peerChannelFactory); // sensors if (!isEmulator()) { Log.d(TAG, "Create sensor channels..."); SensorChannel magnetic = new SensorChannel("magnetic", this, Sensor.TYPE_MAGNETIC_FIELD); channelManager.addChannel(magnetic); SensorChannel accelerometer = new SensorChannel("accelerometer", this, Sensor.TYPE_ACCELEROMETER); channelManager.addChannel(accelerometer); SensorChannel gyro = new SensorChannel("gyro", this, Sensor.TYPE_GYROSCOPE); channelManager.addChannel(gyro); SensorChannel light = new SensorChannel("light", this, Sensor.TYPE_LIGHT); channelManager.addChannel(light); SensorChannel pressure = new SensorChannel("pressure", this, Sensor.TYPE_PRESSURE); channelManager.addChannel(pressure); SensorChannel proximity = new SensorChannel("proximity", this, Sensor.TYPE_PROXIMITY); channelManager.addChannel(proximity); SensorChannel temperature = new SensorChannel("temperature", this, Sensor.TYPE_TEMPERATURE); channelManager.addChannel(temperature); try { Field f = Sensor.class.getField("TYPE_AMBIENT_TEMPERATURE"); SensorChannel sc = new SensorChannel("ambientTemperature", this, f.getInt(null)); channelManager.addChannel(sc); } catch (Exception e) { Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE"); } try { Field f = Sensor.class.getField("TYPE_RELATIVE_HUMIDITY"); SensorChannel sc = new SensorChannel("relativeHumidity", this, f.getInt(null)); channelManager.addChannel(sc); } catch (Exception e) { Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE"); } // all sensors by full name SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); if (sensorManager != null) { List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensors) { SensorChannel sc = new SensorChannel("sensor." + sensor.getName(), this, sensor); channelManager.addChannel(sc); } } BluetoothDiscoveryChannel btchannel = new BluetoothDiscoveryChannel(this, mHandler, "bluetooth"); channelManager.addChannel(btchannel); WifiScannerChannel wifichannel = new WifiScannerChannel(this, mHandler, "wifi"); channelManager.addChannel(wifichannel); GpsStatusChannel gpsstatus = new GpsStatusChannel("gpsstatus", this); channelManager.addChannel(gpsstatus); CellLocationChannel cellchannel = new CellLocationChannel(mHandler, this, "cell.location", false); channelManager.addChannel(cellchannel); CellLocationChannel cellchannel2 = new CellLocationChannel(mHandler, this, "cell.neighbors", true); channelManager.addChannel(cellchannel2); CellStrengthChannel cellchannel3 = new CellStrengthChannel(this, "cell.strength"); channelManager.addChannel(cellchannel3); } channelManager.addChannel(new TimeChannel(mHandler, "time")); List<String> locationProviders = LocationChannel.getAllProviders(this); for (String provider : locationProviders) { LocationChannel locchannel = new LocationChannel("location." + provider, this, provider); channelManager.addChannel(locchannel); } channelManager.addChannel(new MicChannel(mHandler, "mic")); Log.d(TAG, "Create http server..."); // http server httpPort = getPort(); httpListener = new HttpListener(this, httpPort); httpListener.start(); // peer communication peerManager = new PeerManager(this); int serverPort = peerManager.getServerPort(); channelManager.addChannel(new EnabledPeersChannel(this, peerManager, "peers")); // wifi discovery wifiDiscoveryManager = new WifiDiscoveryManager(this); wifiDiscoverable = getWifiDiscoverable(); wifiDiscoveryManager.setServerPort(serverPort); wifiDiscoveryManager.setEnabled(wifiDiscoverable); bluetooth = BluetoothAdapter.getDefaultAdapter(); if (bluetooth != null) btmac = bluetooth.getAddress(); telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (telephony != null) imei = telephony.getDeviceId(); logManager = new LogManager(this, channelManager); logManager.checkPreferences(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(onRunChangeListener); Log.d(TAG, "onCreate() finished"); }
From source file:com.example.appf.CS3570.java
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) { mGyroscopeEvent = event.values;//from w ww. j a v a 2s . c o m } if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) mGravity = event.values; if (mGravity != null && mGyroscopeEvent != null && mGLView != null && mGLView.mRenderer.mTetra != null) { filter.updateFilter(mGyroscopeEvent[0], mGyroscopeEvent[1], mGyroscopeEvent[2], mGravity[0], mGravity[1], mGravity[2]); filter.computerEuler(); azimut = (float) filter.getYaw(); // orientation contains: azimut, pitch and roll pitch = (float) filter.getPitch(); roll = (float) filter.getRoll(); if (previousAzimuth == Float.MAX_VALUE) { previousAzimuth = azimut; } if (previousPitch == Float.MAX_VALUE) { previousPitch = pitch; } if (previousRoll == Float.MAX_VALUE) { previousRoll = roll; } float delta_azimut = azimut - previousAzimuth; float delta_pitch = pitch - previousPitch; float delta_roll = roll - previousRoll; //Log.e("eee", "Azimuth: "+ delta_azimut + " pitch: " + delta_pitch + " roll: " + delta_roll); //Log.e("eee", " roll: " + roll); //Log.e("eee", "Azimuth: " + azimut + " pitch: " + pitch + " roll: " + roll); if (Math.abs(delta_roll) > THRESHOLD && roll != Float.NaN) { previousRoll = roll; if (cam) mGLView.mRenderer.mCamera.rotateX(delta_roll * 180.0 / Math.PI * ROTATE_AMPLIFY); //mGLView.mRenderer.mTetra.rotate((float) (delta_roll * 180.0 / Math.PI) * ROTATE_AMPLIFY, 1, 0, 0); else mGLView.mRenderer.mTetra.pure_rotate((float) ((roll + Math.PI) * 180.0 / Math.PI), 1, 0, 0); } if (Math.abs(delta_pitch) > THRESHOLD && pitch != Float.NaN) { previousPitch = pitch; if (cam) mGLView.mRenderer.mCamera.rotateX(delta_pitch * 180.0 / Math.PI * ROTATE_AMPLIFY); //Log.e("eee", "" + ((delta_pitch)* 180.0 / Math.PI) ); else mGLView.mRenderer.mTetra.pure_rotate((float) ((pitch + Math.PI) * 180.0 / Math.PI), 0, 1, 0); } if (Math.abs(delta_azimut) > THRESHOLD && azimut != Float.NaN) { previousAzimuth = azimut; if (cam) mGLView.mRenderer.mCamera.rotateY(delta_azimut * 180.0 / Math.PI * ROTATE_AMPLIFY); else //mGLView.mRenderer.mTetra.rotate((float)(delta_azimut * 180.0/Math.PI) * ROTATE_AMPLIFY, 0, 0, 1 ); mGLView.mRenderer.mTetra.pure_rotate((float) (azimut * 180.0 / Math.PI), 0, 0, 1); } if (out != null) { //Log.e("eee", "{pitch:" + pitch + "}"); Vector3 cam_pos = mGLView.mRenderer.mCamera.get_position(); out.println("{\"pitch\":" + pitch + ", \"roll\": " + roll + ", \"yaw\": " + azimut + ", \"translation\": [" + cam_pos.getX() + ", " + cam_pos.getY() + "," + cam_pos.getZ() + "]}\0"); } mGLView.requestRender(); } }
From source file:com.example.basensortracker.SensorFusionActivity.java
@Override public void onSensorChanged(SensorEvent event) { switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: // copy new accelerometer data into accel array and calculate // orientation System.arraycopy(event.values, 0, accel, 0, 3); calculateAccMagOrientation();//from ww w . ja v a2 s . c o m break; case Sensor.TYPE_GYROSCOPE: // process gyro data gyroFunction(event); break; case Sensor.TYPE_MAGNETIC_FIELD: // copy new magnetometer data into magnet array System.arraycopy(event.values, 0, magnet, 0, 3); break; } }
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 ww .ja v a2 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.gyroscopeexplorer.activity.GyroscopeActivity.java
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { // Android reuses events, so you probably want a copy System.arraycopy(event.values, 0, acceleration, 0, event.values.length); orientationFusion.setAcceleration(acceleration); } else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { // Android reuses events, so you probably want a copy System.arraycopy(event.values, 0, magnetic, 0, event.values.length); orientationFusion.setMagneticField(this.magnetic); } else if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) { // Android reuses events, so you probably want a copy System.arraycopy(event.values, 0, rotation, 0, event.values.length); // Filter the rotation fusedOrientation = orientationFusion.filter(this.rotation); if (meanFilterEnabled) { fusedOrientation = meanFilter.filter(fusedOrientation); }// w ww. ja v a 2s . com dataLogger.setRotation(fusedOrientation); } }
From source file:com.microsoft.band.sdksample.SensorsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_sensors, container, false); senSensorManager1 = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); senSensorManager2 = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); senGyroscope = senSensorManager1.getDefaultSensor(Sensor.TYPE_GYROSCOPE); senSensorManager1.registerListener(this, senGyroscope, SensorManager.SENSOR_DELAY_NORMAL); senAccelerometer = senSensorManager2.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); senSensorManager2.registerListener(this, senAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); mTableAcc = (TableLayout) rootView.findViewById(R.id.tableAcc); mTableAcc.setVisibility(View.GONE); mTextAccX = (TextView) rootView.findViewById(R.id.textAccX); mTextAccY = (TextView) rootView.findViewById(R.id.textAccY); mTextAccZ = (TextView) rootView.findViewById(R.id.textAccZ); mTextAngX = (TextView) rootView.findViewById(R.id.textPAngX); mTextAngY = (TextView) rootView.findViewById(R.id.textPAngY); mTextAngZ = (TextView) rootView.findViewById(R.id.textPAngZ); mTextLong = (TextView) rootView.findViewById(R.id.textLong); mTextLat = (TextView) rootView.findViewById(R.id.textLat); mTextTime = (TextView) rootView.findViewById(R.id.textTime); temp_list = new double[14]; c = 0;/* w w w .j av a 2 s . c om*/ // Acquire a reference to the system Location Manager LocationManager locationManager = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. temp_list[12] = location.getLongitude(); temp_list[13] = location.getLatitude(); mTextLong.setText(Double.toString(temp_list[12])); mTextLat.setText(Double.toString(temp_list[13])); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); runnable.run(); // // Gyro setup // mTableGyro = (TableLayout) rootView.findViewById(R.id.tableGyro); mTableGyro.setVisibility(View.GONE); mTextGyroAccX = (TextView) rootView.findViewById(R.id.textGyroAccX); mTextGyroAccY = (TextView) rootView.findViewById(R.id.textGyroAccY); mTextGyroAccZ = (TextView) rootView.findViewById(R.id.textGyroAccZ); mTextGyroAngX = (TextView) rootView.findViewById(R.id.textAngX); mTextGyroAngY = (TextView) rootView.findViewById(R.id.textAngY); mTextGyroAngZ = (TextView) rootView.findViewById(R.id.textAngZ); // // Contact setup // mTableContact = (TableLayout) rootView.findViewById(R.id.tableContact); mTableContact.setVisibility(View.GONE); mTextContact = (TextView) rootView.findViewById(R.id.textContact); turnOnSensors(); return rootView; }
From source file:com.android.plugins.GyroscopeListener.java
/** * Called when the accuracy of the sensor has changed. * * @param sensor/*from w ww . j a v a 2s. c o m*/ * @param accuracy */ public void onAccuracyChanged(Sensor sensor, int accuracy) { // Only look at gyroscope events if (sensor.getType() != Sensor.TYPE_GYROSCOPE) { return; } // If not running, then just return if (this.status == GyroscopeListener.STOPPED) { return; } this.accuracy = accuracy; }
From source file:com.android.plugins.GyroscopeListener.java
/** * Sensor listener event.//from ww w. jav a 2 s .co m * * @param SensorEvent event */ public void onSensorChanged(SensorEvent event) { // Only look at gyroscope events if (event.sensor.getType() != Sensor.TYPE_GYROSCOPE) { return; } // If not running, then just return if (this.status == GyroscopeListener.STOPPED) { return; } this.setStatus(GyroscopeListener.RUNNING); if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) { // Save time that event was received this.timestamp = System.currentTimeMillis(); this.x = event.values[0]; this.y = event.values[1]; this.z = event.values[2]; this.win(); } }