List of usage examples for android.hardware Sensor TYPE_PRESSURE
int TYPE_PRESSURE
To view the source code for android.hardware Sensor TYPE_PRESSURE.
Click Source Link
From source file:com.example.sensingapp.SensingApp.java
private void UpdateSensorServiceRegistration() { //Register sensors according to the enable/disable status // if (m_blnAcclEnabled) { // m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION), m_nAcclMode); // m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), m_nAcclMode); // } else { // m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION)); // m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); // }//from w ww .j av a2 s .c om if (m_blnAcclEnabled) { m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), m_nAcclMode); } else { m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); } if (m_blnLinearAcclEnabled) { m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION), m_nLinearAcclMode); } else { m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION)); } if (m_blnGravityEnabled) { m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_GRAVITY), m_nGravityMode); } else { m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_GRAVITY)); } if (m_blnGyroEnabled) { m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_GYROSCOPE), m_nGyroMode); } else { m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_GYROSCOPE)); } if (m_blnMagnetEnabled) { m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), m_nMagnetMode); } else { m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)); } // Changed on 20150910 // if (m_blnOrientEnabled) { // if (!m_blnAcclEnabled) { // m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), m_nOrientMode); // } // // if (!m_blnMagnetEnabled) { // m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), m_nOrientMode); // } // } else { // if (!m_blnAcclEnabled) { // m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); // } // // if (!m_blnMagnetEnabled) { // m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)); // } // } if (m_blnOrientEnabled) { m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR), m_nOrientMode); } else { m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)); } if (m_blnLightEnabled) { m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LIGHT), m_nLightMode); } else { m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LIGHT)); } if (m_blnBarometerEnabled) { m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_PRESSURE), m_nBarometerMode); } else { m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_PRESSURE)); } }
From source file:com.example.sensingapp.SensingApp.java
private void checkSensorAvailability() { //List<Sensor> lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_ORIENTATION); List<Sensor> lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_ROTATION_VECTOR); //Changed on 20150910 if (lstSensor.size() > 0) { m_blnOrientPresent = true;//from w w w .j ava 2 s . c o m } else { m_blnOrientPresent = false; m_blnOrientEnabled = false; } lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_GYROSCOPE); if (lstSensor.size() > 0) { m_blnGyroPresent = true; } else { m_blnGyroPresent = false; m_blnGyroEnabled = false; } lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_ACCELEROMETER); if (lstSensor.size() > 0) { m_blnAcclPresent = true; } else { m_blnAcclPresent = false; m_blnAcclEnabled = false; } lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_LINEAR_ACCELERATION); if (lstSensor.size() > 0) { m_blnLinearAcclPresent = true; } else { m_blnLinearAcclPresent = false; m_blnLinearAcclEnabled = false; } lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_GRAVITY); if (lstSensor.size() > 0) { m_blnGravityPresent = true; } else { m_blnGravityPresent = false; m_blnGravityEnabled = false; } lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_MAGNETIC_FIELD); if (lstSensor.size() > 0) { m_blnMagnetPresent = true; } else { m_blnMagnetPresent = false; m_blnMagnetEnabled = false; } lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_LIGHT); if (lstSensor.size() > 0) { m_blnLightPresent = true; } else { m_blnLightPresent = false; m_blnLightEnabled = false; } lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_PRESSURE); if (lstSensor.size() > 0) { m_blnBarometerPresent = true; } else { m_blnBarometerPresent = false; m_blnBarometerEnabled = false; } }
From source file:com.aware.Aware_Preferences.java
/** * Atmospheric Pressure module settings UI */// w w w. j a v a 2s .com private void barometer() { final PreferenceScreen baro_pref = (PreferenceScreen) findPreference("barometer"); Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_PRESSURE); if (temp != null) { baro_pref.setSummary( baro_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA")); } else { baro_pref.setSummary(baro_pref.getSummary().toString().replace("*", "")); } final CheckBoxPreference pressure = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_BAROMETER); pressure.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_BAROMETER).equals("true")); pressure.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (mSensorMgr.getDefaultSensor(Sensor.TYPE_PRESSURE) == null) { showDialog(DIALOG_ERROR_MISSING_SENSOR); pressure.setChecked(false); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_BAROMETER, false); return false; } Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_BAROMETER, pressure.isChecked()); if (pressure.isChecked()) { framework.startBarometer(); } else { framework.stopBarometer(); } return true; } }); final EditTextPreference frequency_pressure = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_BAROMETER); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_BAROMETER).length() > 0) { frequency_pressure .setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_BAROMETER) + " microseconds"); } frequency_pressure .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_BAROMETER)); frequency_pressure.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_BAROMETER, (String) newValue); frequency_pressure.setSummary((String) newValue + " microseconds"); framework.startBarometer(); return true; } }); }
From source file:com.example.sensingapp.SensingApp.java
public void recordSensingInfo(SensorData senData) { String sRecordLine;//from w w w .j av a2s .co m String sTimeField; Date dtCurDate; int i; long lStartTime = 0; long lCurrentTime = 0; SimpleDateFormat spdRecordTime, spdCurDateTime; final String DATE_FORMAT = "yyyyMMddHHmmss"; final String DATE_FORMAT_S = "yyMMddHHmmssSSS"; //"yyyyMMddHHmmssSSS" int nSensorReadingType = SENSOR_EVENT_NULL; int nSensorDataType; if (m_blnRecordStatus == false) { //Stopped return; } dtCurDate = new Date(); // Timestamp for the record spdRecordTime = new SimpleDateFormat(DATE_FORMAT_S); sTimeField = spdRecordTime.format(dtCurDate); nSensorDataType = senData.getSensorDataType(); if (nSensorDataType == DATA_TYPE_SENSOR) { SensorEvent event; event = senData.getSensorEvent(); synchronized (this) { switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: //X, Y, Z if (m_blnAcclEnabled) { m_sAccl = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + "," + Float.toString(event.values[2]) + ","; nSensorReadingType = SENSOR_EVENT_ACCL; } // if (m_blnOrientEnabled) { // m_arrfAcclValues = event.values.clone(); // // if (calculateOrientation()) { // //Azimuth (rotation around z-axis); Pitch (rotation around x-axis), Roll (rotation around y-axis) // m_sOrient = Float.toString(m_arrfOrientValues[0]) + "," + // Float.toString(m_arrfOrientValues[1]) + "," + // Float.toString(m_arrfOrientValues[2]) + ","; // // nSensorReadingType = SENSOR_EVENT_ORIENT; // // } // } break; case Sensor.TYPE_LINEAR_ACCELERATION: //X,Y,Z if (m_blnLinearAcclEnabled) { m_sLinearAccl = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + "," + Float.toString(event.values[2]) + ","; nSensorReadingType = SENSOR_EVENT_LINEAR_ACCL; } break; case Sensor.TYPE_GRAVITY: //X,Y,Z if (m_blnGravityEnabled) { m_sGravity = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + "," + Float.toString(event.values[2]) + ","; nSensorReadingType = SENSOR_EVENT_GRAVITY; } break; case Sensor.TYPE_GYROSCOPE: //X,Y,Z m_sGyro = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + "," + Float.toString(event.values[2]) + ","; nSensorReadingType = SENSOR_EVENT_GYRO; break; case Sensor.TYPE_MAGNETIC_FIELD: // Values are in micro-Tesla (uT) and measure the ambient magnetic field if (m_blnMagnetEnabled) { m_sMagnet = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + "," + Float.toString(event.values[2]) + ","; nSensorReadingType = SENSOR_EVENT_MAGNET; } // if (m_blnOrientEnabled) { // m_arrfMagnetValues = event.values.clone(); // // if (calculateOrientation()) { // //Azimuth (rotation around z-axis); Pitch (rotation around x-axis), Roll (rotation around y-axis) // m_sOrient = Float.toString(m_arrfOrientValues[0]) + "," + // Float.toString(m_arrfOrientValues[1]) + "," + // Float.toString(m_arrfOrientValues[2]) + ","; // // if (nSensorReadingType != SENSOR_EVENT_MAGNET) { // nSensorReadingType = SENSOR_EVENT_ORIENT; // } // } // } break; case Sensor.TYPE_ROTATION_VECTOR: //Added on 20150910 if (m_blnOrientEnabled) { float[] arrfRotVal = new float[3]; float[] arrfR = new float[9]; float[] arrfValues = new float[3]; try { System.arraycopy(event.values, 0, arrfRotVal, 0, event.values.length); } catch (IllegalArgumentException e) { //Hardcode the size to handle a bug on Samsung devices System.arraycopy(event.values, 0, arrfRotVal, 0, 3); } SensorManager.getRotationMatrixFromVector(arrfR, arrfRotVal); SensorManager.getOrientation(arrfR, arrfValues); m_arrfOrientValues[0] = (float) Math.toDegrees(arrfValues[0]); m_arrfOrientValues[1] = (float) Math.toDegrees(arrfValues[1]); m_arrfOrientValues[2] = (float) Math.toDegrees(arrfValues[2]); if (m_arrfOrientValues[0] < 0) { m_arrfOrientValues[0] = m_arrfOrientValues[0] + 360; // Make Azimuth 0 ~ 360 } // //Azimuth (rotation around z-axis); Pitch (rotation around x-axis), Roll (rotation around y-axis) m_sOrient = Float.toString(m_arrfOrientValues[0]) + "," + Float.toString(m_arrfOrientValues[1]) + "," + Float.toString(m_arrfOrientValues[2]) + ","; //m_tvGpsUp.setText(m_sOrient); //Show orientation nSensorReadingType = SENSOR_EVENT_ORIENT; } break; case Sensor.TYPE_LIGHT: // Ambient light level in SI lux units m_sLight = Float.toString(event.values[0]) + ","; nSensorReadingType = SENSOR_EVENT_LIGHT; break; case Sensor.TYPE_PRESSURE: // Atmospheric pressure in hPa (millibar) m_sBarometer = Float.toString(event.values[0]) + ","; nSensorReadingType = SENSOR_EVENT_BAROMETER; break; } } } else if (nSensorDataType == DATA_TYPE_GPS) { Location locationGps; locationGps = senData.getGpsLocation(); if (locationGps != null) { m_location = new Location(locationGps); //Change from double to float m_sGPS = Float.valueOf((float) (locationGps.getLatitude())).toString() + "," + Float.valueOf((float) (locationGps.getLongitude())).toString() + ","; if (locationGps.hasAltitude()) { m_sGPS = m_sGPS + Float.valueOf((float) (locationGps.getAltitude())).toString() + ","; GeomagneticField geoField = new GeomagneticField( Double.valueOf(locationGps.getLatitude()).floatValue(), Double.valueOf(locationGps.getLongitude()).floatValue(), Double.valueOf(locationGps.getAltitude()).floatValue(), System.currentTimeMillis()); // Append Declination, in Degree m_sGPS = m_sGPS + Float.valueOf((float) (geoField.getDeclination())).toString() + "," + Float.valueOf((float) (geoField.getInclination())).toString() + ","; } else { m_sGPS = m_sGPS + ",,,"; //m_sGPS = m_sGPS + ","; } //New add 201408270009 if (locationGps.hasSpeed()) { m_sGPS = m_sGPS + Float.valueOf((float) (locationGps.getSpeed())).toString() + ","; } else { m_sGPS = m_sGPS + ","; } if (locationGps.hasBearing()) { m_sGPS = m_sGPS + Float.valueOf((float) (locationGps.getBearing())).toString() + ","; } else { m_sGPS = m_sGPS + ","; } nSensorReadingType = SENSOR_EVENT_GPS; m_blnGpsUp = true; show_screen5_GpsUp(); } else { m_blnGpsUp = false; show_screen5_GpsUp(); } } else if (nSensorDataType == DATA_TYPE_MIC) { double fSoundLevelDb; fSoundLevelDb = senData.getSoundLevelDb(); m_sSouldLevel = new BigDecimal(fSoundLevelDb).setScale(0, BigDecimal.ROUND_HALF_UP) + ","; nSensorReadingType = SENSOR_EVENT_MIC; } else if (nSensorDataType == DATA_TYPE_CELLULAR) { int nCellId; nCellId = senData.getCellId(); m_sCellId = Integer.valueOf(nCellId).toString() + ","; nSensorReadingType = SENSOR_EVENT_CELLULAR; } else if (nSensorDataType == DATA_TYPE_WIFI) { List<WifiData> lstWifiData = senData.getListWifiData(); int nWifiCnt = Math.min(WIFI_COUNT, lstWifiData.size()); m_sWifi = ""; for (i = 0; i < nWifiCnt; i++) { //m_sWifi = m_sWifi + lstWifiData.get(i).getSSID() + "," + lstWifiData.get(i).getBSSID() + "," + lstWifiData.get(i).getSignalLevel() + ","; m_sWifi = m_sWifi + lstWifiData.get(i).getBSSID() + "," + lstWifiData.get(i).getSignalLevel() + ","; } for (i = 1; i <= WIFI_COUNT - nWifiCnt; i++) { //m_sWifi = m_sWifi + ",,,"; m_sWifi = m_sWifi + ",,"; } nSensorReadingType = SENSOR_EVENT_WIFI; } if (nSensorReadingType == SENSOR_EVENT_NULL) { return; } sRecordLine = sTimeField + ","; if (m_blnNoLabel == false) { sRecordLine = sRecordLine + m_sCurrentLabel + ","; } sRecordLine = sRecordLine + Integer.valueOf(nSensorReadingType) + ","; //New: Every field always there //Field in each line: /* * 1) Timestamp * 2) Label * 3) SensingEventType * 4-6) Accl * 7-9) Linear Accl * 10-12) Gravity * 13-15) Gyro * 16-18) Orientation * 19-21) Magnet * 22) Light * 23) Barometer * 24) Sould Level (Decibel) * 25) Cell ID * 26-32) GPS (Lat, Long, Alt, Declination, Inclination, Speed, Bearing) * 33-72) WiFi (<BSSID, Level>) */ // sRecordLine = sRecordLine + m_sAccl + m_sGyro + m_sOrient + m_sMagnet + // m_sLight + m_sBarometer + // m_sSouldLevel + m_sCellId + // m_sGPS + m_sWifi; sRecordLine = sRecordLine + m_sAccl + m_sLinearAccl + m_sGravity + m_sGyro + m_sOrient + m_sMagnet + m_sLight + m_sBarometer + m_sSouldLevel + m_sCellId + m_sGPS + m_sWifi; //////////////////////////// // String sAngle = calculateRot(m_sAccl, m_sGravity); // String sarrAngle[] = sAngle.split(","); // String sShow = sarrAngle[0] + "\n" + sarrAngle[1]; // String sShow = ""; // if (m_sGravity.length() > 3) { // String sarrAngle[] = m_sGravity.split(","); // double fX = Double.valueOf(sarrAngle[0]).doubleValue(); // double fY = Double.valueOf(sarrAngle[1]).doubleValue(); // double fZ = Double.valueOf(sarrAngle[2]).doubleValue(); // // double fTotal = Math.sqrt(fX*fX + fY*fY + fZ*fZ); // // double fAngleZ = Math.acos(fZ/fTotal)/Math.PI*180; // double fAngleY = 90 - Math.acos(fY/fTotal)/Math.PI*180; // double fAngleX = 90 - Math.acos(fX/fTotal)/Math.PI*180; // // sShow = "X: " + fAngleX + "\n"; // sShow = sShow + "Y: " + fAngleY + "\n"; // sShow = sShow + "Z: " + fAngleZ; // // // } // if (m_sGravity.length() > 3) { // String sarrAngle[] = m_sGravity.split(","); // double fX = Double.valueOf(sarrAngle[0]).doubleValue(); // double fY = Double.valueOf(sarrAngle[1]).doubleValue(); // double fZ = Double.valueOf(sarrAngle[2]).doubleValue(); // // int nSymbol = 0; // if (fX < 0) { // sShow = sShow + "- X" + "\n"; // } else if (fX > 0) { // sShow = sShow + "+ X" + "\n"; // } // // if (fY < 0) { // sShow = sShow + "- Y" + "\n"; // } else if (fY > 0) { // sShow = sShow + "+ Y" + "\n"; // } // // if (fZ < 0) { // sShow = sShow + "- Z"; // } else if (fZ > 0) { // sShow = sShow + "+ Z"; // } // // } // // if (m_sGyro.length() > 3) { // String sarrAngle[] = m_sGyro.split(","); // double fX = Double.valueOf(sarrAngle[0]).doubleValue(); // double fY = Double.valueOf(sarrAngle[1]).doubleValue(); // double fZ = Double.valueOf(sarrAngle[2]).doubleValue(); // // int nSymbol = 0; // if (fX < 0) { // nSymbol = -1; // } else if (fX > 0) { // nSymbol = 1; // } // // if (fY < 0) { // nSymbol = nSymbol + (-1); // } else if (fY > 0) { // nSymbol = nSymbol + 1; // } // // if (fZ < 0) { // nSymbol = nSymbol + (-1); // } else if (fZ > 0) { // nSymbol = nSymbol + 1; // } // // if (nSymbol < 0) { // nSymbol = -1; // } else if (nSymbol > 0) { // nSymbol = 1; // } // // sShow = sShow + "\n\n" + nSymbol + ""; // } // m_tvSensingInfo.setText(sShow); //////////////////////////// sRecordLine = sRecordLine + System.getProperty("line.separator"); if (m_fwSensorRecord != null) { //Write information into file //Compose information into recordLine try { m_fwSensorRecord.write(sRecordLine); } catch (IOException e) { } } }
From source file:com.example.sensingapp.SensingApp.java
public void onAccuracyChanged(Sensor sensor, int accuracy) { switch (sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: m_sSensorAccuracy = "1,"; //Accl break;//w ww. j a va 2 s. com case Sensor.TYPE_LINEAR_ACCELERATION: m_sSensorAccuracy = "2,"; //LinearAccl break; case Sensor.TYPE_GYROSCOPE: m_sSensorAccuracy = "3,"; //Gyro break; case Sensor.TYPE_MAGNETIC_FIELD: m_sSensorAccuracy = "4,"; //Magnet break; case Sensor.TYPE_GRAVITY: m_sSensorAccuracy = "5,"; //Gravity break; case Sensor.TYPE_PROXIMITY: m_sSensorAccuracy = "6,"; //Proxi break; case Sensor.TYPE_LIGHT: m_sSensorAccuracy = "7,"; //Light break; case Sensor.TYPE_PRESSURE: m_sSensorAccuracy = "8,"; //Barometer break; case Sensor.TYPE_RELATIVE_HUMIDITY: m_sSensorAccuracy = "9,"; //Humidity break; case Sensor.TYPE_AMBIENT_TEMPERATURE: m_sSensorAccuracy = "10,"; //Temperature break; default: m_sSensorAccuracy = "11,"; //Other } switch (accuracy) { case SensorManager.SENSOR_STATUS_ACCURACY_HIGH: m_sSensorAccuracy = m_sSensorAccuracy + "1,"; //H break; case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM: m_sSensorAccuracy = m_sSensorAccuracy + "2,"; //M break; case SensorManager.SENSOR_STATUS_ACCURACY_LOW: m_sSensorAccuracy = m_sSensorAccuracy + "3,"; //L break; case SensorManager.SENSOR_STATUS_UNRELIABLE: m_sSensorAccuracy = m_sSensorAccuracy + "4,"; //U break; } }