List of usage examples for android.hardware SensorManager getOrientation
public static float[] getOrientation(float[] R, float[] values)
From source file:com.davidmascharka.lips.MainActivity.java
@Override public void onSensorChanged(SensorEvent event) { /*/* w w w . j a v a2s. c o m*/ * Because Android doesn't let us query a sensor reading whenever we want so * we have to keep track of the readings at all times. Here we just update * the class members with the values associated with each reading we're * interested in. */ switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: accelerometerX = event.values[0]; accelerometerY = event.values[1]; accelerometerZ = event.values[2]; break; case Sensor.TYPE_MAGNETIC_FIELD: magneticX = event.values[0]; magneticY = event.values[1]; magneticZ = event.values[2]; break; case Sensor.TYPE_LIGHT: light = event.values[0]; break; case Sensor.TYPE_ROTATION_VECTOR: rotationX = event.values[0]; rotationY = event.values[1]; rotationZ = event.values[2]; break; default: break; } SensorManager.getRotationMatrix(rotation, inclination, new float[] { accelerometerX, accelerometerY, accelerometerZ }, new float[] { magneticX, magneticY, magneticZ }); orientation = SensorManager.getOrientation(rotation, orientation); }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopDetailsFragment.java
/** * Update the direction needle so that it is pointing towards the bus stop, * based on the device location and the direction it is facing. *///from w w w . j a va 2s .c om private void updateDirectionNeedle() { // We need values for location, the accelerometer and magnetometer to // continue. if (lastLocation == null || accelerometerValues == null || magnetometerValues == null) { // Make sure the needle isn't showing. txtDistance.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); recycleNeedleBitmapIfNotNull(null); return; } // Calculating the rotation matrix may fail, for example, if the device // is in freefall. In that case we cannot continue as the values will // be unreliable. if (!SensorManager.getRotationMatrix(rotationMatrix, null, accelerometerValues, magnetometerValues)) { return; } // The screen rotation was obtained earlier. switch (screenRotation) { // There's lots of information about this elsewhere, but briefly; // The values from the sensors are in the device's coordinate system // which may be correct if the device is in its natural orientation, // but it needs to be remapped if the device is rotated. case Surface.ROTATION_0: SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, rotationMatrix); break; case Surface.ROTATION_90: SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_Z, SensorManager.AXIS_MINUS_X, rotationMatrix); break; case Surface.ROTATION_180: SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_MINUS_X, SensorManager.AXIS_MINUS_Z, rotationMatrix); break; case Surface.ROTATION_270: SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_MINUS_Z, SensorManager.AXIS_X, rotationMatrix); break; } // Get the X, Y and Z orientations, which are in radians. Covert this // in to degrees East of North. SensorManager.getOrientation(rotationMatrix, headings); double heading = Math.toDegrees(headings[0]); // If there's a GeomagneticField value, then adjust the heading to take // this in to account. if (geoField != null) { heading -= geoField.getDeclination(); } // The orientation is in the range of -180 to +180. Convert this in to // a range of 0 to 360. final float bearingTo = distance[1] < 0 ? distance[1] + 360 : distance[1]; // This is the heading to the bus stop. heading = bearingTo - heading; // The above calculation may come out as a negative number again. Put // this back in to the range of 0 to 360. if (heading < 0) { heading += 360; } // This 'if' statement is required to prevent a crash during device // rotation. It ensured that the Fragment is still part of the Activity. if (isAdded()) { // Get the arrow bitmap from the resources. final Bitmap needleIn = BitmapFactory.decodeResource(getResources(), R.drawable.heading_arrow); // Get an identity matrix and rotate it by the required amount. final Matrix m = new Matrix(); m.setRotate((float) heading % 360, (float) needleIn.getWidth() / 2, (float) needleIn.getHeight() / 2); // Apply the rotation matrix to the Bitmap, to create a new Bitmap. final Bitmap needleOut = Bitmap.createBitmap(needleIn, 0, 0, needleIn.getWidth(), needleIn.getHeight(), m, true); // Recycle the needle read in if it's not the same as the rotated // needle. if (needleIn != needleOut) { needleIn.recycle(); } // This Bitmap needs to be converted to a Drawable type. final BitmapDrawable drawable = new BitmapDrawable(getResources(), needleOut); // Set the new needle to be on the right hand side of the TextView. txtDistance.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null); recycleNeedleBitmapIfNotNull(needleOut); } else { // If the Fragment is not added to the Activity, then make sure // there's no needle. txtDistance.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); recycleNeedleBitmapIfNotNull(null); } }
From source file:org.osm.keypadmapper2.KeypadMapper2Activity.java
@Override public void onSensorChanged(SensorEvent event) { synchronized (this) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) mGravity = event.values;/* w ww .ja v a 2 s .c o m*/ if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) mGeomagnetic = event.values; 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); azimuth = orientation[0]; // orientation contains: azimuth, pitch and roll } } } }
From source file:radu.pidroid.Controller.java
private void computeTiltAngle() { float[] mRotationMatrix = new float[9]; float[] mOrientationMatrix = new float[3]; //// ww w. j av a2 s . c o m if (!SensorManager.getRotationMatrix(mRotationMatrix, null, mAccelerometerData, mGeomagneticData)) return; else SensorManager.getOrientation(mRotationMatrix, mOrientationMatrix); // turnAngle = (int) Math.round(Math.toDegrees((double) mOrientationMatrix[1]) + 90); }
From source file:com.spoiledmilk.ibikecph.navigation.SMRouteNavigationMapFragment.java
public void onSensorChanged(SensorEvent event) { if (event.sensor == mAccelerometer) { accValues.put(event.values);/*from w w w . ja v a 2 s . co m*/ // System.arraycopy(event.values, 0, mLastAccelerometer, 0, event.values.length); mLastAccelerometerSet = true; } else if (event.sensor == mMagnetometer) { if (Math.sqrt(event.values[0] * event.values[0] + event.values[1] * event.values[1] + event.values[2] * event.values[2]) > SensorManager.MAGNETIC_FIELD_EARTH_MAX * 1.5) { return; } if (event.values.length < 3) { return; } magValues.put(event.values); // System.arraycopy(event.values, 0, mLastMagnetometer, 0, event.values.length); mLastMagnetometerSet = true; } if (mLastAccelerometerSet && mLastMagnetometerSet) { SensorManager.getRotationMatrix(mR, null, accValues.get(), magValues.get()); // SensorManager.remapCoordinateSystem(mR, SensorManager.AXIS_X, // SensorManager.AXIS_Z, remapMatrix); SensorManager.getOrientation(mR, mOrientation); // remapMatrx if (SMLocationManager.getInstance().hasValidLocation()) { Location currentLoc = SMLocationManager.getInstance().getLastValidLocation(); float azimuth = -(float) Math.toDegrees(mOrientation[0]); final GeomagneticField geoField = new GeomagneticField( Double.valueOf(currentLoc.getLatitude()).floatValue(), Double.valueOf(currentLoc.getLongitude()).floatValue(), Double.valueOf(currentLoc.getAltitude()).floatValue(), System.currentTimeMillis()); azimuth += geoField.getDeclination(); // converts magnetic north // into true north // LOG.d("azimuth = " + azimuth); compassOrientation = azimuth;// - bearing; // if (Math.abs(locationOverlay.compassOrientation - compassOrientation) > 5) { // locationOverlay.compassOrientation = compassOrientation; // mapView.invalidate(); // } // } // } } } }
From source file:com.woofy.haifa.MapActivity.java
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR && rotation_on) { SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values); float[] orientation = new float[3]; SensorManager.getOrientation(mRotationMatrix, orientation); bearing = (float) (Math.toDegrees(orientation[0]) + mDeclination); // updateCamera(bearing); TODO }/*from w w w . j a v a 2s .c o m*/ }
From source file:ibme.sleepap.recording.SignalsRecorder.java
@Override public void onSensorChanged(SensorEvent event) { synchronized (this) { // Checking which type of sensor called this listener // In this case it is the Accelerometer (the next is the Magnetomer) if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { accelerometerCurrentTime = System.currentTimeMillis(); if (accelerometerCurrentTime - lastAccelerometerReadTime > (1000 / Constants.PARAM_SAMPLERATE_ACCELEROMETER - 1000 / (Constants.PARAM_SAMPLERATE_ACCELEROMETER * Constants.PARAM_UPSAMPLERATE_ACCELEROMETER))) { lastAccelerometerReadTime = accelerometerCurrentTime; float xRaw = event.values[0]; float yRaw = event.values[1]; float zRaw = event.values[2]; // Extracts unwanted gravity component from the // accelerometer signal. float alpha = Constants.PARAM_GRAVITY_FILTER_COEFFICIENT; runningGravityComponents[0] = runningGravityComponents[0] * alpha + (1 - alpha) * xRaw; runningGravityComponents[1] = runningGravityComponents[1] * alpha + (1 - alpha) * yRaw; runningGravityComponents[2] = runningGravityComponents[2] * alpha + (1 - alpha) * zRaw; float xAccel = xRaw - runningGravityComponents[0]; float yAccel = yRaw - runningGravityComponents[1]; float zAccel = zRaw - runningGravityComponents[2]; double magnitudeSquare = xAccel * xAccel + yAccel * yAccel + zAccel * zAccel; double magnitude = Math.sqrt(magnitudeSquare); actigraphyQueue.add(magnitude); int secsToDisplay = Integer.parseInt(sharedPreferences.getString(Constants.PREF_GRAPH_SECONDS, Constants.DEFAULT_GRAPH_RANGE)); int numberExtraSamples = actigraphyQueue.size() - (secsToDisplay * Constants.PARAM_SAMPLERATE_ACCELEROMETER); if (numberExtraSamples > 0) { for (int i = 0; i < numberExtraSamples; i++) { actigraphyQueue.remove(); }/* w w w . ja v a 2 s . c o m*/ } // Saves accelerometer data, necessary for the orientation // computation System.arraycopy(event.values, 0, latestAccelerometerEventValues, 0, 3); pushBackAccelerometerValues(xRaw, yRaw, zRaw); if (accelerometerCurrentTime - lastAccelerometerRecordedTime > Constants.PARAM_ACCELEROMETER_RECORDING_PERIOD + 1000 / Constants.PARAM_SAMPLERATE_ACCELEROMETER) { if (startRecordingFlag) { writeActigraphyLogVariance(); } gravitySum = gravitySquaredSum = 0; varianceCounter = 0; lastAccelerometerRecordedTime = accelerometerCurrentTime; } if (startRecordingFlag) { writeRawActigraphy(); } } } // Checking if the Magnetomer called this listener if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { // Copying magnetometer measures. System.arraycopy(event.values, 0, mGeoMags, 0, 3); if (SensorManager.getRotationMatrix(mRotationM, null, latestAccelerometerEventValues, mGeoMags)) { SensorManager.getOrientation(mRotationM, mOrientation); // Finding current orientation requires both Accelerometer // (using the previous measure) and Magnetometer data. // Converting radians to degrees (yaw, pitch, roll) mOrientation[0] = mOrientation[0] * Constants.CONST_DEGREES_PER_RADIAN; mOrientation[1] = mOrientation[1] * Constants.CONST_DEGREES_PER_RADIAN; mOrientation[2] = mOrientation[2] * Constants.CONST_DEGREES_PER_RADIAN; // The values (1,2,3,4) attributed for // supine/prone/left/right match the // ones attributed in VISI text files. int positionValue = 0; // Supine (4). if (-45 < mOrientation[1] && mOrientation[1] < 45 && -45 < mOrientation[2] && mOrientation[2] < 45) { positionValue = Constants.CODE_POSITION_SUPINE; position = Position.Supine; } // Prone (1). if ((((-180 < mOrientation[2] && mOrientation[2] < -135) || (135 < mOrientation[2] && mOrientation[2] < 180)) && -45 < mOrientation[1] && mOrientation[1] < 45)) { positionValue = Constants.CODE_POSITION_PRONE; position = Position.Prone; } // Right (2). if (-90 < mOrientation[2] && mOrientation[2] < -45) { positionValue = Constants.CODE_POSITION_RIGHT; position = Position.Right; } // Left (3). if (45 < mOrientation[2] && mOrientation[2] < 90) { positionValue = Constants.CODE_POSITION_LEFT; position = Position.Left; } // Sitting up (5). if ((((-135 < mOrientation[1] && mOrientation[1] < -45) || (45 < mOrientation[1] && mOrientation[1] < 135)) && -45 < mOrientation[2] && mOrientation[2] < 45)) { positionValue = Constants.CODE_POSITION_SITTING; position = Position.Sitting; } if ((oldPositionValue != positionValue) && (positionValue != 0) && startRecordingFlag) { updatePositionChangeTime(oldPositionValue); oldPositionValue = positionValue; try { // Write raw body position data BufferedWriter orientationBufferedWriter = new BufferedWriter( new FileWriter(orientationFile, true)); orientationBufferedWriter.append(String.valueOf(System.currentTimeMillis()) + ","); orientationBufferedWriter.append(String.valueOf(positionValue) + "\n"); orientationBufferedWriter.flush(); orientationBufferedWriter.close(); } catch (IOException e) { Log.e(Constants.CODE_APP_TAG, "Error writing orientation data to file", e); } } } } } }
From source file:com.davidmascharka.lips.TrackerActivity.java
@Override public void onSensorChanged(SensorEvent event) { switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: accelerometerX = event.values[0]; accelerometerY = event.values[1]; accelerometerZ = event.values[2]; break;/*from w w w . ja v a2 s . c o m*/ case Sensor.TYPE_MAGNETIC_FIELD: magneticX = event.values[0]; magneticY = event.values[1]; magneticZ = event.values[2]; break; case Sensor.TYPE_LIGHT: light = event.values[0]; break; case Sensor.TYPE_ROTATION_VECTOR: rotationX = event.values[0]; rotationY = event.values[1]; rotationZ = event.values[2]; break; default: break; } SensorManager.getRotationMatrix(rotation, inclination, new float[] { accelerometerX, accelerometerY, accelerometerZ }, new float[] { magneticX, magneticY, magneticZ }); orientation = SensorManager.getOrientation(rotation, orientation); }
From source file:com.example.sensingapp.SensingApp.java
private boolean calculateOrientation() { float[] arrfValues = new float[3]; float[] arrfR = new float[9]; float[] arrfI = new float[9]; if ((m_arrfAcclValues == null) || (m_arrfMagnetValues == null)) { return false; }/*from w ww .j av a2s . c o m*/ //if (SensorManager.getRotationMatrix(arrfR, null, m_arrfAcclValues, m_arrfMagnetValues)) { //Ignore inclintion matrix calculation will make the execution faster if (SensorManager.getRotationMatrix(arrfR, arrfI, m_arrfAcclValues, m_arrfMagnetValues)) { 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 } return true; } else { return false; } }
From source file:com.example.sensingapp.SensingApp.java
public void recordSensingInfo(SensorData senData) { String sRecordLine;// w w w . j av a2 s .c o 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) { } } }